예제 #1
0
    def test_create_mapping_positive(self):
        mapping_version = MappingVersion(
            created_by=self.user1,
            updated_by=self.user1,
            parent=self.source1,
            map_type='Same As',
            from_concept=self.concept1,
            to_concept=self.concept2,
            external_id='mappingversion1',
            versioned_object_id=self.mapping1.id,
            mnemonic='tempid',
            versioned_object_type=ContentType.objects.get_for_model(Mapping),
        )
        mapping_version.full_clean()
        mapping_version.save()

        self.assertTrue(MappingVersion.objects.filter(versioned_object_id = self.mapping1.id).exists())
        mapping_version = MappingVersion.objects.get(versioned_object_id = self.mapping1.id)
        self.assertEquals(ACCESS_TYPE_VIEW, mapping_version.public_access)
        self.assertEquals('user1', mapping_version.created_by)
        self.assertEquals('user1', mapping_version.updated_by)
        self.assertEquals(self.source1, mapping_version.parent)
        self.assertEquals('Same As', mapping_version.map_type)
        self.assertEquals(self.concept1, mapping_version.from_concept)
        self.assertEquals(self.concept2, mapping_version.to_concept)
        self.assertEquals(self.source1, mapping_version.from_source)
        self.assertEquals(self.source1.owner_name, mapping_version.from_source_owner)
        self.assertEquals(self.source1.mnemonic, mapping_version.from_source_name)
        self.assertEquals(self.source1, mapping_version.get_to_source())
        self.assertEquals(self.source1.owner_name, mapping_version.to_source_owner)
        self.assertEquals(self.concept2.mnemonic, mapping_version.get_to_concept_code())
        self.assertEquals(self.concept2.display_name, mapping_version.get_to_concept_name())
예제 #2
0
파일: tests.py 프로젝트: AnshuAg/oclapi
    def test_create_mapping_positive(self):
        mapping_version = MappingVersion(
            created_by=self.user1,
            updated_by=self.user1,
            parent=self.source1,
            map_type='Same As',
            from_concept=self.concept1,
            to_concept=self.concept2,
            external_id='mappingversion1',
            versioned_object_id=self.mapping1.id,
            mnemonic='tempid',
            versioned_object_type=ContentType.objects.get_for_model(Mapping),
        )
        mapping_version.full_clean()
        mapping_version.save()

        self.assertTrue(MappingVersion.objects.filter(versioned_object_id = self.mapping1.id).exists())
        mapping_version = MappingVersion.objects.get(versioned_object_id = self.mapping1.id)
        self.assertEquals(ACCESS_TYPE_VIEW, mapping_version.public_access)
        self.assertEquals('user1', mapping_version.created_by)
        self.assertEquals('user1', mapping_version.updated_by)
        self.assertEquals(self.source1, mapping_version.parent)
        self.assertEquals('Same As', mapping_version.map_type)
        self.assertEquals(self.concept1, mapping_version.from_concept)
        self.assertEquals(self.concept2, mapping_version.to_concept)
        self.assertEquals(self.source1, mapping_version.from_source)
        self.assertEquals(self.source1.owner_name, mapping_version.from_source_owner)
        self.assertEquals(self.source1.mnemonic, mapping_version.from_source_name)
        self.assertEquals(self.source1, mapping_version.get_to_source())
        self.assertEquals(self.source1.owner_name, mapping_version.to_source_owner)
        self.assertEquals(self.concept2.mnemonic, mapping_version.get_to_concept_code())
        self.assertEquals(self.concept2.display_name, mapping_version.get_to_concept_name())
    def test_add_duplicate_mapping_reference_different_version_number(self):
        source_with_open_mrs, user = self.create_source_and_user_fixture()
        collection = create_collection(user, CUSTOM_VALIDATION_SCHEMA_OPENMRS)

        (concept_one, errors) = create_concept(mnemonic="ConceptOne", user=self.user1, source=source_with_open_mrs, names=[
            create_localized_text(name='UserOne', locale='es', type='FULLY_SPECIFIED')])

        (concept_two, errors) = create_concept(mnemonic="ConceptTwo", user=self.user1, source=source_with_open_mrs, names=[
            create_localized_text(name='UserTwo', locale='en', type='FULLY_SPECIFIED')])

        mapping = create_mapping(user, source_with_open_mrs, concept_one, concept_two)

        kwargs = {'user': user.username, 'collection': collection.name}

        data = json.dumps({
            'data': {
                'expressions': [mapping.url]
            }
        })

        self.client.put(reverse('collection-references', kwargs=kwargs), data,
                        content_type='application/json')

        mapping_version = MappingVersion(
            created_by=self.user1,
            updated_by=self.user1,
            map_type=mapping.map_type,
            parent=source_with_open_mrs,
            from_concept=concept_two,
            to_concept=concept_one,
            external_id='mapping1',
            versioned_object_id=mapping.id,
            versioned_object_type=ContentType.objects.get_for_model(Mapping),
            mnemonic='1'
        )

        mapping_version.full_clean()
        mapping_version.save()

        data = json.dumps({
            'data': {
                'expressions': [mapping_version.url]
            }
        })

        response = self.client.put(reverse('collection-references', kwargs=kwargs), data,
                                   content_type='application/json')

        self.assertEquals(response.status_code, status.HTTP_200_OK)
        self.assertEquals(response.data, [{'added': False, 'expression': mapping_version.url,
                                           'message': [REFERENCE_ALREADY_EXISTS]}])
예제 #4
0
 def test_create_mapping_negative__no_version_object(self):
     with self.assertRaises(ValidationError):
         mapping_version = MappingVersion(
             created_by=self.user1,
             updated_by=self.user1,
             parent=self.source1,
             map_type='Same As',
             from_concept=self.concept1,
             to_concept=self.concept2,
             external_id='mapping1',
             versioned_object_type=ContentType.objects.get_for_model(Mapping),
             mnemonic='tempid'
         )
         mapping_version.full_clean()
         mapping_version.save()
예제 #5
0
파일: tests.py 프로젝트: AnshuAg/oclapi
 def test_create_mapping_negative__no_version_object(self):
     with self.assertRaises(ValidationError):
         mapping_version = MappingVersion(
             created_by=self.user1,
             updated_by=self.user1,
             parent=self.source1,
             map_type='Same As',
             from_concept=self.concept1,
             to_concept=self.concept2,
             external_id='mapping1',
             versioned_object_type=ContentType.objects.get_for_model(Mapping),
             mnemonic='tempid'
         )
         mapping_version.full_clean()
         mapping_version.save()
예제 #6
0
    def test_mapping_access_changes_with_source(self):
        public_access = self.source1.public_access
        mapping_version = MappingVersion(
            created_by=self.user1,
            updated_by=self.user1,
            parent=self.source1,
            map_type='Same As',
            from_concept=self.concept1,
            to_concept=self.concept2,
            public_access=public_access,
            external_id='mapping1',
            versioned_object_id=self.mapping1.id,
            versioned_object_type=ContentType.objects.get_for_model(Mapping),
            mnemonic='tempid'
        )
        mapping_version.full_clean()
        mapping_version.save()

        self.assertEquals(self.source1.public_access, mapping_version.public_access)
        self.source1.public_access = ACCESS_TYPE_VIEW
        self.source1.save()
예제 #7
0
파일: tests.py 프로젝트: AnshuAg/oclapi
    def test_mapping_access_changes_with_source(self):
        public_access = self.source1.public_access
        mapping_version = MappingVersion(
            created_by=self.user1,
            updated_by=self.user1,
            parent=self.source1,
            map_type='Same As',
            from_concept=self.concept1,
            to_concept=self.concept2,
            public_access=public_access,
            external_id='mapping1',
            versioned_object_id=self.mapping1.id,
            versioned_object_type=ContentType.objects.get_for_model(Mapping),
            mnemonic='tempid'
        )
        mapping_version.full_clean()
        mapping_version.save()

        self.assertEquals(self.source1.public_access, mapping_version.public_access)
        self.source1.public_access = ACCESS_TYPE_VIEW
        self.source1.save()
    def test_add_duplicate_mapping_reference_different_version_number(self):
        source_with_open_mrs, user = self.create_source_and_user_fixture()
        collection = create_collection(user, CUSTOM_VALIDATION_SCHEMA_OPENMRS)

        (concept_one, errors) = create_concept(mnemonic="ConceptOne",
                                               user=self.user1,
                                               source=source_with_open_mrs,
                                               names=[
                                                   create_localized_text(
                                                       name='UserOne',
                                                       locale='es',
                                                       type='FULLY_SPECIFIED')
                                               ])

        (concept_two, errors) = create_concept(mnemonic="ConceptTwo",
                                               user=self.user1,
                                               source=source_with_open_mrs,
                                               names=[
                                                   create_localized_text(
                                                       name='UserTwo',
                                                       locale='en',
                                                       type='FULLY_SPECIFIED')
                                               ])

        mapping = create_mapping(user, source_with_open_mrs, concept_one,
                                 concept_two)

        kwargs = {'user': user.username, 'collection': collection.name}

        data = json.dumps({'data': {'expressions': [mapping.url]}})

        self.client.put(reverse('collection-references', kwargs=kwargs),
                        data,
                        content_type='application/json')

        mapping_version = MappingVersion(
            created_by=self.user1,
            updated_by=self.user1,
            map_type=mapping.map_type,
            parent=source_with_open_mrs,
            from_concept=concept_two,
            to_concept=concept_one,
            external_id='mapping1',
            versioned_object_id=mapping.id,
            versioned_object_type=ContentType.objects.get_for_model(Mapping),
            mnemonic='1')

        mapping_version.full_clean()
        mapping_version.save()

        data = json.dumps({'data': {'expressions': [mapping_version.url]}})

        response = self.client.put(reverse('collection-references',
                                           kwargs=kwargs),
                                   data,
                                   content_type='application/json')

        self.assertEquals(response.status_code, status.HTTP_200_OK)
        self.assertEquals(response.data, [{
            'added': False,
            'expression': mapping_version.url,
            'message': [REFERENCE_ALREADY_EXISTS]
        }])