Skip to content

Commit

Permalink
Add test case for update AssessmentRegistry using SnapShotTextCase
Browse files Browse the repository at this point in the history
  • Loading branch information
sauravsapkota committed Aug 14, 2024
1 parent 65ae8c7 commit 16f4ed4
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 233 deletions.
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
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 != self.project:
raise serializers.ValidationError('Only Source from current Project are allowed')
return lead

def validate(self, data):
data['project'] = self.project
return data
166 changes: 78 additions & 88 deletions apps/assessment_registry/tests/snapshots/snap_test_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,101 +7,79 @@

snapshots = Snapshot()

snapshots['TestAnalysisMutationSnapShotTestCase::test_assessment_registry_update error'] = {
snapshots['TestAssessmentRegistryMutationSnapShotTestCase::test_assessment_registry_update error'] = {
'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': [
],
'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': '2021-06-21',
'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'
'errors': [
{
'arrayErrors': None,
'clientId': None,
'field': 'lead',
'messages': 'Only Source from current Project are allowed',
'objectErrors': None
},
'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': '2020-02-16',
'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': [
]
}
{
'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['TestAnalysisMutationSnapShotTestCase::test_assessment_registry_update success'] = {
snapshots['TestAssessmentRegistryMutationSnapShotTestCase::test_assessment_registry_update success'] = {
'data': {
'project': {
'updateAssessmentRegistry': {
Expand All @@ -123,6 +101,18 @@
'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',
Expand All @@ -132,7 +122,7 @@
'costEstimatesUsd': 0,
'createdAt': '2021-01-01T00:00:00.123456+00:00',
'dataCollectionEndDate': '2020-09-06',
'dataCollectionStartDate': '2021-06-21',
'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',
Expand Down Expand Up @@ -172,7 +162,7 @@
],
'protectionRisks': [
],
'publicationDate': '2020-02-16',
'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': [
Expand Down
Loading

0 comments on commit 16f4ed4

Please sign in to comment.