Beispiel #1
0
    def test_source_version_create_positive__same_mnemonic(self):
        source_version = SourceVersion(
            name='version1',
            mnemonic='version1',
            versioned_object=self.source1,
            created_by=self.user1,
            updated_by=self.user1,
        )
        source_version.full_clean()
        source_version.save()
        self.assertTrue(SourceVersion.objects.filter(
            mnemonic='version1',
            versioned_object_type=ContentType.objects.get_for_model(Source),
            versioned_object_id=self.source1.id
        ).exists())
        self.assertEquals(1, self.source1.num_versions)

        source_version = SourceVersion(
            name='version1',
            mnemonic='version1',
            versioned_object=self.source2,
            created_by=self.user1,
            updated_by=self.user1,
        )
        source_version.full_clean()
        source_version.save()
        self.assertTrue(SourceVersion.objects.filter(
            mnemonic='version1',
            versioned_object_type=ContentType.objects.get_for_model(Source),
            versioned_object_id=self.source2.id
        ).exists())
        self.assertEquals(1, self.source2.num_versions)
Beispiel #2
0
    def test_source_version_create_negative__same_mnemonic(self):
        source_version = SourceVersion(
            name='version1',
            mnemonic='version1',
            versioned_object=self.source1,
            created_by=self.user1,
            updated_by=self.user1,

        )
        source_version.full_clean()
        source_version.save()
        self.assertEquals(1, self.source1.num_versions)

        with self.assertRaises(ValidationError):
            source_version = SourceVersion(
                name='version1',
                mnemonic='version1',
                versioned_object=self.source1,
                created_by=self.user1,
                updated_by=self.user1,

            )
            source_version.full_clean()
            source_version.save()
        self.assertEquals(1, self.source1.num_versions)
Beispiel #3
0
    def test_source_version_create_positive(self):
        source_version = SourceVersion(
            name='version1',
            mnemonic='version1',
            versioned_object=self.source1,
            released=True,
            created_by=self.user1,
            updated_by=self.user1,
        )
        source_version.full_clean()
        source_version.save()
        self.assertTrue(SourceVersion.objects.filter(
            mnemonic='version1',
            versioned_object_type=ContentType.objects.get_for_model(Source),
            versioned_object_id=self.source1.id
        ).exists())

        self.assertIsNone(source_version.previous_version)
        self.assertIsNone(source_version.previous_version_mnemonic)
        self.assertIsNone(source_version.parent_version)
        self.assertIsNone(source_version.parent_version_mnemonic)

        self.assertEquals(self.org1.mnemonic, source_version.parent_resource)
        self.assertEquals(self.org1.resource_type, source_version.parent_resource_type)

        self.assertEquals(source_version, SourceVersion.get_latest_version_of(self.source1))
        self.assertEquals(1, self.source1.num_versions)
Beispiel #4
0
 def test_source_version_create_negative__no_source(self):
     with self.assertRaises(ValidationError):
         source_version = SourceVersion(
             mnemonic='version1',
             name='version1',
             created_by=self.user1,
             updated_by=self.user1,
         )
         source_version.full_clean()
         source_version.save()
     self.assertEquals(0, self.source1.num_versions)
Beispiel #5
0
    def test_get_latest_version_of(self):
        latest_version_identity = 'version'
        expected_latest_source_version = SourceVersion(
            name=latest_version_identity,
            mnemonic=latest_version_identity,
            versioned_object=self.source,
            released=True,
            created_by=self.user,
            updated_by=self.user,
        )
        expected_latest_source_version.full_clean()
        expected_latest_source_version.save()

        self.assertEquals(SourceVersion.get_latest_version_of(self.source).name, latest_version_identity)
Beispiel #6
0
    def test_get_latest_version_of(self):
        latest_version_identity = 'version'
        expected_latest_source_version = SourceVersion(
            name=latest_version_identity,
            mnemonic=latest_version_identity,
            versioned_object=self.source,
            released=True,
            created_by=self.user,
            updated_by=self.user,
        )
        expected_latest_source_version.full_clean()
        expected_latest_source_version.save()

        self.assertEquals(SourceVersion.get_latest_version_of(self.source).name, latest_version_identity)
