Skip to content

Commit

Permalink
Feature/pdct 1094 Update tests to use correct geographies instead of …
Browse files Browse the repository at this point in the history
…default (#169)

* Bump db_client version to 3.6.1

* Move event_types into corpora taxonomy

* Add event_type to default metadata in helper dto functions

* Bump to 2.10.3

* Add missing 'event_type' field to metadata objs

* Bump db_client to 3.7.0

* Fix tests

* Make geo_id of family match what the geography value is

* Bump db_client to 3.7.1

* Add local test option so we can use pytest --lf

* Bump to 2.10.5
  • Loading branch information
katybaulch authored Jul 1, 2024
1 parent 2b8a3d2 commit 8753442
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 29 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ integration_test: build_dev
test: build_dev
docker compose run --rm navigator-admin-backend pytest -vvv tests

test_local:
poetry run pytest -vvv tests/integration_tests

run:
docker compose -f docker-compose.yml up -d --remove-orphans

Expand Down
35 changes: 17 additions & 18 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "admin_backend"
version = "2.10.4"
version = "2.10.5"
description = ""
authors = ["CPR-dev-team <[email protected]>"]
packages = [{ include = "app" }, { include = "tests" }]
Expand Down Expand Up @@ -29,7 +29,7 @@ boto3 = "^1.28.46"
moto = "^4.2.2"
types-sqlalchemy = "^1.4.53.38"
urllib3 = "^1.26.17"
db-client = { git = "https://github.com/climatepolicyradar/navigator-db-client.git", tag = "v3.6.3" }
db-client = { git = "https://github.com/climatepolicyradar/navigator-db-client.git", tag = "v3.7.1" }

[tool.poetry.dev-dependencies]
pre-commit = "^2.17.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,4 @@ def test_config_geographies(client: TestClient, data_db: Session, user_header_to
# Now sanity check the data
#
# Geographies.
assert data["geographies"][1]["node"]["slug"] == "south-asia"
assert data["geographies"][0]["node"]["slug"] == "south-asia"
16 changes: 11 additions & 5 deletions tests/integration_tests/family/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from sqlalchemy.orm import Session

from tests.helpers.family import create_family_write_dto
from tests.integration_tests.setup_db import DEFAULT_GEO_ID, EXPECTED_FAMILIES, setup_db
from tests.integration_tests.setup_db import EXPECTED_FAMILIES, setup_db

USA_GEO_ID = 212
USA_GEO_ID = 209


def test_update_family(client: TestClient, data_db: Session, user_header_token):
Expand Down Expand Up @@ -277,9 +277,11 @@ def test_update_fails_family_when_user_org_different_to_family_org(
)
assert db_family.title == "apple orange banana"
assert db_family.description == "apple"
assert db_family.geography_id == DEFAULT_GEO_ID
assert db_family.family_category == "UNFCCC"

geo_id = data_db.query(Geography.id).filter(Geography.value == "Other").scalar()
assert db_family.geography_id == geo_id


def test_update_family_succeeds_when_user_org_different_to_family_org_super(
client: TestClient, data_db: Session, superuser_header_token
Expand Down Expand Up @@ -351,9 +353,11 @@ def test_update_family_when_collection_org_different_to_family_org(
db_family = db_families[0]
assert db_family.title == "apple"
assert db_family.description == ""
assert db_family.geography_id == DEFAULT_GEO_ID
assert db_family.family_category == "UNFCCC"

geo_id = data_db.query(Geography.id).filter(Geography.value == "Other").scalar()
assert db_family.geography_id == geo_id


def test_update_family_when_not_authenticated(client: TestClient, data_db: Session):
setup_db(data_db)
Expand Down Expand Up @@ -390,9 +394,11 @@ def test_update_family_idempotent_when_ok(
)
assert db_family.title == EXPECTED_FAMILIES[1]["title"]
assert db_family.description == EXPECTED_FAMILIES[1]["summary"]
assert db_family.geography_id == DEFAULT_GEO_ID
assert db_family.family_category == EXPECTED_FAMILIES[1]["category"]

geo_id = data_db.query(Geography.id).filter(Geography.value == "Other").scalar()
assert db_family.geography_id == geo_id


def test_update_family_rollback(
client: TestClient, data_db: Session, rollback_family_repo, user_header_token
Expand Down
12 changes: 9 additions & 3 deletions tests/integration_tests/setup_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
FamilyCorpus,
FamilyDocument,
FamilyEvent,
Geography,
Slug,
)
from db_client.models.dfce.metadata import FamilyMetadata
Expand All @@ -23,8 +24,6 @@
from db_client.models.organisation.users import AppUser, Organisation, OrganisationUser
from sqlalchemy.orm import Session

DEFAULT_GEO_ID = 1

EXPECTED_FAMILIES = [
{
"import_id": "A.0.0.1",
Expand Down Expand Up @@ -409,12 +408,19 @@ def _setup_family_data(

for index in range(EXPECTED_NUM_FAMILIES):
data = EXPECTED_FAMILIES[index]

geo_id = (
test_db.query(Geography.id)
.filter(Geography.value == data["geography"])
.scalar()
)

test_db.add(
Family(
import_id=data["import_id"],
title=data["title"],
description=data["summary"],
geography_id=DEFAULT_GEO_ID,
geography_id=geo_id,
family_category=data["category"],
)
)
Expand Down

0 comments on commit 8753442

Please sign in to comment.