Port homepage intro to fastapi

Port the main home page content to fastapi.
This commit is contained in:
Jelle van der Waa 2021-06-27 13:55:51 +02:00
parent 0a3aa40f20
commit 12911a101e
No known key found for this signature in database
GPG key ID: C06086337C50773E
5 changed files with 146 additions and 0 deletions

36
test/test_homepage.py Normal file
View file

@ -0,0 +1,36 @@
from http import HTTPStatus
from unittest.mock import patch
from fastapi.testclient import TestClient
from aurweb.asgi import app
client = TestClient(app)
def test_homepage():
with client as request:
response = request.get("/")
assert response.status_code == int(HTTPStatus.OK)
@patch('aurweb.util.get_ssh_fingerprints')
def test_homepage_ssh_fingerprints(get_ssh_fingerprints_mock):
fingerprints = {'Ed25519': "SHA256:RFzBCUItH9LZS0cKB5UE6ceAYhBD5C8GeOBip8Z11+4"}
get_ssh_fingerprints_mock.return_value = fingerprints
with client as request:
response = request.get("/")
assert list(fingerprints.values())[0] in response.content.decode()
assert 'The following SSH fingerprints are used for the AUR' in response.content.decode()
@patch('aurweb.util.get_ssh_fingerprints')
def test_homepage_no_ssh_fingerprints(get_ssh_fingerprints_mock):
get_ssh_fingerprints_mock.return_value = {}
with client as request:
response = request.get("/")
assert 'The following SSH fingerprints are used for the AUR' not in response.content.decode()