def test_form_list(self, mock_time): self._set_mock_time(mock_time) self._publish_transportation_form() self._make_submissions() view = SubmissionStatsViewSet.as_view({'get': 'list'}) request = self.factory.get('/', **self.extra) response = view(request) self.assertEqual(response.status_code, 200) formid = self.xform.pk data = [{ 'id': formid, 'id_string': u'transportation_2011_07_25', 'url': 'http://testserver/api/v1/stats/submissions/%s' % formid }] self.assertEqual(response.data, data) view = SubmissionStatsViewSet.as_view({'get': 'retrieve'}) request = self.factory.get('/?group=_xform_id_string', **self.extra) response = view(request, pk=formid) self.assertEqual(response.status_code, 200) self.assertIsInstance(response.data, list) data = { u'count': 4 } self.assertDictContainsSubset(data, response.data[0])
def test_submissions_stats(self, mock_time): self._set_mock_time(mock_time) self._publish_transportation_form() self._make_submissions() view = SubmissionStatsViewSet.as_view({'get': 'list'}) request = self.factory.get('/', **self.extra) response = view(request) self.assertEqual(response.status_code, 200) formid = self.xform.pk data = [{ 'id': formid, 'id_string': u'transportation_2011_07_25', 'url': 'http://testserver/api/v1/stats/submissions/%s' % formid }] self.assertEqual(response.data, data) view = SubmissionStatsViewSet.as_view({'get': 'retrieve'}) request = self.factory.get('/', **self.extra) response = view(request, pk=formid) self.assertEqual(response.status_code, 400) data = {u'detail': u'Expecting `group` and `name` query parameters.'} self.assertEqual(response.data, data) request = self.factory.get('/?group=_xform_id_string', **self.extra) response = view(request, pk=formid) self.assertEqual(response.status_code, 200) self.assertIsInstance(response.data, list) data = {u'count': 4} self.assertDictContainsSubset(data, response.data[0])
def test_anon_form_list(self): self._publish_transportation_form() self._make_submissions() view = SubmissionStatsViewSet.as_view({'get': 'list'}) request = self.factory.get('/') response = view(request) self.assertEqual(response.status_code, 401)
def test_same_id_string_form_different_users(self, mock_time): self._set_mock_time(mock_time) # as bob self._publish_transportation_form() # as demo user self._create_user_and_login('demo') self.extra = { 'HTTP_AUTHORIZATION': 'Token %s' % self.user.auth_token} self._publish_transportation_form() self._make_submissions() view = SubmissionStatsViewSet.as_view({'get': 'list'}) request = self.factory.get('/', **self.extra) response = view(request) self.assertEqual(response.status_code, 200) formid = self.xform.id_string data = { u'transportation_2011_07_25': 'http://testserver/api/v1/stats/submissions/demo/%s' % self.xform.pk } self.assertDictEqual(response.data, data) request = self.factory.get('/?group=_xform_id_string', **self.extra) response = view(request) response = view(request, owner='bob', formid=formid) self.assertEqual(response.status_code, 200) self.assertIsInstance(response.data, list) data = { u'count': 4 } self.assertDictContainsSubset(data, response.data[0])
def test_form_list_select_one_choices(self): self._tutorial_form_submission() view = SubmissionStatsViewSet.as_view({'get': 'retrieve'}) formid = self.xform.pk request = self.factory.get('/?group=gender', **self.extra) response = view(request, pk=formid) self.assertEqual(response.status_code, 200) self.assertIsInstance(response.data, list) data = [ {'count': 2, 'gender': u'Female'}, {'count': 1, 'gender': u'Male'} ] self.assertEqual(sorted(data), sorted(response.data))
def test_form_list_select_one_choices_multi_language(self): paths = [os.path.join( self.this_directory, 'fixtures', 'good_eats_multilang', x) for x in ['good_eats_multilang.xls', '1.xml']] self._publish_xls_file_and_set_xform(paths[0]) self._make_submission(paths[1]) view = SubmissionStatsViewSet.as_view({'get': 'retrieve'}) formid = self.xform.pk request = self.factory.get('/?group=rating', **self.extra) response = view(request, pk=formid) self.assertEqual(response.status_code, 200) self.assertIsInstance(response.data, list) data = [{'count': 1, 'rating': u'Nothing Special'}] self.assertEqual(data, response.data)
def test_form_list(self, mock_time): self._set_mock_time(mock_time) self._publish_transportation_form() self._make_submissions() view = SubmissionStatsViewSet.as_view({'get': 'list'}) request = self.factory.get('/', **self.extra) response = view(request) self.assertEqual(response.status_code, 200) formid = self.xform.pk data = { u'transportation_2011_07_25': 'http://testserver/api/v1/stats/submissions/bob/%s' % formid } self.assertDictEqual(response.data, data) request = self.factory.get('/?group=_xform_id_string', **self.extra) response = view(request) response = view(request, owner='bob', formid=formid) self.assertEqual(response.status_code, 200) self.assertIsInstance(response.data, list) data = {u'count': 4} self.assertDictContainsSubset(data, response.data[0])
def test_submissions_stats_with_xform_in_delete_async_queue( self, mock_time): self._set_mock_time(mock_time) self._publish_transportation_form() self._make_submissions() view = SubmissionStatsViewSet.as_view({'get': 'list'}) request = self.factory.get('/', **self.extra) response = view(request) self.assertEqual(response.status_code, 200) formid = self.xform.pk data = [{ 'id': formid, 'id_string': u'transportation_2011_07_25', 'url': 'http://testserver/api/v1/stats/submissions/%s' % formid }] self.assertEqual(response.data, data) initial_count = len(response.data) self.xform.deleted_at = timezone.now() self.xform.save() request = self.factory.get('/', **self.extra) response = view(request) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), initial_count - 1)