def iati_organisations__iati_organisation__name(self, element): name_list = self.get_model_list('OrganisationName') if name_list and len(name_list) > 0: raise FieldValidationError("name", "Duplicate names are not allowed") organisation = self.get_model('Organisation') name = OrganisationName() name.organisation = organisation self.register_model('OrganisationName', name) return element
def iati_organisations__iati_organisation__name(self, element): # Although OrganisationName and Organisation has One-to-One relation # on the database level, we check here whether element 'name' occurs # only once in the parent element 'organisation'. organisation = self.get_model('Organisation') if 'OrganisationName' in self.model_store: for name in self.model_store['OrganisationName']: if name.organisation == organisation: raise ParserError("Organisation", "OrganisationName", "must occur no more than once.") # narrative is parsed in different method but as it is required # sub-element in 'name' element so we check it here. narrative = element.xpath("narrative") if len(narrative) < 1: raise RequiredFieldError("OrganisationName", "narrative", "must occur at least once.") organisation_name = OrganisationName() organisation_name.organisation = organisation self.register_model("OrganisationName", organisation_name) return element
def test_organisation_file_document_link_list_endpoint_result(self): # Version version = Version(code='2.03') version.save() # Language language = Language(code='en', name='English') language.save() # Organisation organisation_identifier = 'test-org' organisation = Organisation( organisation_identifier=organisation_identifier, normalized_organisation_identifier='test-org', iati_standard_version=version, primary_name='Test Primary Name') organisation.save() # Organisation Name organisation_name = OrganisationName(organisation=organisation) organisation_name.save() # Organisation Narrative OrganisationNarrative( organisation=organisation, content_type=ContentType.objects.get_for_model(organisation_name), object_id=organisation_name.id, language=language, content='Test Content').save() # File Format file_format = FileFormat(code='application/http', name='URL') file_format.save() # Organisation Document Link organisation_document_link_url = 'https://www.test.com' organisation_document_link = OrganisationDocumentLink( organisation=organisation, url=organisation_document_link_url, file_format=file_format, language=language, iso_date=datetime.datetime.strptime('2018-01-01', '%Y-%m-%d')) organisation_document_link.save() # DocumentCategoryCategory document_category_category = DocumentCategoryCategory( code='B', name='Organisation Level') document_category_category.save() # Document Category document_category = DocumentCategory( code='B01', name='Organisation Web URL', category=document_category_category) document_category.save() # Organisation Document Link Category organisation_document_link_category = \ OrganisationDocumentLinkCategory( document_link=organisation_document_link, category=document_category) organisation_document_link_category.save() # API client client = APIClient() # URL endpoint organisation dopcument links url = reverse( 'organisations:organisation-file-organisation-document-link-list', kwargs={'organisation_identifier': organisation_identifier}) # Get response from client response = client.get(path=url) first_organisation_document_link = response.data.get('results')[0] # The first result of the organisation document link list # should be the same with above URL 'https://www.test.com' self.assertEqual( first_organisation_document_link.get('url'), organisation_document_link_url)
def test_organisation_file_document_link_list_endpoint_result(self): # Version version = Version(code='2.03') version.save() # Language language = Language(code='en', name='English') language.save() # Organisation organisation_identifier = 'test-org' organisation = Organisation( organisation_identifier=organisation_identifier, normalized_organisation_identifier='test-org', iati_standard_version=version, primary_name='Test Primary Name') organisation.save() # Organisation Name organisation_name = OrganisationName(organisation=organisation) organisation_name.save() # Organisation Narrative OrganisationNarrative( organisation=organisation, content_type=ContentType.objects.get_for_model(organisation_name), object_id=organisation_name.id, language=language, content='Test Content').save() # File Format file_format = FileFormat(code='application/http', name='URL') file_format.save() # Organisation Document Link organisation_document_link_url = 'https://www.test.com' organisation_document_link = OrganisationDocumentLink( organisation=organisation, url=organisation_document_link_url, file_format=file_format, language=language, iso_date=datetime.datetime.strptime('2018-01-01', '%Y-%m-%d')) organisation_document_link.save() # DocumentCategoryCategory document_category_category = DocumentCategoryCategory( code='B', name='Organisation Level') document_category_category.save() # Document Category document_category = DocumentCategory( code='B01', name='Organisation Web URL', category=document_category_category) document_category.save() # Organisation Document Link Category organisation_document_link_category = \ OrganisationDocumentLinkCategory( document_link=organisation_document_link, category=document_category) organisation_document_link_category.save() # API client client = APIClient() # URL endpoint organisation dopcument links url = reverse( 'organisations:organisation-file-organisation-document-link-list', kwargs={'organisation_identifier': organisation_identifier}) # Get response from client response = client.get(path=url) first_organisation_document_link = response.data.get('results')[0] # The first result of the organisation document link list # should be the same with above URL 'https://www.test.com' self.assertEqual(first_organisation_document_link.get('url'), organisation_document_link_url)