def test_yesterday_return_proper_formatted_json_on_ajax_request(self): request = HttpRequest() request.method = 'GET' request.GET['startdate'] = self.yesterday_date request.GET['enddate'] = self.yesterday_date request.GET['info'] = 'get_word_details' request.GET['word'] = 'bike' response = yesterday(request=request) import json response_json = json.loads((response.content.decode())) self.assertEqual(response_json['word'], 'bike') self.assertEqual(1, len(response_json['links'])) self.assertIn('10 Reasons to Get on a Bike.', get_response_jsons_items_attributes(response_json, 'links', 'title')) self.assertIn('WP', get_response_jsons_items_attributes(response_json, 'links', 'source')) self.assertIn('www.wp.pl/articles/015', get_response_jsons_items_attributes(response_json, 'links', 'link')) self.assertEqual(response_json['startdate'], self.yesterday_date.strftime("%Y-%m-%d")) self.assertEqual(response_json['enddate'], self.yesterday_date.strftime("%Y-%m-%d"))
def test_yesterday_view_does_not_render_words_occurred_not_yesterday(self): request = HttpRequest() response = yesterday(request=request) self.assertNotContains(response, 'ferry') self.assertNotContains(response, 'train')
def test_yesterday_view_renders_words_occurred_only_yesterday(self): request = HttpRequest() response = yesterday(request=request) self.assertContains(response, 'bike') self.assertContains(response, 'boat')