Skip to content

Commit

Permalink
test: fix user + org creation prior to project creation
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Oct 12, 2023
1 parent 94a5c01 commit cc86388
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
22 changes: 22 additions & 0 deletions src/backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 7 additions & 7 deletions src/backend/tests/test_projects_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand Down Expand Up @@ -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",
Expand All @@ -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(
Expand All @@ -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()
Expand Down

0 comments on commit cc86388

Please sign in to comment.