From cc863886d774109efa1715d43ae8faa2b5202460 Mon Sep 17 00:00:00 2001 From: spwoodcock Date: Fri, 13 Oct 2023 00:17:09 +0100 Subject: [PATCH] test: fix user + org creation prior to project creation --- src/backend/tests/conftest.py | 22 ++++++++++++++++++++++ src/backend/tests/test_projects_routes.py | 14 +++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/backend/tests/conftest.py b/src/backend/tests/conftest.py index 50395af50d..906c928233 100644 --- a/src/backend/tests/conftest.py +++ b/src/backend/tests/conftest.py @@ -76,6 +76,28 @@ def db(db_engine): connection.close() +@pytest.fixture(scope="function") +def user(db): + db_user = DbUser(id=100, username="test_user") + db.add(db_user) + db.commit() + return db_user + + +@pytest.fixture(scope="function") +def organization(db): + db_org = DbOrganisation( + name="test_org_qwerty", + slug="test_qwerty", + description="test org", + url="https://test.org", + logo="none", + ) + db.add(db_org) + db.commit() + return db_org + + @pytest.fixture(scope="function") def get_ids(db): user_id_query = text(f"SELECT id FROM {DbUser.__table__.name} LIMIT 1") diff --git a/src/backend/tests/test_projects_routes.py b/src/backend/tests/test_projects_routes.py index 38aca68af5..03d80d13fc 100644 --- a/src/backend/tests/test_projects_routes.py +++ b/src/backend/tests/test_projects_routes.py @@ -37,9 +37,9 @@ def refresh(self, item): pass -def test_create_project(client, db): +def test_create_project(client, organization, user): project_data = { - "author": {"username": "test_user", "id": 1}, + "author": {"username": user.username, "id": user.id}, "project_info": { "name": "test project", "short_description": "test", @@ -52,7 +52,7 @@ def test_create_project(client, db): "odk_central_password": odk_central_password, }, "hashtags": ["hot-fmtm"], - "organisation_id": 1, + "organisation_id": organization.id, } response = client.post("/projects/create_project", json=project_data) @@ -104,9 +104,9 @@ def test_convert_to_app_project(): assert isinstance(result.project_tasks, list) -def test_create_project_with_project_info(db): +def test_create_project_with_project_info(db, organization, user): project_metadata = BETAProjectUpload( - author=User(username="test_user", id=1), + author=User(username=user.username, id=user.id), project_info=ProjectInfo( name="test project", short_description="test", @@ -119,7 +119,7 @@ def test_create_project_with_project_info(db): odk_central_password=odk_central_password, ), hashtags=["hot-fmtm"], - organisation_id=1, + organisation_id=organization.id, ) try: result = project_crud.create_project_with_project_info( @@ -130,7 +130,7 @@ def test_create_project_with_project_info(db): pytest.fail(f"Test failed with exception: {str(e)}") -def test_generate_app_user(db, get_ids): +def test_generate_appuser_files(db, get_ids): custom_form = "/opt/app/test_data/buildings.xls" with open(custom_form, "rb") as file: contents = file.read()