diff --git a/.gitignore b/.gitignore index 7c2d6fc39854bd55d92b175bd46ed414f20e150b..813e48d43d723280a791cbdf77901fd2fbf5219b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ __pycache__/ dist/ *.py[cod] .env +.venv .cache/ *.egg-info/ .coverage diff --git a/README.md b/README.md index e96068b4602ecb7e0627e849edbeccb6fafc4cf8..0573febcf29454868b53a21750e0a4c7471f0bd6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Open Lobby Server -Open Lobby is register of lobby meetings. It's being developed for and tested +Open Lobby is register of lobby contacts. It's being developed for and tested on [Czech Pirate Party](https://www.pirati.cz) but later it may be used by any party, organization, agency, ... diff --git a/tests/conftest.py b/tests/conftest.py index e9c3f605586d58234a7bc65dd3ec3ecba79a1953..7b54ac66a685d73ddfa68b24ef558380116a3982 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -57,7 +57,9 @@ def author_fix(author_factory): username="wolfe", first_name="Winston", last_name="Wolfe", - extra={"movies": 1}, + extra={"caliber": 45}, + email="winston@wolfe.com", + openid_uid="TheWolf", ) diff --git a/tests/dummy.py b/tests/dummy.py index 7d1570f95cb250d6bbad883f9006c12e2dec35ef..fc2e23a76c79fd0b7bd7cfb8342d278092b4b435 100644 --- a/tests/dummy.py +++ b/tests/dummy.py @@ -149,10 +149,6 @@ def prepare_reports(): Report.objects.create(author=author1, **reports[7]) -def prepare_author(): - User.objects.create(**authors[0]) - - def prepare_report(is_draft=False): author = User.objects.create(**authors[0]) Report.objects.create(author=author, is_draft=is_draft, **reports[0]) diff --git a/tests/mutations/snapshots/snap_test_create_report.py b/tests/mutations/snapshots/snap_test_create_report.py index 04a0923218ee4b6100f3106d6641add691cb1d0e..3b84514580a928f1ea6fc35de37eb1007c62385f 100644 --- a/tests/mutations/snapshots/snap_test_create_report.py +++ b/tests/mutations/snapshots/snap_test_create_report.py @@ -32,9 +32,9 @@ snapshots['test_full_report 1'] = { 'createReport': { 'report': { 'author': { - 'extra': '{"movies": 1}', + 'extra': '{"caliber": 45}', 'firstName': 'Winston', - 'id': 'QXV0aG9yOjE=', + 'id': 'QXV0aG9yOjQy', 'lastName': 'Wolfe', 'totalReports': 1 }, @@ -60,9 +60,9 @@ snapshots['test_is_draft 1'] = { 'createReport': { 'report': { 'author': { - 'extra': '{"movies": 1}', + 'extra': '{"caliber": 45}', 'firstName': 'Winston', - 'id': 'QXV0aG9yOjE=', + 'id': 'QXV0aG9yOjQy', 'lastName': 'Wolfe', 'totalReports': 0 }, diff --git a/tests/mutations/snapshots/snap_test_update_report.py b/tests/mutations/snapshots/snap_test_update_report.py index 32aa1adbe63f1e4835ba3ecb271fc773e75af2fe..20d697c23a5ed0d338666bbab44fdc40e33584ef 100644 --- a/tests/mutations/snapshots/snap_test_update_report.py +++ b/tests/mutations/snapshots/snap_test_update_report.py @@ -92,7 +92,7 @@ snapshots['test_update_draft_with_draft 1'] = { 'updateReport': { 'report': { 'author': { - 'extra': '{"movies": 1}', + 'extra': '{"caliber": 45}', 'firstName': 'Winston', 'id': 'QXV0aG9yOjQy', 'lastName': 'Wolfe', @@ -123,7 +123,7 @@ snapshots['test_update_draft_with_published 1'] = { 'updateReport': { 'report': { 'author': { - 'extra': '{"movies": 1}', + 'extra': '{"caliber": 45}', 'firstName': 'Winston', 'id': 'QXV0aG9yOjQy', 'lastName': 'Wolfe', @@ -154,7 +154,7 @@ snapshots['test_update_published_with_published 1'] = { 'updateReport': { 'report': { 'author': { - 'extra': '{"movies": 1}', + 'extra': '{"caliber": 45}', 'firstName': 'Winston', 'id': 'QXV0aG9yOjQy', 'lastName': 'Wolfe', @@ -185,7 +185,7 @@ snapshots['test_input_sanitization 1'] = { 'updateReport': { 'report': { 'author': { - 'extra': '{"movies": 1}', + 'extra': '{"caliber": 45}', 'firstName': 'Winston', 'id': 'QXV0aG9yOjQy', 'lastName': 'Wolfe', @@ -216,7 +216,7 @@ snapshots['test_update_draft_with_draft__late_edit 1'] = { 'updateReport': { 'report': { 'author': { - 'extra': '{"movies": 1}', + 'extra': '{"caliber": 45}', 'firstName': 'Winston', 'id': 'QXV0aG9yOjQy', 'lastName': 'Wolfe', @@ -247,7 +247,7 @@ snapshots['test_update_draft_with_published__late_edit 1'] = { 'updateReport': { 'report': { 'author': { - 'extra': '{"movies": 1}', + 'extra': '{"caliber": 45}', 'firstName': 'Winston', 'id': 'QXV0aG9yOjQy', 'lastName': 'Wolfe', @@ -373,7 +373,7 @@ snapshots['test_update_published_with_published__late_edit 1'] = { 'updateReport': { 'report': { 'author': { - 'extra': '{"movies": 1}', + 'extra': '{"caliber": 45}', 'firstName': 'Winston', 'id': 'QXV0aG9yOjQy', 'lastName': 'Wolfe', diff --git a/tests/mutations/test_create_report.py b/tests/mutations/test_create_report.py index d59a4b65024580031a2d6b4f0faf479d0aca0578..51f75020266383c70cde349f0783101ef399ed43 100644 --- a/tests/mutations/test_create_report.py +++ b/tests/mutations/test_create_report.py @@ -4,8 +4,7 @@ import re from openlobby.core.models import Report -from ..dummy import prepare_author -from ..utils import call_api, strip_value +from ..utils import strip_value pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures("django_es")] @@ -40,22 +39,17 @@ mutation createReport ($input: CreateReportInput!) { """ -@pytest.fixture(autouse=True) -def setup(): - prepare_author() - - -def test_unauthorized(client, snapshot): +def test_unauthorized(call_api, snapshot): input = { "title": "Short Story", "body": "I told you!", "date": arrow.utcnow().isoformat(), } - response = call_api(client, query, input) + response = call_api(query, input) snapshot.assert_match(response) -def test_full_report(client, snapshot): +def test_full_report(call_api, snapshot, author_fix): date = arrow.get(2018, 1, 1) title = "Free Tesla" body = "I visited Tesla factory and talked with Elon Musk." @@ -73,7 +67,7 @@ def test_full_report(client, snapshot): "date": date.isoformat(), } - response = call_api(client, query, input, "wolf") + response = call_api(query, input, author_fix) published = strip_value(response, "data", "createReport", "report", "published") edited = strip_value(response, "data", "createReport", "report", "edited") @@ -84,7 +78,7 @@ def test_full_report(client, snapshot): snapshot.assert_match(response) report = Report.objects.get() - assert report.author_id == 1 + assert report.author_id == author_fix.id assert report.date == date.datetime assert report.published == arrow.get(published).datetime assert report.edited == arrow.get(edited).datetime @@ -98,7 +92,7 @@ def test_full_report(client, snapshot): assert report.is_draft is False -def test_input_sanitization(client): +def test_input_sanitization(call_api, author_fix): input = { "title": "<s>No</s> tags", "body": 'some <a href="http://foo">link</a> <br>in body', @@ -109,7 +103,7 @@ def test_input_sanitization(client): "date": arrow.utcnow().isoformat(), } - call_api(client, query, input, "wolf") + call_api(query, input, author_fix) report = Report.objects.get() assert report.title == "No tags" @@ -120,7 +114,7 @@ def test_input_sanitization(client): assert report.other_participants == "you!" -def test_is_draft(client, snapshot): +def test_is_draft(call_api, snapshot, author_fix): date = arrow.get(2018, 1, 3) title = "Visited by old friend" body = "Niel deGrasse Tyson just visited me..." @@ -139,7 +133,7 @@ def test_is_draft(client, snapshot): "isDraft": True, } - response = call_api(client, query, input, "wolf") + response = call_api(query, input, author_fix) published = strip_value(response, "data", "createReport", "report", "published") edited = strip_value(response, "data", "createReport", "report", "edited") @@ -150,7 +144,7 @@ def test_is_draft(client, snapshot): snapshot.assert_match(response) report = Report.objects.get() - assert report.author_id == 1 + assert report.author_id == author_fix.id assert report.date == date.datetime assert report.published == arrow.get(published).datetime assert report.edited == arrow.get(edited).datetime diff --git a/tests/mutations/test_login.py b/tests/mutations/test_login.py index fb6f6bc300d91890115daf237c57bdd1436ac503..0c4d8c7b8f1c7dfd0975fedacde59945660a005d 100644 --- a/tests/mutations/test_login.py +++ b/tests/mutations/test_login.py @@ -7,8 +7,6 @@ from unittest.mock import patch from openlobby.core.models import OpenIdClient, LoginAttempt from openlobby.core.openid import register_client -from ..utils import call_api - pytestmark = pytest.mark.django_db @@ -29,7 +27,7 @@ def check_authorization_url(authorization_url, oid_client, state, snapshot): snapshot.assert_match(json.loads(qs["claims"][0])) -def test_login__known_openid_client(issuer, client, snapshot): +def test_login__known_openid_client(issuer, call_api, snapshot): oc = register_client(issuer) oid_client = OpenIdClient.objects.create( name="Test", @@ -53,7 +51,7 @@ def test_login__known_openid_client(issuer, client, snapshot): with patch( "openlobby.core.api.mutations.discover_issuer", return_value=issuer ) as mock: - response = call_api(client, query) + response = call_api(query) mock.assert_called_once_with(openid_uid) assert "errors" not in response @@ -66,7 +64,7 @@ def test_login__known_openid_client(issuer, client, snapshot): check_authorization_url(authorization_url, oid_client, la.state, snapshot) -def test_login__new_openid_client(issuer, client, snapshot): +def test_login__new_openid_client(issuer, call_api, snapshot): app_redirect_uri = "http://i.am.pirate" openid_uid = "wolf@openid.provider" query = """ @@ -82,7 +80,7 @@ def test_login__new_openid_client(issuer, client, snapshot): with patch( "openlobby.core.api.mutations.discover_issuer", return_value=issuer ) as mock: - response = call_api(client, query) + response = call_api(query) mock.assert_called_once_with(openid_uid) assert "errors" not in response diff --git a/tests/mutations/test_login_by_shortcut.py b/tests/mutations/test_login_by_shortcut.py index 6238aa2952fa5e85cf4bc43c0d290a5e8f29d356..4d9f3ed8ef6e82a28c0a2bfdaeb9d733e2011c3b 100644 --- a/tests/mutations/test_login_by_shortcut.py +++ b/tests/mutations/test_login_by_shortcut.py @@ -5,12 +5,11 @@ from openlobby.core.models import OpenIdClient, LoginAttempt from openlobby.core.openid import register_client from .test_login import check_authorization_url -from ..utils import call_api pytestmark = pytest.mark.django_db -def test_login_by_shortcut(issuer, client, snapshot): +def test_login_by_shortcut(issuer, call_api, snapshot): oc = register_client(issuer) oid_client = OpenIdClient.objects.create( name="Test", @@ -30,7 +29,7 @@ def test_login_by_shortcut(issuer, client, snapshot): """.format( id=to_global_id("LoginShortcut", oid_client.id), uri=app_redirect_uri ) - response = call_api(client, query) + response = call_api(query) assert "errors" not in response authorization_url = response["data"]["loginByShortcut"]["authorizationUrl"] diff --git a/tests/schema/snapshots/snap_test_viewer.py b/tests/schema/snapshots/snap_test_viewer.py index fb88edfc1557b7f419ab91d39a872731cc332863..bf43544acacac68191592383a0798ce0da918ff6 100644 --- a/tests/schema/snapshots/snap_test_viewer.py +++ b/tests/schema/snapshots/snap_test_viewer.py @@ -20,7 +20,7 @@ snapshots['test_authenticated 1'] = { 'extra': '{"caliber": 45}', 'firstName': 'Winston', 'hasCollidingName': False, - 'id': 'VXNlcjox', + 'id': 'VXNlcjo0Mg==', 'isAuthor': True, 'lastName': 'Wolfe', 'openidUid': 'TheWolf' diff --git a/tests/schema/test_authors.py b/tests/schema/test_authors.py index 2a56952ae43cbf5f5f59c908a2fa397956b3835b..977597e2192d70d8db30403f93cfc0bb12ed9ae9 100644 --- a/tests/schema/test_authors.py +++ b/tests/schema/test_authors.py @@ -3,13 +3,12 @@ import pytest from openlobby.core.models import User from ..dummy import prepare_reports -from ..utils import call_api pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures("django_es")] -def test_all(client, snapshot): +def test_all(call_api, snapshot): prepare_reports() User.objects.create(id=4, is_author=False, username="x") query = """ @@ -36,11 +35,11 @@ def test_all(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_first(client, snapshot): +def test_first(call_api, snapshot): prepare_reports() query = """ query { @@ -66,11 +65,11 @@ def test_first(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_first_after(client, snapshot): +def test_first_after(call_api, snapshot): prepare_reports() query = """ query { @@ -96,11 +95,11 @@ def test_first_after(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_last(client, snapshot): +def test_last(call_api, snapshot): prepare_reports() query = """ query { @@ -126,11 +125,11 @@ def test_last(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_last_before(client, snapshot): +def test_last_before(call_api, snapshot): prepare_reports() query = """ query { @@ -156,11 +155,11 @@ def test_last_before(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_with_reports(client, snapshot): +def test_with_reports(call_api, snapshot): prepare_reports() query = """ query { @@ -198,11 +197,11 @@ def test_with_reports(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_sort_by_last_name(client, snapshot): +def test_sort_by_last_name(call_api, snapshot): prepare_reports() query = """ query { @@ -228,11 +227,11 @@ def test_sort_by_last_name(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_sort_by_last_name_reversed(client, snapshot): +def test_sort_by_last_name_reversed(call_api, snapshot): prepare_reports() query = """ query { @@ -258,11 +257,11 @@ def test_sort_by_last_name_reversed(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_sort_by_total_reports(client, snapshot): +def test_sort_by_total_reports(call_api, snapshot): prepare_reports() query = """ query { @@ -288,11 +287,11 @@ def test_sort_by_total_reports(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_sort_by_total_reports_reversed(client, snapshot): +def test_sort_by_total_reports_reversed(call_api, snapshot): prepare_reports() query = """ query { @@ -318,11 +317,11 @@ def test_sort_by_total_reports_reversed(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_sort_by_default_reversed(client, snapshot): +def test_sort_by_default_reversed(call_api, snapshot): prepare_reports() query = """ query { @@ -348,5 +347,5 @@ def test_sort_by_default_reversed(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) diff --git a/tests/schema/test_login_shortcuts.py b/tests/schema/test_login_shortcuts.py index 4ec90abd615e15c5cc1b12c35e9cdfc831e2212f..b3cad2b6f44633f6bbf83f4096dc156c12734907 100644 --- a/tests/schema/test_login_shortcuts.py +++ b/tests/schema/test_login_shortcuts.py @@ -2,13 +2,11 @@ import pytest from openlobby.core.models import OpenIdClient -from ..utils import call_api - pytestmark = pytest.mark.django_db -def test_returns_only_shortcuts(client, snapshot): +def test_returns_only_shortcuts(call_api, snapshot): OpenIdClient.objects.create(id=10, name="foo", issuer="foo") OpenIdClient.objects.create(id=20, name="bar", issuer="bar", is_shortcut=True) query = """ @@ -19,11 +17,11 @@ def test_returns_only_shortcuts(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_none(client, snapshot): +def test_none(call_api, snapshot): OpenIdClient.objects.create(id=10, name="foo") query = """ query { @@ -33,5 +31,5 @@ def test_none(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) diff --git a/tests/schema/test_node.py b/tests/schema/test_node.py index 4e1984caa17e872ef3d44d0ae86c73f751861b70..c4793acea72a386e31419b1cdca64f94af3bb767 100644 --- a/tests/schema/test_node.py +++ b/tests/schema/test_node.py @@ -4,13 +4,12 @@ from graphql_relay import to_global_id from openlobby.core.models import OpenIdClient, User from ..dummy import prepare_reports -from ..utils import call_api pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures("django_es")] -def test_login_shortcut(client, snapshot): +def test_login_shortcut(call_api, snapshot): OpenIdClient.objects.create(id=10, name="foo", issuer="foo", is_shortcut=True) query = """ query {{ @@ -24,11 +23,11 @@ def test_login_shortcut(client, snapshot): """.format( id=to_global_id("LoginShortcut", 10) ) - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_author(client, snapshot): +def test_author(call_api, snapshot): prepare_reports() query = """ query {{ @@ -46,11 +45,11 @@ def test_author(client, snapshot): """.format( id=to_global_id("Author", 1) ) - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_author__returns_only_if_is_author(client, snapshot): +def test_author__returns_only_if_is_author(call_api, snapshot): User.objects.create(id=7, is_author=False) query = """ query {{ @@ -63,11 +62,11 @@ def test_author__returns_only_if_is_author(client, snapshot): """.format( id=to_global_id("Author", 7) ) - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_report(client, snapshot): +def test_report(call_api, snapshot): prepare_reports() query = """ query {{ @@ -99,11 +98,11 @@ def test_report(client, snapshot): """.format( id=to_global_id("Report", 1) ) - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_report__is_draft(client, snapshot): +def test_report__is_draft(call_api, snapshot): prepare_reports() query = """ query {{ @@ -118,11 +117,11 @@ def test_report__is_draft(client, snapshot): """.format( id=to_global_id("Report", 4) ) - response = call_api(client, query, username="wolf") + response = call_api(query, user=User.objects.get(username="wolf")) snapshot.assert_match(response) -def test_report__is_draft__unauthorized_viewer(client, snapshot): +def test_report__is_draft__unauthorized_viewer(call_api, snapshot): prepare_reports() query = """ query {{ @@ -137,11 +136,11 @@ def test_report__is_draft__unauthorized_viewer(client, snapshot): """.format( id=to_global_id("Report", 4) ) - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_report__is_draft__viewer_is_not_author(client, snapshot): +def test_report__is_draft__viewer_is_not_author(call_api, snapshot): prepare_reports() query = """ query {{ @@ -156,11 +155,11 @@ def test_report__is_draft__viewer_is_not_author(client, snapshot): """.format( id=to_global_id("Report", 4) ) - response = call_api(client, query, username="spongebob") + response = call_api(query, user=User.objects.get(username="sponge")) snapshot.assert_match(response) -def test_report__without_revisions(client, snapshot): +def test_report__without_revisions(call_api, snapshot): prepare_reports() query = """ query {{ @@ -178,11 +177,11 @@ def test_report__without_revisions(client, snapshot): """.format( id=to_global_id("Report", 3) ) - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_report__with_revisions(client, snapshot): +def test_report__with_revisions(call_api, snapshot): prepare_reports() query = """ query {{ @@ -221,11 +220,11 @@ def test_report__with_revisions(client, snapshot): """.format( id=to_global_id("Report", 2) ) - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_user__unauthorized(client, snapshot): +def test_user__unauthorized(call_api, snapshot): User.objects.create( id=8, username="albert", @@ -251,11 +250,11 @@ def test_user__unauthorized(client, snapshot): """.format( id=to_global_id("User", 8) ) - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_user__not_a_viewer(client, snapshot): +def test_user__not_a_viewer(call_api, snapshot): User.objects.create( id=8, username="albert", @@ -264,7 +263,7 @@ def test_user__not_a_viewer(client, snapshot): last_name="Einstein", extra={"e": "mc2"}, ) - User.objects.create( + user = User.objects.create( id=2, username="isaac", openid_uid="isaac@newton.id", @@ -289,12 +288,12 @@ def test_user__not_a_viewer(client, snapshot): """.format( id=to_global_id("User", 8) ) - response = call_api(client, query, username="isaac") + response = call_api(query, user=user) snapshot.assert_match(response) -def test_user(client, snapshot): - User.objects.create( +def test_user(call_api, snapshot): + user = User.objects.create( id=8, username="albert", openid_uid="albert@einstein.id", @@ -319,5 +318,5 @@ def test_user(client, snapshot): """.format( id=to_global_id("User", 8) ) - response = call_api(client, query, username="albert") + response = call_api(query, user=user) snapshot.assert_match(response) diff --git a/tests/schema/test_report_drafts.py b/tests/schema/test_report_drafts.py index ce12831efc3b6b246cb84e242f6d444f378bcd33..9df3f3232695d8b4d1bef0b6e0e008962868bb70 100644 --- a/tests/schema/test_report_drafts.py +++ b/tests/schema/test_report_drafts.py @@ -1,13 +1,14 @@ import pytest +from openlobby.core.models import User + from ..dummy import prepare_reports -from ..utils import call_api pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures("django_es")] -def test_unauthenticated(client, snapshot): +def test_unauthenticated(call_api, snapshot): prepare_reports() query = """ query { @@ -16,11 +17,11 @@ def test_unauthenticated(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_authenticated(client, snapshot): +def test_authenticated(call_api, snapshot): prepare_reports() query = """ query { @@ -39,5 +40,5 @@ def test_authenticated(client, snapshot): } } """ - response = call_api(client, query, username="wolf") + response = call_api(query, user=User.objects.get(username="wolf")) snapshot.assert_match(response) diff --git a/tests/schema/test_search_reports.py b/tests/schema/test_search_reports.py index 910b80d64ef2f9072b194fe56b621f1ebac9c870..e803019121b30126b8a66fcfbf97490b4405eced 100644 --- a/tests/schema/test_search_reports.py +++ b/tests/schema/test_search_reports.py @@ -1,13 +1,12 @@ import pytest from ..dummy import prepare_reports -from ..utils import call_api pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures("django_es")] -def test_all(client, snapshot): +def test_all(call_api, snapshot): prepare_reports() query = """ query { @@ -48,11 +47,11 @@ def test_all(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_query(client, snapshot): +def test_query(call_api, snapshot): prepare_reports() query = """ query { @@ -87,11 +86,11 @@ def test_query(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_highlight(client, snapshot): +def test_highlight(call_api, snapshot): prepare_reports() query = """ query { @@ -126,11 +125,11 @@ def test_highlight(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_first(client, snapshot): +def test_first(call_api, snapshot): prepare_reports() query = """ query { @@ -152,11 +151,11 @@ def test_first(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_first_after(client, snapshot): +def test_first_after(call_api, snapshot): prepare_reports() query = """ query { @@ -178,11 +177,11 @@ def test_first_after(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_last(client, snapshot): +def test_last(call_api, snapshot): prepare_reports() query = """ query { @@ -204,11 +203,11 @@ def test_last(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_last_before(client, snapshot): +def test_last_before(call_api, snapshot): prepare_reports() query = """ query { @@ -230,5 +229,5 @@ def test_last_before(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) diff --git a/tests/schema/test_viewer.py b/tests/schema/test_viewer.py index 1255eff15f9147a4f5585bc3bb765e8a24a638b9..e8fc805d725e643ffe7c4b9d1c7c12c31eb4d6bc 100644 --- a/tests/schema/test_viewer.py +++ b/tests/schema/test_viewer.py @@ -1,29 +1,12 @@ import pytest from openlobby.core.auth import create_access_token -from openlobby.core.models import User - -from ..utils import call_api pytestmark = pytest.mark.django_db -@pytest.fixture(autouse=True) -def setup(): - User.objects.create( - id=1, - is_author=True, - username="wolf", - openid_uid="TheWolf", - first_name="Winston", - last_name="Wolfe", - email="winston@wolfe.com", - extra={"caliber": 45}, - ) - - -def test_unauthenticated(client, snapshot): +def test_unauthenticated(call_api, snapshot, author_fix): query = """ query { viewer { @@ -31,11 +14,11 @@ def test_unauthenticated(client, snapshot): } } """ - response = call_api(client, query) + response = call_api(query) snapshot.assert_match(response) -def test_authenticated(client, snapshot): +def test_authenticated(call_api, snapshot, author_fix): query = """ query { viewer { @@ -50,15 +33,15 @@ def test_authenticated(client, snapshot): } } """ - response = call_api(client, query, username="wolf") + response = call_api(query, user=author_fix) snapshot.assert_match(response) # integration tests of wrong authentication -def test_wrong_header(client, snapshot): - token = create_access_token("wolfe") +def test_wrong_header(client, snapshot, author_fix): + token = create_access_token(author_fix.username) auth_header = "WRONG {}".format(token) res = client.post( "/graphql", @@ -76,8 +59,8 @@ def test_wrong_header(client, snapshot): snapshot.assert_match(res.json()) -def test_wrong_token(client, snapshot): - token = create_access_token("wolfe") +def test_wrong_token(client, snapshot, author_fix): + token = create_access_token(author_fix.username) auth_header = "Bearer XXX{}".format(token) res = client.post( "/graphql", diff --git a/tests/utils.py b/tests/utils.py index ca15876585e45fc1db0a483882b765d50be8c563..21ad1269293e5d8b466dc2b0289c405dcaf4b115 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -4,21 +4,6 @@ import json from openlobby.core.auth import create_access_token -def call_api(client, query, input=None, username=None): - variables = json.dumps({"input": input or {}}) - if username is None: - res = client.post("/graphql", {"query": query, "variables": variables}) - else: - token = create_access_token(username) - auth_header = "Bearer {}".format(token) - res = client.post( - "/graphql", - {"query": query, "variables": variables}, - HTTP_AUTHORIZATION=auth_header, - ) - return res.json() - - def strip_value(data, *path): element = path[0] value = data.get(element)