Skip to content

Commit

Permalink
PDCT 998/ensure new documents have relationships in old and new schema (
Browse files Browse the repository at this point in the history
  • Loading branch information
diversemix authored Mar 26, 2024
1 parent ce70848 commit 2f21b4a
Show file tree
Hide file tree
Showing 31 changed files with 554 additions and 9,940 deletions.
9 changes: 9 additions & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*out
*logs
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
tmp
10 changes: 4 additions & 6 deletions .trunk/configure-pyright-with-pyenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ venv_name=$(grep -m 1 venv pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" |
# Check if pyrightconfig already exists.
if [[ ! -f pyrightconfig.json ]]; then
# Check if pyenv-pyright plugin is installed
if ! command -v pyenv &>/dev/null; then
if ! command -v pyenv 1>/dev/null; then
echo "pyenv not installed. Please install pyenv..."
exit 1
fi

# Check if pyenv-pyright plugin is installed
if ! command -v pyenv pyright &>/dev/null; then
echo "pyenv-pyright not installed. Installing..."
pyenv_root=$(pyenv root)
pyenv_root=$(pyenv root)
dir_exists=$(ls -A "${pyenv_root}"/plugins/pyenv-pyright)
if [[ -z ${dir_exists} ]]; then
git clone https://github.com/alefpereira/pyenv-pyright.git "${pyenv_root}"/plugins/pyenv-pyright
fi

# Generate the pyrightconfig.json file.
pyenv pyright "${venv_name}"
pyenv local "${venv_name}"

fi

# Check whether required keys are present in pyrightconfig.json.
Expand Down
23 changes: 19 additions & 4 deletions app/repository/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
from db_client.models.dfce.family import (
DocumentStatus,
Family,
FamilyCorpus,
FamilyDocument,
FamilyOrganisation,
FamilyStatus,
Slug,
)
from db_client.models.dfce.geography import Geography
from db_client.models.dfce.metadata import FamilyMetadata, MetadataOrganisation
from db_client.models.organisation.corpus import Corpus
from db_client.models.organisation.counters import CountedEntity
from db_client.models.organisation.users import Organisation
from sqlalchemy import Column, and_
Expand Down Expand Up @@ -342,14 +344,24 @@ def create(db: Session, family: FamilyCreateDTO, geo_id: int, org_id: int) -> st
"""
try:
new_family, new_fam_org = _family_org_from_dto(family, geo_id, org_id)

new_family.import_id = cast(
Column, generate_import_id(db, CountedEntity.Family, org_id)
)
new_fam_org.family_import_id = new_family.import_id

db.add(new_family)

# Old schema (to be removed in PDCT-937).
new_fam_org.family_import_id = new_family.import_id
db.add(new_fam_org)

# New schema.
new_fam_corpus = db.query(Corpus).filter(Corpus.organisation_id == org_id).one()
db.add(
FamilyCorpus(
family_import_id=new_family.import_id,
corpus_import_id=new_fam_corpus.import_id,
)
)

db.flush()
except:
_LOGGER.exception("Error trying to create Family")
Expand All @@ -365,7 +377,10 @@ def create(db: Session, family: FamilyCreateDTO, geo_id: int, org_id: int) -> st
)
db.flush()

# TODO Validate that the metadata being added conforms to corpus type. PDCT-945

# Add the metadata
# tax to be removed in PDCT-937.
tax = (
db.query(MetadataOrganisation)
.filter(MetadataOrganisation.organisation_id == org_id)
Expand All @@ -374,7 +389,7 @@ def create(db: Session, family: FamilyCreateDTO, geo_id: int, org_id: int) -> st
db.add(
FamilyMetadata(
family_import_id=new_family.import_id,
taxonomy_id=tax.taxonomy_id,
taxonomy_id=tax.taxonomy_id, # TODO Remove as part PDCT-937
value=family.metadata,
)
)
Expand Down
32 changes: 16 additions & 16 deletions integration_tests/analytics/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
# --- GET ALL


def test_get_all_analytics(client: TestClient, test_db: Session, user_header_token):
setup_db(test_db)
def test_get_all_analytics(client: TestClient, data_db: Session, user_header_token):
setup_db(data_db)
response = client.get(
"/api/v1/analytics",
headers=user_header_token,
)
assert response.status_code == status.HTTP_404_NOT_FOUND


def test_get_all_analytics_when_not_authenticated(client: TestClient, test_db: Session):
setup_db(test_db)
def test_get_all_analytics_when_not_authenticated(client: TestClient, data_db: Session):
setup_db(data_db)
response = client.get(
"/api/v1/analytics",
)
Expand All @@ -31,8 +31,8 @@ def test_get_all_analytics_when_not_authenticated(client: TestClient, test_db: S
# --- GET SUMMARY


def test_get_analytics_summary(client: TestClient, test_db: Session, user_header_token):
setup_db(test_db)
def test_get_analytics_summary(client: TestClient, data_db: Session, user_header_token):
setup_db(data_db)
response = client.get(
"/api/v1/analytics/summary",
headers=user_header_token,
Expand All @@ -49,19 +49,19 @@ def test_get_analytics_summary(client: TestClient, test_db: Session, user_header


def test_get_analytics_summary_when_not_authenticated(
client: TestClient, test_db: Session
client: TestClient, data_db: Session
):
setup_db(test_db)
setup_db(data_db)
response = client.get(
"/api/v1/analytics/summary",
)
assert response.status_code == status.HTTP_401_UNAUTHORIZED


def test_get_analytics_summary_when_not_found(
client: TestClient, test_db: Session, collection_count_none, user_header_token
client: TestClient, data_db: Session, collection_count_none, user_header_token
):
setup_db(test_db, configure_empty=True)
setup_db(data_db, configure_empty=True)
response = client.get(
"/api/v1/analytics/summary",
headers=user_header_token,
Expand All @@ -72,9 +72,9 @@ def test_get_analytics_summary_when_not_found(


def test_get_analytics_when_collection_db_error(
client: TestClient, test_db: Session, bad_collection_repo, user_header_token
client: TestClient, data_db: Session, bad_collection_repo, user_header_token
):
setup_db(test_db)
setup_db(data_db)
response = client.get(
"/api/v1/analytics/summary",
headers=user_header_token,
Expand All @@ -85,9 +85,9 @@ def test_get_analytics_when_collection_db_error(


def test_get_analytics_when_family_db_error(
client: TestClient, test_db: Session, bad_family_repo, user_header_token
client: TestClient, data_db: Session, bad_family_repo, user_header_token
):
setup_db(test_db)
setup_db(data_db)
response = client.get(
"/api/v1/analytics/summary",
headers=user_header_token,
Expand All @@ -98,9 +98,9 @@ def test_get_analytics_when_family_db_error(


def test_get_analytics_when_document_db_error(
client: TestClient, test_db: Session, bad_document_repo, user_header_token
client: TestClient, data_db: Session, bad_document_repo, user_header_token
):
setup_db(test_db)
setup_db(data_db)
response = client.get(
"/api/v1/analytics/summary",
headers=user_header_token,
Expand Down
Loading

0 comments on commit 2f21b4a

Please sign in to comment.