Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDCT 998/ensure new documents have relationships in old and new schema #107

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f50713a
Upgrade dbclient to v3.2.1 & remove ruff config
katybaulch Mar 25, 2024
89193fd
Merge branch 'main' into PDCT-998/ensure-new-documents-have-relations…
katybaulch Mar 25, 2024
d0e4dcd
Configure pyright to work with pyenv in makefile
katybaulch Mar 25, 2024
92fe7a1
Add pyrightconfig to gitignore & add trunk ignores
katybaulch Mar 25, 2024
1b2459f
Add ruff config for trunk
katybaulch Mar 25, 2024
bb46706
Populate old and new schema for new families.
katybaulch Mar 25, 2024
5113a3b
Don't add corpus type on family create.
katybaulch Mar 25, 2024
b32d746
Update blank.sql with alembic version 0032 schema
katybaulch Mar 26, 2024
e12b288
update tests
diversemix Mar 26, 2024
ab784b0
fix final tests
diversemix Mar 26, 2024
c7d52fa
Fix formatting trunk issues
diversemix Mar 26, 2024
1254c41
fix unbound vars
diversemix Mar 26, 2024
d7f8429
fix bad test data
diversemix Mar 26, 2024
09ddf91
update test for idempotency
diversemix Mar 26, 2024
7df9dea
Fix script to install pyenv-pyright if not in expected location
katybaulch Mar 26, 2024
2090710
Formatting fix
katybaulch Mar 26, 2024
72460b7
Add test for checking new schema is also populated on fam create
katybaulch Mar 26, 2024
0904303
Merge branch 'main' into PDCT-998/ensure-new-documents-have-relations…
katybaulch Mar 26, 2024
fb50ba9
Use [[ ]] and prevent hiding return of dir_exists command
katybaulch Mar 26, 2024
c0dc4ee
Check old schema 'organisation_id' on family is still populated
katybaulch Mar 26, 2024
27001ae
Check org_id not None
katybaulch Mar 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading