def forwards_func(apps, schema_editor): # We get the model from the versioned app registry; # if we directly import it, it'll be the wrong version GraphModel = apps.get_model("models", "GraphModel") delete_search_index() for graphid in GraphModel.objects.filter(isresource=True).values_list( 'graphid', flat=True): prepare_search_index(str(graphid), create=True)
def delete_indexes(self): delete_terms_index() delete_concepts_index() delete_search_index() delete_resource_relations_index() # remove custom indexes for index in settings.ELASTICSEARCH_CUSTOM_INDEXES: self.remove_index(index["name"])
def tearDownTestPackage(): """ see https://nose.readthedocs.io/en/latest/writing_tests.html#test-packages this is called from __init__.py """ delete_terms_index() delete_concepts_index() delete_search_index() delete_resource_relations_index()
def forwards_func(apps, schema_editor): # We get the model from the versioned app registry; # if we directly import it, it'll be the wrong version delete_search_index() for graphid in GraphModel.objects.filter(isresource=True).values_list('graphid', flat=True): prepare_search_index(str(graphid), create=True) settings_data_file = os.path.join(settings.ROOT_DIR, 'db', 'system_settings', 'Arches_System_Settings.json') local_settings_available = os.path.isfile(os.path.join(settings.SYSTEM_SETTINGS_LOCAL_PATH)) if local_settings_available == True: settings_data_file = settings.SYSTEM_SETTINGS_LOCAL_PATH management.call_command('es', operation='index_resources') management.call_command('packages', operation='import_graphs', source=os.path.join(settings.ROOT_DIR, 'db', 'system_settings', 'Arches_System_Settings_Model.json')) management.call_command('packages', operation='import_business_data', source=settings_data_file, overwrite='overwrite')
def tearDownClass(cls): sql = """ DELETE FROM public.node_groups WHERE nodegroupid = '99999999-0000-0000-0000-000000000001' OR nodegroupid = '32999999-0000-0000-0000-000000000000' OR nodegroupid = '19999999-0000-0000-0000-000000000000' OR nodegroupid = '21111111-0000-0000-0000-000000000000'; DELETE FROM public.resource_instances WHERE resourceinstanceid = '40000000-0000-0000-0000-000000000000'; """ cursor = connection.cursor() cursor.execute(sql) delete_terms_index() delete_concepts_index() delete_search_index()
def setUpClass(cls): delete_terms_index() delete_concepts_index() delete_search_index() prepare_terms_index(create=True) prepare_concepts_index(create=True) prepare_search_index(create=True) cls.client = Client() cls.client.login(username="******", password="******") models.ResourceInstance.objects.all().delete() with open( os.path.join( "tests/fixtures/resource_graphs/Search Test Model.json"), "rU") as f: archesfile = JSONDeserializer().deserialize(f) ResourceGraphImporter(archesfile["graph"]) cls.search_model_graphid = "d291a445-fa5f-11e6-afa8-14109fd34195" cls.search_model_cultural_period_nodeid = "7a182580-fa60-11e6-96d1-14109fd34195" cls.search_model_creation_date_nodeid = "1c1d05f5-fa60-11e6-887f-14109fd34195" cls.search_model_destruction_date_nodeid = "e771b8a1-65fe-11e7-9163-14109fd34195" cls.search_model_name_nodeid = "2fe14de3-fa61-11e6-897b-14109fd34195" cls.search_model_sensitive_info_nodeid = "57446fae-65ff-11e7-b63a-14109fd34195" cls.search_model_geom_nodeid = "3ebc6785-fa61-11e6-8c85-14109fd34195" cls.user = User.objects.create_user( "unpriviliged_user", "*****@*****.**", "test") cls.user.groups.add(Group.objects.get(name="Guest")) nodegroup = models.NodeGroup.objects.get( pk=cls.search_model_destruction_date_nodeid) assign_perm("no_access_to_nodegroup", cls.user, nodegroup) # Add a concept that defines a min and max date concept = { "id": "00000000-0000-0000-0000-000000000001", "legacyoid": "ARCHES", "nodetype": "ConceptScheme", "values": [], "subconcepts": [{ "values": [ { "value": "Mock concept", "language": "en-US", "category": "label", "type": "prefLabel", "id": "", "conceptid": "" }, { "value": "1950", "language": "en-US", "category": "note", "type": "min_year", "id": "", "conceptid": "" }, { "value": "1980", "language": "en-US", "category": "note", "type": "max_year", "id": "", "conceptid": "" }, ], "relationshiptype": "hasTopConcept", "nodetype": "Concept", "id": "", "legacyoid": "", "subconcepts": [], "parentconcepts": [], "relatedconcepts": [], }], } post_data = JSONSerializer().serialize(concept) content_type = "application/x-www-form-urlencoded" response = cls.client.post( reverse( "concept", kwargs={"conceptid": "00000000-0000-0000-0000-000000000001"}), post_data, content_type) response_json = json.loads(response.content) valueid = response_json["subconcepts"][0]["values"][0]["id"] cls.conceptid = response_json["subconcepts"][0]["id"] # add resource instance with only a cultural period defined cls.cultural_period_resource = Resource( graph_id=cls.search_model_graphid) tile = Tile(data={cls.search_model_cultural_period_nodeid: [valueid]}, nodegroup_id=cls.search_model_cultural_period_nodeid) cls.cultural_period_resource.tiles.append(tile) cls.cultural_period_resource.save() # add resource instance with a creation and destruction date defined cls.date_resource = Resource(graph_id=cls.search_model_graphid) tile = Tile(data={cls.search_model_creation_date_nodeid: "1941-01-01"}, nodegroup_id=cls.search_model_creation_date_nodeid) cls.date_resource.tiles.append(tile) tile = Tile( data={cls.search_model_destruction_date_nodeid: "1948-01-01"}, nodegroup_id=cls.search_model_destruction_date_nodeid) cls.date_resource.tiles.append(tile) tile = Tile(data={cls.search_model_name_nodeid: "testing 123"}, nodegroup_id=cls.search_model_name_nodeid) cls.date_resource.tiles.append(tile) cls.date_resource.save() # add resource instance with a creation date and a cultural period defined cls.date_and_cultural_period_resource = Resource( graph_id=cls.search_model_graphid) tile = Tile(data={cls.search_model_creation_date_nodeid: "1942-01-01"}, nodegroup_id=cls.search_model_creation_date_nodeid) cls.date_and_cultural_period_resource.tiles.append(tile) tile = Tile(data={cls.search_model_cultural_period_nodeid: [valueid]}, nodegroup_id=cls.search_model_cultural_period_nodeid) cls.date_and_cultural_period_resource.tiles.append(tile) cls.date_and_cultural_period_resource.save() # add resource instance with with no dates or periods defined cls.name_resource = Resource(graph_id=cls.search_model_graphid) tile = Tile(data={cls.search_model_name_nodeid: "some test name"}, nodegroup_id=cls.search_model_name_nodeid) cls.name_resource.tiles.append(tile) geom = { "type": "FeatureCollection", "features": [{ "geometry": { "type": "Point", "coordinates": [0, 0] }, "type": "Feature", "properties": {} }], } tile = Tile(data={cls.search_model_geom_nodeid: geom}, nodegroup_id=cls.search_model_geom_nodeid) cls.name_resource.tiles.append(tile) cls.name_resource.save() # add delay to allow for indexes to be updated time.sleep(1)
def tearDownClass(cls): cls.user.delete() delete_terms_index() delete_concepts_index() delete_search_index()
def delete_indexes(self): delete_terms_index() delete_concepts_index() delete_search_index() delete_resource_relations_index()
def reverse_func(apps, schema_editor): delete_terms_index() delete_concepts_index() delete_search_index()
def setUpClass(cls): delete_terms_index() delete_concepts_index() delete_search_index() prepare_terms_index(create=True) prepare_concepts_index(create=True) prepare_search_index(create=True) prepare_resource_relations_index(create=True) cls.client = Client() cls.client.login(username='******', password='******') models.ResourceInstance.objects.all().delete() with open( os.path.join( 'tests/fixtures/resource_graphs/Resource Test Model.json'), 'rU') as f: archesfile = JSONDeserializer().deserialize(f) resource_graph_importer(archesfile['graph']) cls.search_model_graphid = 'e503a445-fa5f-11e6-afa8-14109fd34195' cls.search_model_cultural_period_nodeid = '7a182580-fa60-11e6-96d1-14109fd34195' cls.search_model_creation_date_nodeid = '1c1d05f5-fa60-11e6-887f-14109fd34195' cls.search_model_destruction_date_nodeid = 'e771b8a1-65fe-11e7-9163-14109fd34195' cls.search_model_name_nodeid = '2fe14de3-fa61-11e6-897b-14109fd34195' cls.search_model_sensitive_info_nodeid = '57446fae-65ff-11e7-b63a-14109fd34195' cls.search_model_geom_nodeid = '3ebc6785-fa61-11e6-8c85-14109fd34195' cls.user = User.objects.create_user('test', '*****@*****.**', 'test') cls.user.save() cls.user.groups.add(Group.objects.get(name='Guest')) nodegroup = models.NodeGroup.objects.get( pk=cls.search_model_destruction_date_nodeid) assign_perm('no_access_to_nodegroup', cls.user, nodegroup) # Add a concept that defines a min and max date concept = { "id": "00000000-0000-0000-0000-000000000001", "legacyoid": "ARCHES", "nodetype": "ConceptScheme", "values": [], "subconcepts": [{ "values": [{ "value": "Mock concept", "language": "en-US", "category": "label", "type": "prefLabel", "id": "", "conceptid": "" }, { "value": "1950", "language": "en-US", "category": "note", "type": "min_year", "id": "", "conceptid": "" }, { "value": "1980", "language": "en-US", "category": "note", "type": "max_year", "id": "", "conceptid": "" }], "relationshiptype": "hasTopConcept", "nodetype": "Concept", "id": "", "legacyoid": "", "subconcepts": [], "parentconcepts": [], "relatedconcepts": [] }] } post_data = JSONSerializer().serialize(concept) content_type = 'application/x-www-form-urlencoded' response = cls.client.post( reverse( 'concept', kwargs={'conceptid': '00000000-0000-0000-0000-000000000001'}), post_data, content_type) response_json = json.loads(response.content) valueid = response_json['subconcepts'][0]['values'][0]['id'] cls.conceptid = response_json['subconcepts'][0]['id'] # Add resource with Name, Cultural Period, Creation Date and Geometry cls.test_resource = Resource(graph_id=cls.search_model_graphid) # Add Name tile = Tile(data={cls.search_model_name_nodeid: 'Test Name 1'}, nodegroup_id=cls.search_model_name_nodeid) cls.test_resource.tiles.append(tile) # Add Cultural Period tile = Tile(data={cls.search_model_cultural_period_nodeid: [valueid]}, nodegroup_id=cls.search_model_cultural_period_nodeid) cls.test_resource.tiles.append(tile) # Add Creation Date tile = Tile(data={cls.search_model_creation_date_nodeid: '1941-01-01'}, nodegroup_id=cls.search_model_creation_date_nodeid) cls.test_resource.tiles.append(tile) # Add Gometry cls.geom = { "type": "FeatureCollection", "features": [{ "geometry": { "type": "Point", "coordinates": [0, 0] }, "type": "Feature", "properties": {} }] } tile = Tile(data={cls.search_model_geom_nodeid: cls.geom}, nodegroup_id=cls.search_model_geom_nodeid) cls.test_resource.tiles.append(tile) cls.test_resource.save() # add delay to allow for indexes to be updated time.sleep(1)
def delete_indexes(self, package_name): delete_term_index() delete_search_index()
def delete_indexes(self): delete_term_index() delete_search_index() delete_resource_relations_index()
def delete_indexes(self, package_name): delete_term_index() delete_search_index() delete_resource_relations_index()