def test_organisation_added_to_index(self): queryset = Fixtures.es_organisation_connection() indexed_organisation = get_organisation_by_id(queryset, self.org.id)[0] self.assertEqual(indexed_organisation.id, str(self.org.id)) self.assertEqual(indexed_organisation.name, self.org.name) self.assertEqual(indexed_organisation.description, self.org.description) self.assertEqual(indexed_organisation.published, self.org.published)
def test_organisation_filter_organisations_by_query(self): queryset = Fixtures.es_organisation_connection() self.org.name = "banana weird" self.org.save() result = filter_organisations_by_query(queryset, "banana") result = order_organistations_by_created_on(result).execute() self.assertEqual(result[0].name, self.org.name)
def test_organisation_query(self): org_queryset = get_organisations( Fixtures.es_organisation_connection(), [self.org3.pk, self.org2.pk, self.org.pk]) result = filter_organisations_by_query(org_queryset, "TestOrg") x = result.execute() order = keyword_order(result) orgs = Organisation.objects.filter(id__in=order["ids"]).order_by( order["order"]) self.assertTrue(self.org2 in orgs) #basic test for travis self.assertTrue(self.org in orgs)
def test_specificity_of_organisation_search(self): queryset = Fixtures.es_organisation_connection() exact_query = "Scottish Optometrist Society" inexact_query = "Scottish Optometrist Society Glasgow" undesired_query = "Scottish Ontology Society" result_exact_query = filter_organisations_by_query(queryset, exact_query).execute() result_inexact_query = filter_organisations_by_query(queryset, inexact_query).execute() result_undesired_query = filter_organisations_by_query(queryset, undesired_query).execute() while len(result_inexact_query) == 0: inexact_query = inexact_query[:-1] result_inexact_query = filter_organisations_by_query(queryset, inexact_query).execute() self.assertEqual(result_exact_query[0].name, self.org2.name) self.assertEqual(result_inexact_query[0].name, self.org2.name)
def test_organisation_filter_organisations_by_query_published(self): queryset = Fixtures.es_organisation_connection() published_org = Organisation.objects.create(name="Banana Published") unpublished_org = Organisation.objects.create(name="Banana Unpublished") unpublished_org.published = False unpublished_org.save() result_all = filter_organisations_by_query(queryset, "Banana") result_all = order_organistations_by_created_on(result_all).execute() result_published = filter_organisations_by_query_published(queryset, "Banana") result_published = order_organistations_by_created_on(result_published).execute() self.assertEqual(unpublished_org.published, False) self.assertEqual(result_all[0].name, unpublished_org.name) self.assertEqual(result_published[0].name, published_org.name)
def test_organisation_publish(self): queryset = Fixtures.es_connection() org_queryset = Fixtures.es_organisation_connection() self.organisation.published = False self.organisation.save() unpublished_service = Fixtures.create_service(self.organisation) index_result = get_service(queryset, unpublished_service.id) self.client.login(username='******', password='******') self.assertEqual(len(index_result), 0) response = self.client.post( reverse('organisation_publish', kwargs={'pk': self.organisation.pk})) self.organisation.refresh_from_db() index_result = get_service(queryset, unpublished_service.id) self.assertEqual(len(index_result), 1) self.assertTrue(self.organisation.published) self.assertEqual(response.status_code, 302) self.assertRedirects(response, (reverse('organisation_unpublished'))) org_index_result = get_organisation_by_id(org_queryset, self.organisation.id) self.assertEqual(len(org_index_result), 1)
def test_organisation_update_reindexes(self): queryset = Fixtures.es_organisation_connection() self.org.name = "Test Org" self.org.save() result = get_organisation_by_id(queryset, self.org.id)[0] self.assertEqual(result['name'], self.org.name)