Skip to content

Commit

Permalink
Merge pull request #1523 from the-deep/feature/test-update-assessment…
Browse files Browse the repository at this point in the history
…-registry

Add test case for update AssessmentRegistry Mutation
  • Loading branch information
subinasr authored Aug 22, 2024
2 parents dd2d05a + 78bc438 commit 2e1bfeb
Show file tree
Hide file tree
Showing 8 changed files with 537 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Add this to your `.git/hooks/pre-commit` to generate latest graphql schema befor
#!/bin/sh
echo "pre-commit: Generating graphql schema."
if [ -z `docker ps -q --no-trunc | grep $(docker-compose ps -q web)` ]; then
if [ -z `docker ps -q --no-trunc | grep $(docker compose ps -q web)` ]; then
docker compose run --rm web ./manage.py graphql_schema --out schema.graphql
else
docker compose exec -T web ./manage.py graphql_schema --out schema.graphql
Expand Down
8 changes: 8 additions & 0 deletions apps/assessment_registry/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Question,
Answer,
AssessmentRegistry,
AssessmentRegistryOrganization,
MethodologyAttribute,
AdditionalDocument,
ScoreRating,
Expand Down Expand Up @@ -215,3 +216,10 @@ def bg_countries(self, create, extracted, **_):
self.bg_countries.add( # pyright: ignore [reportGeneralTypeIssues]
country
)


class AssessmentRegistryOrganizationFactory(DjangoModelFactory):
organization_type = fuzzy.FuzzyChoice(_choices(AssessmentRegistryOrganization.Type))

class Meta:
model = AssessmentRegistryOrganization
2 changes: 1 addition & 1 deletion apps/assessment_registry/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Arguments:
class UpdateAssessmentRegistry(AssessmentRegsitryMutationMixin, PsGrapheneMutation):
class Arguments:
data = AssessmentRegistryCreateInputType(required=True)
id = graphene.ID(required=False)
id = graphene.ID(required=True)

result = graphene.Field(AssessmentRegistryType)
serializer_class = AssessmentRegistrySerializer
Expand Down
5 changes: 5 additions & 0 deletions apps/assessment_registry/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ def validate_cna(self, data):
raise serializers.ValidationError('Dublicate question selected')
question_list.append(question)

def validate_lead(self, lead):
if lead.project_id != self.project.id:
raise serializers.ValidationError('Only Source from current Project are allowed')
return lead

def validate(self, data):
data['project'] = self.project
return data
Empty file.
186 changes: 186 additions & 0 deletions apps/assessment_registry/tests/snapshots/snap_test_mutation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# -*- coding: utf-8 -*-
# snapshottest: v1 - https://goo.gl/zC4yUc
from __future__ import unicode_literals

from snapshottest import Snapshot


snapshots = Snapshot()

snapshots['TestAssessmentRegistryMutationSnapShotTestCase::test_assessment_registry_update error'] = {
'data': {
'project': {
'updateAssessmentRegistry': {
'errors': [
{
'arrayErrors': None,
'clientId': None,
'field': 'lead',
'messages': 'Only Source from current Project are allowed',
'objectErrors': None
},
{
'arrayErrors': [
{
'clientId': 'nonMemberErrors',
'messages': 'Dublicate organization selected',
'objectErrors': None
}
],
'clientId': None,
'field': 'stakeholders',
'messages': None,
'objectErrors': None
},
{
'arrayErrors': [
{
'clientId': 'nonMemberErrors',
'messages': 'Score ratings should have unique score types',
'objectErrors': None
}
],
'clientId': None,
'field': 'scoreRatings',
'messages': None,
'objectErrors': None
},
{
'arrayErrors': [
{
'clientId': 'nonMemberErrors',
'messages': 'Score analytical density should have unique sectors',
'objectErrors': None
}
],
'clientId': None,
'field': 'scoreAnalyticalDensity',
'messages': None,
'objectErrors': None
},
{
'arrayErrors': [
{
'clientId': 'nonMemberErrors',
'messages': 'Dublicate question selected',
'objectErrors': None
}
],
'clientId': None,
'field': 'cna',
'messages': None,
'objectErrors': None
}
],
'ok': False,
'result': None
}
}
}
}

snapshots['TestAssessmentRegistryMutationSnapShotTestCase::test_assessment_registry_update success'] = {
'data': {
'project': {
'updateAssessmentRegistry': {
'errors': None,
'ok': True,
'result': {
'additionalDocumentComplete': True,
'additionalDocuments': [
],
'affectedGroups': [
'ALL_AFFECTED'
],
'bgCountries': [
{
'id': '1'
}
],
'bgCrisisStartDate': '2019-07-03',
'bgCrisisType': 'LANDSLIDE',
'bgPreparedness': 'WITHOUT_PREPAREDNESS',
'cna': [
{
'answer': True,
'id': '1',
'question': {
'id': '1',
'question': 'test question',
'sector': 'RELEVANCE',
'sectorDisplay': 'Relevance',
'subSector': 'RELEVANCE',
'subSectorDisplay': 'Relevance'
}
}
],
'cnaComplete': True,
'confidentiality': 'CONFIDENTIAL',
'confidentialityDisplay': 'Confidential',
'coordinatedJoint': 'HARMONIZED',
'coordinatedJointDisplay': 'Coordinated - Harmonized',
'costEstimatesUsd': 0,
'createdAt': '2021-01-01T00:00:00.123456+00:00',
'dataCollectionEndDate': '2020-09-06',
'dataCollectionStartDate': '2020-02-16',
'dataCollectionTechniques': '''Current hear claim well two truth out major. Upon these story film. Drive note bad rule.
She campaign little near enter their institution. Up sense ready require human.''',
'detailsType': 'MONITORING',
'detailsTypeDisplay': 'Monitoring',
'externalSupport': 'NO_EXTERNAL_SUPPORT_RECEIVED',
'externalSupportDisplay': 'No external support received',
'family': 'HUMANITARIAN_NEEDS_OVERVIEW',
'familyDisplay': 'Humanitarian Needs Overview (HNO)',
'focusComplete': True,
'focuses': [
'CONTEXT',
'HUMANITERIAN_ACCESS',
'DISPLACEMENT'
],
'frequency': 'REGULAR',
'frequencyDisplay': 'Regular',
'id': '1',
'language': [
'ENGLISH',
'FRENCH'
],
'lead': {
'id': '2'
},
'limitations': '''Choice father why often my security arm. Live try most arm meet surface attention attack. Identify walk now often always.
Price north first end prove fire. How public feel first sell.''',
'metadataComplete': True,
'methodologyAttributes': [
],
'methodologyComplete': True,
'modifiedAt': '2021-01-01T00:00:00.123456+00:00',
'noOfPages': 0,
'objectives': '''Then fire pretty how trip learn enter. Seat much section investment on.
Young catch management sense technology. Physical society instead as. Other life edge network wall quite.''',
'protectionInfoMgmts': [
'PROTECTION_MONITORING'
],
'protectionRisks': [
],
'publicationDate': '2021-06-21',
'sampling': '''Best issue interest level. Pull worker better.
Song body court movie cell contain. Economic type kitchen technology nearly anything yourself. Why unit support.''',
'sectors': [
'HEALTH',
'SHELTER',
'WASH'
],
'status': 'ONGOING',
'summaryComplete': True,
'summaryDimensionMeta': [
],
'summaryPillarMeta': None,
'summarySubDimensionIssue': [
],
'summarySubPillarIssue': [
]
}
}
}
}
}
Loading

0 comments on commit 2e1bfeb

Please sign in to comment.