def test_essearch_filter_tag(self): if self.es_failed: self.skipTest('Elasticsearch is not currently up: {}'.format(self.error_string)) url = '/api/listings/essearch/?tag=demo_tag' response = unittest_request_helper(self, url, 'GET', username='******', status_code=200) titles = sorted([i['title'] for i in response.data['results']]) listings_from_file = ListingFile.filter_listings(is_enabled=True, approval_status='APPROVED', tags__in=['demo_tag']) sorted_listings_from_file = sorted([listing['title'] for listing in listings_from_file]) self.assertEqual(titles, sorted_listings_from_file)
def test_essearch_categories_multiple_with_space(self): """ test_essearch_categories_multiple_with_space TODO: TEST listing_title = Newspaper when is_private = True """ if self.es_failed: self.skipTest('Elasticsearch is not currently up: {}'.format(self.error_string)) url = '/api/listings/essearch/?category=Health and Fitness&category=Communication' response = unittest_request_helper(self, url, 'GET', username='******', status_code=200) titles = sorted([i['title'] for i in response.data['results']]) listings_from_file = ListingFile.filter_listings(is_enabled=True, approval_status='APPROVED', categories__in=['Health and Fitness', 'Communication']) sorted_listings_from_file = sorted([listing['title'] for listing in listings_from_file]) self.assertEqual(titles, sorted_listings_from_file)
def test_essearch_filter_type(self): """ test_essearch_filter_type TODO: Iterate through all Listings types in listings_types.yaml file, Deal with Private apps """ if self.es_failed: self.skipTest('Elasticsearch is not currently up: {}'.format(self.error_string)) url = '/api/listings/essearch/?type=Web Application' response = unittest_request_helper(self, url, 'GET', username='******', status_code=200) titles = sorted([i['title'] for i in response.data['results']]) listings_from_file = ListingFile.filter_listings(is_enabled=True, approval_status='APPROVED', listing_type='Web Application') sorted_listings_from_file = sorted([listing['title'] for listing in listings_from_file]) self.assertEqual(titles, sorted_listings_from_file)
def test_search_tags(self): user = generic_model_access.get_profile('wsmith').user self.client.force_authenticate(user=user) url = '/api/listings/search/?search=demo_tag' response = self.client.get(url, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) titles = sorted([i['title'] for i in response.data]) listings_from_file = ListingFile.filter_listings( is_enabled=True, approval_status='APPROVED', tags__in=['demo_tag']) sorted_listings_from_file = sorted( [listing['title'] for listing in listings_from_file]) print(titles) print(sorted_listings_from_file) self.assertEqual(titles, sorted_listings_from_file) for listing_map in response.data: self.assertEquals(validate_listing_map_keys(listing_map), [])
def test_search_categories_multiple_with_space(self): user = generic_model_access.get_profile('wsmith').user self.client.force_authenticate(user=user) url = '/api/listings/search/?category=Health and Fitness&category=Communication' response = self.client.get(url, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) titles = sorted([i['title'] for i in response.data]) listings_from_file = ListingFile.filter_listings( is_enabled=True, approval_status='APPROVED', categories__in=['Health and Fitness', 'Communication']) sorted_listings_from_file = sorted( [listing['title'] for listing in listings_from_file]) self.assertEqual(titles, sorted_listings_from_file) # TODO: TEST listing_title = Newspaper when is_private = True for listing_map in response.data: self.assertEquals(validate_listing_map_keys(listing_map), [])
def test_search_categories_single_with_space(self): search_category = 'Health and Fitness' url = '/api/listings/search/?category={}'.format(search_category) response = unittest_request_helper(self, url, 'GET', username='******', status_code=200) titles = sorted([i['title'] for i in response.data]) listings_from_file = ListingFile.filter_listings( is_enabled=True, approval_status='APPROVED', categories__in=['Health and Fitness']) sorted_listings_from_file = sorted( [listing['title'] for listing in listings_from_file]) # TODO: TEST listing_title = Newspaper when is_private = True self.assertEqual(titles, sorted_listings_from_file) for listing_map in response.data: self.assertEquals(validate_listing_map_keys(listing_map), [])
def test_tags_to_string_object(self): tags = models.Tag.objects.order_by('name').all() out = model_access.tags_to_string(tags, True) self.assertEqual(out, str(ListingFile.listings_tags()))
def test_get_all_listings(self): all_listings = models.Listing.objects.all() self.assertEqual(len(all_listings), len(ListingFile.listings_titles()))