Beispiel #7
0
    def test_dispatch_with_head_and_versions(self):
        source_version = SourceVersion(
            name='version1',
            mnemonic='version1',
            versioned_object=self.source1,
            released=True,
            created_by=self.user1,
            updated_by=self.user1,
        )
        source_version.full_clean()
        source_version.save()

        concept2 = Concept(
            mnemonic='concept2',
            created_by=self.user1,
            updated_by=self.user1,
            parent=self.source1,
            concept_class='not First',
            external_id='EXTID',
            names=[self.name],
        )
        display_name = LocalizedText(
            name='concept2',
            locale='en'
        )
        concept2.names.append(display_name)
        kwargs = {
            'parent_resource': self.source1,
        }
        Concept.persist_new(concept2, self.user1, **kwargs)


        self.client.login(username='******', password='******')

        kwargs = {
            'org': self.org1.mnemonic,
            'source': self.source1.mnemonic
        }
        response = self.client.get(reverse('concept-create', kwargs=kwargs))
        self.assertEquals(response.status_code, 200)
        content = json.loads(response.content)
        self.assertEquals(2, len(content))
        source_head_concepts = SourceVersion.objects.get(mnemonic='HEAD', versioned_object_id=self.source1.id).concepts
        self.assertEquals(2, len(source_head_concepts))
        for concept in content:
            self.assertTrue(concept['version'] in source_head_concepts)
Beispiel #8
0
    def test_source_version_create_positive__child_and_subsequent_versions(self):
        version1 = SourceVersion(
            name='version1',
            mnemonic='version1',
            versioned_object=self.source1,
            released=True,
            created_by=self.user1,
            updated_by=self.user1,
        )
        version1.full_clean()
        version1.save()
        self.assertTrue(SourceVersion.objects.filter(
            mnemonic='version1',
            versioned_object_type=ContentType.objects.get_for_model(Source),
            versioned_object_id=self.source1.id
        ).exists())
        self.assertEquals(version1, SourceVersion.get_latest_version_of(self.source1))
        self.assertEquals(1, self.source1.num_versions)

        version2 = SourceVersion(
            name='version2',
            mnemonic='version2',
            versioned_object=self.source1,
            parent_version=version1,
            created_by=self.user1,
            updated_by=self.user1,
        )
        version2.full_clean()
        version2.save()
        self.assertTrue(SourceVersion.objects.filter(
            mnemonic='version2',
            versioned_object_type=ContentType.objects.get_for_model(Source),
            versioned_object_id=self.source1.id
        ).exists())
        self.assertEquals(version1, version2.parent_version)
        self.assertEquals(version1.mnemonic, version2.parent_version_mnemonic)
        self.assertIsNone(version2.previous_version)
        self.assertIsNone(version2.previous_version_mnemonic)
        self.assertEquals(2, self.source1.num_versions)

        version3 = SourceVersion(
            name='version3',
            mnemonic='version3',
            versioned_object=self.source1,
            previous_version=version2,
            created_by=self.user1,
            updated_by=self.user1,
        )
        version3.full_clean()
        version3.save()
        self.assertTrue(SourceVersion.objects.filter(
            mnemonic='version3',
            versioned_object_type=ContentType.objects.get_for_model(Source),
            versioned_object_id=self.source1.id
        ).exists())
        self.assertEquals(version2, version3.previous_version)
        self.assertEquals(version2.mnemonic, version3.previous_version_mnemonic)
        self.assertIsNone(version3.parent_version)
        self.assertIsNone(version3.parent_version_mnemonic)
        self.assertEquals(3, self.source1.num_versions)
