def test_get_sort_specifies_artist(self): view = views.RecordListView() mock_request = mock.MagicMock(name='Mock Request') mock_request.GET = {'sort': 'artist'} view.request = mock_request self.assertEqual('artist__name', view.get_sort())
def test_get_sort_unspecified(self): view = views.RecordListView() mock_request = mock.MagicMock(name='Mock Request') mock_request.GET.get.return_value = None view.request = mock_request self.assertEqual('title', view.get_sort())
def test_dispatch_redirect(self): models.Record.objects.create(title='Kind of blue') view = views.RecordListView() mock_request = mock.MagicMock(name='Mock Request') mock_request.GET = {'redirect': 'random'} view.request = mock_request resp = view.dispatch(mock_request) self.assertEqual(302, resp.status_code)
def test_dispatch_regular(self): view = views.RecordListView() mock_request = mock.MagicMock(name='Mock Request') mock_request.GET = {} view.request = mock_request view.kwargs = {} rf = RequestFactory() resp = view.dispatch(rf.get('/')) self.assertEqual(200, resp.status_code)
def test_get_random_record(self): record_1 = models.Record.objects.create(title='Kind of blue') record_2 = models.Record.objects.create(title='Milestones') view = views.RecordListView() mock_request = mock.MagicMock(name='Mock Request') mock_request.GET = {} view.request = mock_request redirect = view.redirect_to_random_record() potential_redirects = [ record_1.get_absolute_url(), record_2.get_absolute_url() ] self.assertIn(redirect.url, potential_redirects)