def setUp(self): super(ConceptReferenceClassMethodsTest, self).setUp() self.collection1 = Collection( name='collection1', mnemonic='collection1', full_name='Collection One', collection_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.collection1.com', description='This is the first test collection' ) kwargs = { 'parent_resource': self.userprofile1 } Collection.persist_new(self.collection1, self.user1, **kwargs) self.collection1 = Collection.objects.get(id=self.collection1.id) self.collection2 = 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' ) kwargs = { 'parent_resource': self.userprofile1 } Collection.persist_new(self.collection2, self.user1, **kwargs) self.collection2 = Collection.objects.get(id=self.collection2.id)
def create_collection(user, validation_schema=None, name=None): suffix = generate_random_string() collection = Collection( name=name if name else "collection{0}".format(suffix), mnemonic=name if name else "collection{0}".format(suffix), full_name=name if name else "Collection {0}".format(suffix), 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', custom_validation_schema=validation_schema) kwargs = {'parent_resource': UserProfile.objects.get(user=user)} Collection.persist_new(collection, user, **kwargs) return Collection.objects.get(id=collection.id)
def create_collection(user, validation_schema=None, name=None): suffix = generate_random_string() collection = Collection( name=name if name else "collection{0}".format(suffix), mnemonic=name if name else "collection{0}".format(suffix), full_name=name if name else "Collection {0}".format(suffix), 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", custom_validation_schema=validation_schema, ) kwargs = {"parent_resource": UserProfile.objects.get(user=user)} Collection.persist_new(collection, user, **kwargs) return Collection.objects.get(id=collection.id)
def save_object(self, obj, **kwargs): request_user = self.context['request'].user errors = Collection.persist_new(obj, request_user, **kwargs) self._errors.update(errors)
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 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 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_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 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])