def test_get_latest_version(self): source = Source(name='source', mnemonic='source', full_name='Source One', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source1.com', description='This is the first test source') kwargs = {'parent_resource': self.org1} Source.persist_new(source, self.user1, **kwargs) concept1 = Concept( mnemonic='concept12', created_by=self.user1, updated_by=self.user1, parent=source, concept_class='First', names=[LocalizedText.objects.create(name='User', locale='es')], ) kwargs = { 'parent_resource': source, } Concept.persist_new(concept1, self.user1, **kwargs) concept = Concept.objects.get(mnemonic=concept1.mnemonic) concept_version1 = ConceptVersion.objects.get( versioned_object_id=concept.id) self.assertEquals(concept.get_latest_version.id, concept_version1.id)
def create_source(user, validation_schema=None, organization=None): suffix = generate_random_string() source = Source( name="source{0}".format(suffix), mnemonic="source{0}".format(suffix), full_name="Source {0}".format(suffix), source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source.com', description='This is a test source', custom_validation_schema=validation_schema ) if organization is not None: kwargs = { 'parent_resource': organization } else: kwargs = { 'parent_resource': create_user_profile(user) } Source.persist_new(source, user, **kwargs) return Source.objects.get(id=source.id)
def setUp(self): User.objects.filter().delete() UserProfile.objects.filter().delete() Organization.objects.filter().delete() Source.objects.filter().delete() SourceVersion.objects.filter().delete() self.user = User.objects.create(username='******', email='*****@*****.**', last_name='One', first_name='User') self.profile = UserProfile.objects.create(user=self.user, mnemonic='user') self.org = Organization.objects.create(name='org', mnemonic='org') self.source = Source(name='source', mnemonic='source', full_name='Source One', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source.com', description='This is the first test source' ) kwargs = { 'parent_resource': self.profile } Source.persist_new(self.source, self.user, **kwargs) self.source = Source.objects.get(id=self.source.id)
def create_sources(self, org, user): sources = dict() kwargs = {'parent_resource': org} for source_name in [ 'Locales', 'Classes', 'Datatypes', 'DescriptionTypes', 'NameTypes', 'MapTypes' ]: source = None if Source.objects.filter(parent_id=org.id, mnemonic=source_name).count() < 1: source = Source(name=source_name, mnemonic=source_name, full_name=source_name, parent=org, created_by=user, default_locale='en', supported_locales=['en'], updated_by=user) Source.persist_new(source, user, **kwargs) else: source = Source.objects.get(parent_id=org.id, mnemonic=source_name) sources[source_name] = source return sources
def create_source(user, validation_schema=None, organization=None, name=None): suffix = generate_random_string() source = Source( name=name if name else "source{0}".format(suffix), mnemonic=name if name else "source{0}".format(suffix), full_name=name if name else "Source {0}".format(suffix), source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source.com', description='This is a test source', custom_validation_schema=validation_schema ) if organization is not None: kwargs = { 'parent_resource': organization } else: kwargs = { 'parent_resource': UserProfile.objects.get(user=user) } Source.persist_new(source, user, **kwargs) return Source.objects.get(id=source.id)
def create_sources(self, org, user): sources = dict() source = None kwargs = { 'parent_resource': org } if Source.objects.filter(parent_id=org.id, mnemonic='Locales').count() < 1: source = Source(name='Locales', mnemonic='Locales', full_name='Locales', parent=org, created_by=user, updated_by=user) Source.persist_new(source, user, **kwargs) else: source = Source.objects.get(parent_id=org.id, mnemonic='Locales') sources['Locales'] = source if Source.objects.filter(parent_id=org.id, mnemonic='Classes').count() < 1: source = Source(name='Classes', mnemonic='Classes', full_name='Classes', parent=org, created_by=user, updated_by=user) Source.persist_new(source, user, **kwargs) else: source = Source.objects.get(parent_id=org.id, mnemonic='Classes') sources['Classes'] = source if Source.objects.filter(parent_id=org.id, mnemonic='Datatypes').count() < 1: source = Source(name='Datatypes', mnemonic='Datatypes', full_name='Datatypes', parent=org, created_by=user, updated_by=user) Source.persist_new(source, user, **kwargs) else: source = Source.objects.get(parent_id=org.id, mnemonic='Datatypes') sources['Datatypes'] = source if Source.objects.filter(parent_id=org.id, mnemonic='DescriptionTypes').count() < 1: source = Source(name='DescriptionTypes', mnemonic='DescriptionTypes', full_name='DescriptionTypes', parent=org, created_by=user, updated_by=user) Source.persist_new(source, user, **kwargs) else: source = Source.objects.get(parent_id=org.id, mnemonic='DescriptionTypes') sources['DescriptionTypes'] = source if Source.objects.filter(parent_id=org.id, mnemonic='NameTypes').count() < 1: source = Source(name='NameTypes', mnemonic='NameTypes', full_name='NameTypes', parent=org, created_by=user, updated_by=user) Source.persist_new(source, user, **kwargs) else: source = Source.objects.get(parent_id=org.id, mnemonic='NameTypes') sources['NameTypes'] = source print sources return sources
def setUp(self): self.user1 = User.objects.create( username='******', email='*****@*****.**', last_name='One', first_name='User' ) self.user2 = User.objects.create( username='******', email='*****@*****.**', last_name='Two', first_name='User' ) self.userprofile1 = UserProfile.objects.create(user=self.user1, mnemonic='user1') self.userprofile2 = UserProfile.objects.create(user=self.user2, mnemonic='user2') self.org1 = Organization.objects.create(name='org1', mnemonic='org1') self.org2 = Organization.objects.create(name='org2', mnemonic='org2') self.source1 = Source( name='source1', mnemonic='source1', full_name='Source One', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source1.com', description='This is the first test source' ) kwargs = { 'parent_resource': self.userprofile1 } Source.persist_new(self.source1, self.user1, **kwargs) self.source1 = Source.objects.get(id=self.source1.id) self.source2 = Source( name='source2', mnemonic='source2', full_name='Source Two', source_type='Reference', public_access=ACCESS_TYPE_VIEW, default_locale='fr', supported_locales=['fr'], website='www.source2.com', description='This is the second test source' ) kwargs = { 'parent_resource': self.org2, } Source.persist_new(self.source2, self.user2, **kwargs) self.source2 = Source.objects.get(id=self.source2.id) self.name = LocalizedText.objects.create(name='Fred', locale='en') self.description = LocalizedText.objects.create(name='guapo', locale='es')
def create_source(self, user, org, name): kwargs = { 'parent_resource': org } if Source.objects.filter(parent_id=org.id, mnemonic=name).count() < 1: source = Source(name=name, mnemonic=name, full_name=name, parent=org, created_by=user, default_locale='en', supported_locales=['en'], updated_by=user) Source.persist_new(source, user, **kwargs) else: source = Source.objects.get(parent_id=org.id, mnemonic=name) return source
def setUp(self): self.user1 = User.objects.create(username='******', password='******', email='*****@*****.**', last_name='One', first_name='User') self.user2 = User.objects.create(username='******', email='*****@*****.**', last_name='Two', first_name='User') self.userprofile1 = UserProfile.objects.create(user=self.user1, mnemonic='user1') self.userprofile2 = UserProfile.objects.create(user=self.user2, mnemonic='user2') self.org1 = Organization.objects.create(name='org1', mnemonic='org1') self.org2 = Organization.objects.create(name='org2', mnemonic='org2') self.source1 = Source(name='source1', mnemonic='source1', full_name='Source One', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source1.com', description='This is the first test source') kwargs = {'parent_resource': self.org1} Source.persist_new(self.source1, self.user1, **kwargs) self.source1 = Source.objects.get(id=self.source1.id) self.source2 = Source(name='source2', mnemonic='source2', full_name='Source Two', source_type='Reference', public_access=ACCESS_TYPE_VIEW, default_locale='fr', supported_locales=['fr'], website='www.source2.com', description='This is the second test source') kwargs = { 'parent_resource': self.org2, } Source.persist_new(self.source2, self.user2, **kwargs) self.source2 = Source.objects.get(id=self.source2.id) self.name = LocalizedText.objects.create(name='Fred', locale='es') self.description = LocalizedText.objects.create(name='guapo', locale='es')
def test_get_head_of_when_head_does_not_exist(self): source = Source(name='source2', mnemonic='source2', full_name='Source Two', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source2.com', description='This is not the first test source') kwargs = {'parent_resource': self.profile} Source.persist_new(source, self.user, **kwargs) source.get_version_model().objects.get( mnemonic='HEAD', versioned_object_id=source.id).delete() self.assertIsNone(SourceVersion.get_head_of(source))
def test_persist_new_negative__no_owner(self): kwargs = { 'parent_resource': self.userprofile1 } errors = Source.persist_new(self.new_source, None, **kwargs) self.assertTrue(errors.has_key('created_by')) self.assertFalse(Source.objects.filter(name='source1').exists())
def test_persist_new_negative__no_name(self): kwargs = { 'parent_resource': self.userprofile1 } self.new_source.name = None errors = Source.persist_new(self.new_source, self.user1, **kwargs) self.assertTrue(errors.has_key('name')) self.assertFalse(Source.objects.filter(name='source1').exists())
def create_source(self, user, org, name): kwargs = {'parent_resource': org} if Source.objects.filter(parent_id=org.id, mnemonic=name).count() < 1: source = Source(name=name, mnemonic=name, full_name=name, parent=org, created_by=user, default_locale='en', supported_locales=['en'], updated_by=user) Source.persist_new(source, user, **kwargs) else: source = Source.objects.get(parent_id=org.id, mnemonic=name) return source
def test_get_head_of_when_head_does_not_exist(self): source = Source(name='source2', mnemonic='source2', full_name='Source Two', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source2.com', description='This is not the first test source' ) kwargs = { 'parent_resource': self.profile } Source.persist_new(source, self.user, **kwargs) source.get_version_model().objects.get(mnemonic='HEAD', versioned_object_id=source.id).delete() self.assertIsNone(SourceVersion.get_head_of(source))
def create_sources(self, org, user): sources = dict() kwargs = { 'parent_resource': org } for source_name in ['Locales', 'Classes', 'Datatypes', 'DescriptionTypes', 'NameTypes', 'MapTypes']: source = None if Source.objects.filter(parent_id=org.id, mnemonic=source_name).count() < 1: source = Source(name=source_name, mnemonic=source_name, full_name=source_name, parent=org, created_by=user, default_locale='en', supported_locales=['en'], updated_by=user) Source.persist_new(source, user, **kwargs) else: source = Source.objects.get(parent_id=org.id, mnemonic=source_name) sources[source_name] = source return sources
def test_persist_new_positive(self): kwargs = { 'parent_resource': self.userprofile1 } errors = Source.persist_new(self.new_source, self.user1, **kwargs) self.assertEquals(0, len(errors)) self.assertTrue(Source.objects.filter(name='source1').exists()) source = Source.objects.get(name='source1') self.assertTrue(SourceVersion.objects.filter(versioned_object_id=source.id)) source_version = SourceVersion.objects.get(versioned_object_id=source.id) self.assertEquals(1, source.num_versions) self.assertEquals(source_version, SourceVersion.get_latest_version_of(source))
def setUp(self): self.user = User.objects.create(username='******', email='*****@*****.**', last_name='One', first_name='User') self.profile = UserProfile.objects.create(user=self.user, mnemonic='user') self.org = Organization.objects.create(name='org', mnemonic='org') self.source = Source(name='source', mnemonic='source', full_name='Source One', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source.com', description='This is the first test source' ) kwargs = { 'parent_resource': self.profile } Source.persist_new(self.source, self.user, **kwargs) self.source = Source.objects.get(id=self.source.id)
def test_persist_changes_positive(self): kwargs = { 'parent_resource': self.userprofile1 } errors = Source.persist_new(self.new_source, self.user1, **kwargs) self.assertEquals(0, len(errors)) id = self.new_source.id name = self.new_source.name mnemonic = self.new_source.mnemonic full_name = self.new_source.full_name source_type = self.new_source.source_type public_access = self.new_source.public_access default_locale = self.new_source.default_locale supported_locales = self.new_source.supported_locales website = self.new_source.website description = self.new_source.description self.new_source.name = "%s_prime" % name self.new_source.mnemonic = "%s-prime" % mnemonic self.new_source.full_name = "%s_prime" % full_name self.new_source.source_type = 'Reference' self.new_source.public_access = ACCESS_TYPE_VIEW self.new_source.default_locale = "%s_prime" % default_locale self.new_source.supported_locales = ["%s_prime" % supported_locales[0]] self.new_source.website = "%s_prime" % website self.new_source.description = "%s_prime" % description errors = Source.persist_changes(self.new_source, self.user1, **kwargs) self.assertEquals(0, len(errors)) self.assertTrue(Source.objects.filter(id=id).exists()) self.assertTrue(SourceVersion.objects.filter(versioned_object_id=id)) source_version = SourceVersion.objects.get(versioned_object_id=id) self.assertEquals(1, self.new_source.num_versions) self.assertEquals(source_version, SourceVersion.get_latest_version_of(self.new_source)) self.new_source = Source.objects.get(id=id) self.assertNotEquals(name, self.new_source.name) self.assertNotEquals(mnemonic, self.new_source.mnemonic) self.assertNotEquals(full_name, self.new_source.full_name) self.assertNotEquals(source_type, self.new_source.source_type) self.assertNotEquals(public_access, self.new_source.public_access) self.assertNotEquals(default_locale, self.new_source.default_locale) self.assertNotEquals(supported_locales, self.new_source.supported_locales) self.assertNotEquals(website, self.new_source.website) self.assertNotEquals(description, self.new_source.description)
def test_collections_version_ids(self): kwargs = { 'parent_resource': self.userprofile1 } collection = Collection( name='collection2', mnemonic='collection2', full_name='Collection Two', collection_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.collection2.com', description='This is the second test collection' ) Collection.persist_new(collection, self.user1, **kwargs) source = Source( name='source', mnemonic='source', full_name='Source One', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source1.com', description='This is the first test source' ) kwargs = { 'parent_resource': self.org1 } Source.persist_new(source, self.user1, **kwargs) (concept1, errors) = create_concept(mnemonic='concept12', user=self.user1, source=source) (from_concept, errors) = create_concept(mnemonic='fromConcept', user=self.user1, source=source) (to_concept, errors) = create_concept(mnemonic='toConcept', user=self.user1, source=source) mapping = Mapping( map_type='Same As', from_concept=from_concept, to_concept=to_concept, external_id='mapping', ) kwargs = { 'parent_resource': source, } Mapping.persist_new(mapping, self.user1, **kwargs) mapping = Mapping.objects.filter()[1] mapping_reference = '/orgs/org1/sources/source/mappings/' + mapping.id + '/' references = [mapping_reference] collection.expressions = references collection.full_clean() collection.save() mapping_version = MappingVersion.objects.filter()[0] collection_version = CollectionVersion( name='version1', mnemonic='version1', versioned_object=collection, released=True, created_by=self.user1, updated_by=self.user1, mappings=[mapping_version.id] ) collection_version.full_clean() collection_version.save() self.assertEquals(mapping_version.collection_version_ids, [collection_version.id])
def setUp(self): self.user1 = User.objects.create_user(username='******', email='*****@*****.**', password='******', last_name='One', first_name='User') self.user2 = User.objects.create_user(username='******', email='*****@*****.**', password='******', last_name='Two', first_name='User') self.userprofile1 = UserProfile.objects.create(user=self.user1, mnemonic='user1') self.userprofile2 = UserProfile.objects.create(user=self.user2, mnemonic='user2') self.org1 = Organization.objects.create(name='org1', mnemonic='org1') self.org2 = Organization.objects.create(name='org2', mnemonic='org2') add_user_to_org(self.userprofile2, self.org2) self.source1 = Source( name='source1', mnemonic='source1', full_name='Source One', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source1.com', description='This is the first test source', ) kwargs = {'parent_resource': self.userprofile1} Source.persist_new(self.source1, self.user1, **kwargs) self.source1 = Source.objects.get(id=self.source1.id) self.source2 = Source( name='source2', mnemonic='source2', full_name='Source Two', source_type='Reference', public_access=ACCESS_TYPE_VIEW, default_locale='fr', supported_locales=['fr'], website='www.source2.com', description='This is the second test source', ) kwargs = { 'parent_resource': self.org2, } Source.persist_new(self.source2, self.user1, **kwargs) self.source2 = Source.objects.get(id=self.source2.id) self.name = LocalizedText.objects.create(name='Fred', locale='en') self.concept1 = Concept( mnemonic='concept1', updated_by=self.user1, parent=self.source1, concept_class='First', names=[self.name], ) kwargs = { 'parent_resource': self.source1, } Concept.persist_new(self.concept1, self.user1, **kwargs) self.concept2 = Concept( mnemonic='concept2', updated_by=self.user1, parent=self.source1, concept_class='Second', names=[self.name], ) kwargs = { 'parent_resource': self.source1, } Concept.persist_new(self.concept2, self.user1, **kwargs) self.concept3 = Concept( mnemonic='concept3', updated_by=self.user1, parent=self.source2, concept_class='Third', names=[self.name], ) kwargs = { 'parent_resource': self.source2, } Concept.persist_new(self.concept3, self.user1, **kwargs) self.concept4 = Concept( mnemonic='concept4', updated_by=self.user2, parent=self.source2, concept_class='Fourth', names=[self.name], ) kwargs = { 'parent_resource': self.source2, } Concept.persist_new(self.concept4, self.user1, **kwargs)
def test_collections_ids(self): kwargs = { 'parent_resource': self.userprofile1 } collection = Collection( name='collection2', mnemonic='collection2', full_name='Collection Two', collection_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.collection2.com', description='This is the second test collection' ) Collection.persist_new(collection, self.user1, **kwargs) source = Source( name='source', mnemonic='source', full_name='Source One', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source1.com', description='This is the first test source' ) kwargs = { 'parent_resource': self.org1 } Source.persist_new(source, self.user1, **kwargs) (concept1, errors) = create_concept(mnemonic='concept12', user=self.user1, source=source) (from_concept, errors) = create_concept(mnemonic='fromConcept', user=self.user1, source=source) (to_concept, errors) = create_concept(mnemonic='toConcept', user=self.user1, source=source) mapping = Mapping( map_type='Same As', from_concept=from_concept, to_concept=to_concept, external_id='mapping', ) kwargs = { 'parent_resource': source, } Mapping.persist_new(mapping, self.user1, **kwargs) initial_mapping_version = MappingVersion.objects.get(versioned_object_id=mapping.id) new_mapping_version = MappingVersion.for_mapping(mapping) new_mapping_version.mnemonic = 98 new_mapping_version.save() from_concept_reference = '/orgs/org1/sources/source/concepts/' + Concept.objects.get(mnemonic=from_concept.mnemonic).mnemonic + '/' concept1_reference = '/orgs/org1/sources/source/concepts/' + Concept.objects.get(mnemonic=concept1.mnemonic).mnemonic + '/' mapping = Mapping.objects.filter()[1] references = [concept1_reference, from_concept_reference, mapping.uri, initial_mapping_version.uri] collection.expressions = references collection.full_clean() collection.save() self.assertEquals(initial_mapping_version.collection_ids, [collection.id]) self.assertEquals(new_mapping_version.collection_ids, [collection.id])
def setUp(self): super(MappingBaseTest, self).setUp() self.user1 = User.objects.create_user( username='******', email='*****@*****.**', password='******', last_name='One', first_name='User' ) self.user2 = User.objects.create_user( username='******', email='*****@*****.**', password='******', last_name='Two', first_name='User' ) self.userprofile1 = UserProfile.objects.create(user=self.user1, mnemonic='user1') self.userprofile2 = UserProfile.objects.create(user=self.user2, mnemonic='user2') self.org1 = Organization.objects.create(name='org1', mnemonic='org1') self.org2 = Organization.objects.create(name='org2', mnemonic='org2') add_user_to_org(self.userprofile2, self.org2) self.source1 = Source( name='source1', mnemonic='source1', full_name='Source One', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source1.com', description='This is the first test source', ) kwargs = { 'parent_resource': self.userprofile1 } Source.persist_new(self.source1, self.user1, **kwargs) self.source1 = Source.objects.get(id=self.source1.id) self.source2 = Source( name='source2', mnemonic='source2', full_name='Source Two', source_type='Reference', public_access=ACCESS_TYPE_VIEW, default_locale='fr', supported_locales=['fr'], website='www.source2.com', description='This is the second test source', ) kwargs = { 'parent_resource': self.org2, } Source.persist_new(self.source2, self.user1, **kwargs) self.source2 = Source.objects.get(id=self.source2.id) self.name = LocalizedText.objects.create(name='Fred', locale='en', type='FULLY_SPECIFIED') (self.concept1, errors) = create_concept(mnemonic='concept1', user=self.user1, source=self.source1, names=[self.name], descriptions=[self.name]) (self.concept2, errors) = create_concept(mnemonic='concept2', user=self.user1, source=self.source1, names=[self.name], descriptions=[self.name]) (self.concept3, errors) = create_concept(mnemonic='concept3', user=self.user1, source=self.source2, names=[self.name], descriptions=[self.name]) (self.concept4, errors) = create_concept(mnemonic='concept4', user=self.user1, source=self.source2, names=[self.name], descriptions=[self.name])
def test_persist_new_negative__no_parent(self): errors = Source.persist_new(self.new_source, self.user1) self.assertTrue(errors.has_key('parent')) self.assertFalse(Source.objects.filter(name='source1').exists())
def test_collections_version_ids(self): kwargs = { 'parent_resource': self.userprofile1 } collection = Collection( name='collection2', mnemonic='collection2', full_name='Collection Two', collection_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.collection2.com', description='This is the second test collection' ) Collection.persist_new(collection, self.user1, **kwargs) source = Source( name='source', mnemonic='source', full_name='Source One', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source1.com', description='This is the first test source' ) kwargs = { 'parent_resource': self.org1 } Source.persist_new(source, self.user1, **kwargs) concept1 = Concept( mnemonic='concept12', created_by=self.user1, updated_by=self.user1, parent=source, concept_class='First', names=[LocalizedText.objects.create(name='User', locale='es', type='FULLY_SPECIFIED')], ) kwargs = { 'parent_resource': source, } Concept.persist_new(concept1, self.user1, **kwargs) fromConcept = Concept( mnemonic='fromConcept', created_by=self.user1, updated_by=self.user1, parent=source, concept_class='First', names=[LocalizedText.objects.create(name='User', locale='es', type='FULLY_SPECIFIED')], ) kwargs = { 'parent_resource': source, } Concept.persist_new(fromConcept, self.user1, **kwargs) toConcept = Concept( mnemonic='toConcept', created_by=self.user1, updated_by=self.user1, parent=source, concept_class='First', names=[LocalizedText.objects.create(name='User', locale='es', type='FULLY_SPECIFIED')], ) kwargs = { 'parent_resource': source, } Concept.persist_new(toConcept, self.user1, **kwargs) mapping = Mapping( map_type='Same As', from_concept=fromConcept, to_concept=toConcept, external_id='mapping', ) kwargs = { 'parent_resource': source, } Mapping.persist_new(mapping, self.user1, **kwargs) mapping = Mapping.objects.filter()[1] mapping_reference = '/orgs/org1/sources/source/mappings/' + mapping.id + '/' references = [mapping_reference] collection.expressions = references collection.full_clean() collection.save() mapping_version = MappingVersion.objects.filter()[0] collection_version = CollectionVersion( name='version1', mnemonic='version1', versioned_object=collection, released=True, created_by=self.user1, updated_by=self.user1, mappings=[mapping_version.id] ) collection_version.full_clean() collection_version.save() self.assertEquals(mapping_version.collection_version_ids, [collection_version.id])
def save_object(self, obj, **kwargs): request_user = self.context['request'].user errors = Source.persist_new(obj, request_user, **kwargs) self._errors.update(errors)
def setUp(self): self.user1 = User.objects.create_user( username='******', email='*****@*****.**', password='******', last_name='One', first_name='User' ) self.user2 = User.objects.create_user( username='******', email='*****@*****.**', password='******', last_name='Two', first_name='User' ) self.userprofile1 = UserProfile.objects.create(user=self.user1, mnemonic='user1') self.userprofile2 = UserProfile.objects.create(user=self.user2, mnemonic='user2') self.org1 = Organization.objects.create(name='org1', mnemonic='org1') self.org2 = Organization.objects.create(name='org2', mnemonic='org2') add_user_to_org(self.userprofile2, self.org2) self.source1 = Source( name='source1', mnemonic='source1', full_name='Source One', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source1.com', description='This is the first test source', ) kwargs = { 'parent_resource': self.userprofile1 } Source.persist_new(self.source1, self.user1, **kwargs) self.source1 = Source.objects.get(id=self.source1.id) self.source2 = Source( name='source2', mnemonic='source2', full_name='Source Two', source_type='Reference', public_access=ACCESS_TYPE_VIEW, default_locale='fr', supported_locales=['fr'], website='www.source2.com', description='This is the second test source', ) kwargs = { 'parent_resource': self.org2, } Source.persist_new(self.source2, self.user1, **kwargs) self.source2 = Source.objects.get(id=self.source2.id) self.name = LocalizedText.objects.create(name='Fred', locale='en', type='FULLY_SPECIFIED') self.concept1 = Concept( mnemonic='concept1', updated_by=self.user1, parent=self.source1, concept_class='First', names=[self.name], ) kwargs = { 'parent_resource': self.source1, } Concept.persist_new(self.concept1, self.user1, **kwargs) self.concept2 = Concept( mnemonic='concept2', updated_by=self.user1, parent=self.source1, concept_class='Second', names=[self.name], ) kwargs = { 'parent_resource': self.source1, } Concept.persist_new(self.concept2, self.user1, **kwargs) self.concept3 = Concept( mnemonic='concept3', updated_by=self.user1, parent=self.source2, concept_class='Third', names=[self.name], ) kwargs = { 'parent_resource': self.source2, } Concept.persist_new(self.concept3, self.user1, **kwargs) self.concept4 = Concept( mnemonic='concept4', updated_by=self.user2, parent=self.source2, concept_class='Fourth', names=[self.name], ) kwargs = { 'parent_resource': self.source2, } Concept.persist_new(self.concept4, self.user1, **kwargs)
def test_collections_version_ids(self): kwargs = {'parent_resource': self.userprofile1} collection = Collection( name='collection2', mnemonic='collection2', full_name='Collection Two', collection_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.collection2.com', description='This is the second test collection') Collection.persist_new(collection, self.user1, **kwargs) source = Source(name='source', mnemonic='source', full_name='Source One', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source1.com', description='This is the first test source') kwargs = {'parent_resource': self.org1} Source.persist_new(source, self.user1, **kwargs) concept1 = Concept( mnemonic='concept12', created_by=self.user1, updated_by=self.user1, parent=source, concept_class='First', names=[LocalizedText.objects.create(name='User', locale='es')], ) kwargs = { 'parent_resource': source, } Concept.persist_new(concept1, self.user1, **kwargs) another_concept = Concept( mnemonic='anotherConcept', created_by=self.user1, updated_by=self.user1, parent=source, concept_class='First', names=[LocalizedText.objects.create(name='User', locale='es')], ) kwargs = { 'parent_resource': source, } Concept.persist_new(another_concept, self.user1, **kwargs) another_concept_reference = '/orgs/org1/sources/source/concepts/' + Concept.objects.get( mnemonic=another_concept.mnemonic).mnemonic + '/' concept1_reference = '/orgs/org1/sources/source/concepts/' + Concept.objects.get( mnemonic=concept1.mnemonic).mnemonic + '/' references = [concept1_reference, another_concept_reference] collection.expressions = references collection.full_clean() collection.save() concept_version = ConceptVersion.objects.get( versioned_object_id=Concept.objects.get( mnemonic=another_concept.mnemonic).id) version = CollectionVersion.for_base_object(collection, 'version1') kwargs = {} CollectionVersion.persist_new(version, **kwargs) self.assertEquals( concept_version.collection_version_ids, [CollectionVersion.objects.get(mnemonic='version1').id])
def test_persist_changes_negative__repeated_mnemonic(self): kwargs = { 'parent_resource': self.userprofile1 } errors = Source.persist_new(self.new_source, self.user1, **kwargs) self.assertEquals(0, len(errors)) source = Source( name='source2', mnemonic='source2', full_name='Source Two', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source2.com', description='This is the second test source' ) errors = Source.persist_new(source, self.user1, **kwargs) self.assertEquals(0, len(errors)) self.assertEquals(2, Source.objects.all().count()) self.new_source = Source.objects.get(mnemonic='source2') id = self.new_source.id name = self.new_source.name mnemonic = self.new_source.mnemonic full_name = self.new_source.full_name source_type = self.new_source.source_type public_access = self.new_source.public_access default_locale = self.new_source.default_locale supported_locales = self.new_source.supported_locales website = self.new_source.website description = self.new_source.description self.new_source.mnemonic = 'source1' self.new_source.name = "%s_prime" % name self.new_source.full_name = "%s_prime" % full_name self.new_source.source_type = 'Reference' self.new_source.public_access = ACCESS_TYPE_VIEW self.new_source.default_locale = "%s_prime" % default_locale self.new_source.supported_locales = ["%s_prime" % supported_locales[0]] self.new_source.website = "%s_prime" % website self.new_source.description = "%s_prime" % description errors = Source.persist_changes(self.new_source, self.user1, **kwargs) self.assertEquals(1, len(errors)) self.assertTrue(errors.has_key('__all__')) self.assertTrue(Source.objects.filter(id=id).exists()) self.assertTrue(SourceVersion.objects.filter(versioned_object_id=id)) source_version = SourceVersion.objects.get(versioned_object_id=id) self.assertEquals(1, self.new_source.num_versions) self.assertEquals(source_version, SourceVersion.get_latest_version_of(self.new_source)) self.new_source = Source.objects.get(id=id) self.assertEquals(name, self.new_source.name) self.assertEquals(mnemonic, self.new_source.mnemonic) self.assertEquals(full_name, self.new_source.full_name) self.assertEquals(source_type, self.new_source.source_type) self.assertEquals(public_access, self.new_source.public_access) self.assertEquals(default_locale, self.new_source.default_locale) self.assertEquals(supported_locales, self.new_source.supported_locales) self.assertEquals(website, self.new_source.website) self.assertEquals(description, self.new_source.description)
def test_collections_version_ids(self): kwargs = {'parent_resource': self.userprofile1} collection = Collection( name='collection2', mnemonic='collection2', full_name='Collection Two', collection_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.collection2.com', description='This is the second test collection') Collection.persist_new(collection, self.user1, **kwargs) source = Source(name='source', mnemonic='source', full_name='Source One', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source1.com', description='This is the first test source') kwargs = {'parent_resource': self.org1} Source.persist_new(source, self.user1, **kwargs) concept1 = Concept( mnemonic='concept12', created_by=self.user1, updated_by=self.user1, parent=source, concept_class='First', names=[LocalizedText.objects.create(name='User', locale='es')], ) kwargs = { 'parent_resource': source, } Concept.persist_new(concept1, self.user1, **kwargs) fromConcept = Concept( mnemonic='fromConcept', created_by=self.user1, updated_by=self.user1, parent=source, concept_class='First', names=[LocalizedText.objects.create(name='User', locale='es')], ) kwargs = { 'parent_resource': source, } Concept.persist_new(fromConcept, self.user1, **kwargs) toConcept = Concept( mnemonic='toConcept', created_by=self.user1, updated_by=self.user1, parent=source, concept_class='First', names=[LocalizedText.objects.create(name='User', locale='es')], ) kwargs = { 'parent_resource': source, } Concept.persist_new(toConcept, self.user1, **kwargs) mapping = Mapping( map_type='Same As', from_concept=fromConcept, to_concept=toConcept, external_id='mapping', ) kwargs = { 'parent_resource': source, } Mapping.persist_new(mapping, self.user1, **kwargs) from_concept_reference = '/orgs/org1/sources/source/concepts/' + Concept.objects.get( mnemonic=fromConcept.mnemonic).mnemonic + '/' concept1_reference = '/orgs/org1/sources/source/concepts/' + Concept.objects.get( mnemonic=concept1.mnemonic).mnemonic + '/' mapping = Mapping.objects.filter()[1] mapping_reference = '/orgs/org1/sources/source/mappings/' + mapping.id + '/' references = [ concept1_reference, from_concept_reference, mapping_reference ] collection.expressions = references collection.full_clean() collection.save() self.assertEquals(mapping.collection_version_ids, [ Collection.objects.get(mnemonic=collection.mnemonic).get_head().id ])
def create_sources(self, org, user): sources = dict() source = None kwargs = {'parent_resource': org} if Source.objects.filter(parent_id=org.id, mnemonic='Locales').count() < 1: source = Source(name='Locales', mnemonic='Locales', full_name='Locales', parent=org, created_by=user, updated_by=user) Source.persist_new(source, user, **kwargs) else: source = Source.objects.get(parent_id=org.id, mnemonic='Locales') sources['Locales'] = source if Source.objects.filter(parent_id=org.id, mnemonic='Classes').count() < 1: source = Source(name='Classes', mnemonic='Classes', full_name='Classes', parent=org, created_by=user, updated_by=user) Source.persist_new(source, user, **kwargs) else: source = Source.objects.get(parent_id=org.id, mnemonic='Classes') sources['Classes'] = source if Source.objects.filter(parent_id=org.id, mnemonic='Datatypes').count() < 1: source = Source(name='Datatypes', mnemonic='Datatypes', full_name='Datatypes', parent=org, created_by=user, updated_by=user) Source.persist_new(source, user, **kwargs) else: source = Source.objects.get(parent_id=org.id, mnemonic='Datatypes') sources['Datatypes'] = source if Source.objects.filter(parent_id=org.id, mnemonic='DescriptionTypes').count() < 1: source = Source(name='DescriptionTypes', mnemonic='DescriptionTypes', full_name='DescriptionTypes', parent=org, created_by=user, updated_by=user) Source.persist_new(source, user, **kwargs) else: source = Source.objects.get(parent_id=org.id, mnemonic='DescriptionTypes') sources['DescriptionTypes'] = source if Source.objects.filter(parent_id=org.id, mnemonic='NameTypes').count() < 1: source = Source(name='NameTypes', mnemonic='NameTypes', full_name='NameTypes', parent=org, created_by=user, updated_by=user) Source.persist_new(source, user, **kwargs) else: source = Source.objects.get(parent_id=org.id, mnemonic='NameTypes') sources['NameTypes'] = source print sources return sources