Beispiel #9
0
    def test_delete_organization_with_sources_and_collections(self):
        org = Organization(mnemonic='org1',
                           name='My Organization',
                           created_by=self.user,
                           updated_by=self.user)
        org.full_clean()
        org.save()
        org_id = org.id

        org = Organization.objects.get(id=org.id)
        user1 = UserProfile.objects.get(mnemonic=self.user.username)
        org.members.append(user1.id)
        user1.organizations.append(org.id)
        org.save()
        user1.save()

        source = Source(name='source1',
                        mnemonic='source1',
                        full_name='Source One',
                        parent=org,
                        created_by=self.user,
                        updated_by=self.user)
        source.full_clean()
        source.save()

        source2 = Source(name='source2',
                         mnemonic='source2',
                         full_name='Source Two',
                         parent=org,
                         created_by=self.user,
                         updated_by=self.user)
        source2.full_clean()
        source2.save()

        source_version = SourceVersion(
            name='version1',
            mnemonic='version1',
            versioned_object=source2,
            released=True,
            created_by=self.user,
            updated_by=self.user,
        )
        source_version.full_clean()
        source_version.save()

        source_version2 = SourceVersion(
            name='version2',
            mnemonic='version2',
            versioned_object=source2,
            released=True,
            created_by=self.user,
            updated_by=self.user,
        )
        source_version2.full_clean()
        source_version2.save()

        collection = Collection.objects.create(name='collection1',
                                               mnemonic='collection1',
                                               created_by=self.user,
                                               updated_by=self.user,
                                               parent=org,
                                               external_id='EXTID1')

        collection_version = CollectionVersion(
            name='version1',
            mnemonic='version1',
            versioned_object=collection,
            released=True,
            created_by='user1',
            updated_by='user1',
        )
        collection_version.full_clean()
        collection_version.save()

        collection_version2 = CollectionVersion(
            name='version2',
            mnemonic='version2',
            versioned_object=collection,
            released=True,
            created_by=self.user,
            updated_by=self.user,
        )
        collection_version2.full_clean()
        collection_version2.save()

        collection2 = Collection.objects.create(name='collection2',
                                                mnemonic='collection2',
                                                created_by=self.user,
                                                updated_by=self.user,
                                                parent=org,
                                                external_id='EXTID2')

        self.assertTrue(Organization.objects.filter(id=org_id).exists())

        self.assertTrue(Source.objects.filter(id=source.id).exists())
        self.assertTrue(Source.objects.filter(id=source2.id).exists())

        self.assertTrue(
            SourceVersion.objects.filter(id=source_version.id).exists())
        self.assertTrue(
            SourceVersion.objects.filter(id=source_version2.id).exists())

        self.assertTrue(Collection.objects.filter(id=collection.id).exists())
        self.assertTrue(Collection.objects.filter(id=collection2.id).exists())

        self.assertTrue(
            CollectionVersion.objects.filter(
                id=collection_version.id).exists())
        self.assertTrue(
            CollectionVersion.objects.filter(
                id=collection_version2.id).exists())

        org.delete()
        self.assertFalse(Organization.objects.filter(id=org.id).exists())

        self.assertFalse(Source.objects.filter(id=source.id).exists())
        self.assertFalse(Source.objects.filter(id=source2.id).exists())

        self.assertFalse(
            SourceVersion.objects.filter(id=source_version.id).exists())
        self.assertFalse(
            SourceVersion.objects.filter(id=source_version2.id).exists())

        self.assertFalse(Collection.objects.filter(id=collection.id).exists())
        self.assertFalse(Collection.objects.filter(id=collection2.id).exists())

        self.assertFalse(
            CollectionVersion.objects.filter(
                id=collection_version.id).exists())
        self.assertFalse(
            CollectionVersion.objects.filter(
                id=collection_version2.id).exists())

        #should not delete member user
        self.assertTrue(
            UserProfile.objects.filter(mnemonic=self.user.username).exists())
        #should delete org from organizations on user
        self.assertFalse(org_id in UserProfile.objects.get(
            mnemonic=self.user.username).organizations)