示例#1
0
 def _publish_xls_form_to_project(self):
     self._project_create()
     view = ProjectViewSet.as_view({
         'post': 'forms'
     })
     project_id = self.project.pk
     data = {
         'owner': 'http://testserver/api/v1/users/bob',
         'public': False,
         'public_data': False,
         'description': u'',
         'downloadable': True,
         'is_crowd_form': False,
         'allows_sms': False,
         'encrypted': False,
         'sms_id_string': u'transportation_2011_07_25',
         'id_string': u'transportation_2011_07_25',
         'title': u'transportation_2011_07_25',
         'bamboo_dataset': u''
     }
     path = os.path.join(
         settings.PROJECT_ROOT, "main", "tests", "fixtures",
         "transportation", "transportation.xls")
     with open(path) as xls_file:
         post_data = {'xls_file': xls_file}
         request = self.factory.post('/', data=post_data, **self.extra)
         response = view(request, owner='bob', pk=project_id)
         self.assertEqual(response.status_code, 201)
         self.xform = self.user.xforms.all()[0]
         data.update({
             'url':
             'http://testserver/api/v1/forms/bob/%s' % self.xform.pk
         })
         self.assertDictContainsSubset(data, response.data)
         self.form_data = response.data
示例#2
0
文件: test_api.py 项目: smn/formhub
 def _publish_xls_form_to_project(self):
     self._project_create()
     view = ProjectViewSet.as_view({'post': 'forms'})
     data = {
         'url': 'http://testserver/api/v1/forms/bob/1',
         'formid': 1,
         'owner': 'http://testserver/api/v1/users/bob',
         'public': False,
         'public_data': False,
         'description': u'',
         'downloadable': True,
         'is_crowd_form': False,
         'allows_sms': False,
         'encrypted': False,
         'sms_id_string': u'transportation_2011_07_25',
         'id_string': u'transportation_2011_07_25',
         'title': u'transportation_2011_07_25',
         'bamboo_dataset': u''
     }
     path = os.path.join(settings.PROJECT_ROOT, "main", "tests", "fixtures",
                         "transportation", "transportation.xls")
     with open(path) as xls_file:
         post_data = {'xls_file': xls_file}
         request = self.factory.post('/', data=post_data, **self.extra)
         response = view(request, owner='bob', pk=1)
         self.assertEqual(response.status_code, 201)
         self.assertDictContainsSubset(data, response.data)
         self.form_data = response.data
示例#3
0
 def test_view_xls_form(self):
     self._publish_xls_form_to_project()
     view = ProjectViewSet.as_view({'get': 'forms'})
     request = self.factory.get('/', **self.extra)
     response = view(request, owner='bob', pk=1)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, [self.form_data])
     response = view(request, owner='bob', pk=1, formid=1)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, self.form_data)
示例#4
0
文件: test_api.py 项目: smn/formhub
 def _project_create(self):
     view = ProjectViewSet.as_view({'post': 'create'})
     data = {'name': u'demo', 'owner': 'http://testserver/api/v1/users/bob'}
     request = self.factory.post('/',
                                 data=json.dumps(data),
                                 content_type="application/json",
                                 **self.extra)
     response = view(request, owner='bob')
     self.assertEqual(response.status_code, 201)
     data['url'] = 'http://testserver/api/v1/projects/bob/%s' % 1
     self.assertDictContainsSubset(data, response.data)
     self.project_data = response.data
示例#5
0
 def test_projects_get(self):
     self._project_create()
     view = ProjectViewSet.as_view({'get': 'retrieve'})
     request = self.factory.get('/', **self.extra)
     response = view(request)
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.data,
                      {'detail': 'Expected URL keyword argument `owner`.'})
     request = self.factory.get('/', **self.extra)
     response = view(request, owner='bob', pk=1)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, self.project_data)
示例#6
0
 def test_view_xls_form(self):
     self._publish_xls_form_to_project()
     view = ProjectViewSet.as_view({
         'get': 'forms'
     })
     request = self.factory.get('/', **self.extra)
     response = view(request, owner='bob', pk=1)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, [self.form_data])
     response = view(request, owner='bob', pk=1, formid=1)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, self.form_data)
示例#7
0
 def test_projects_get(self):
     self._project_create()
     view = ProjectViewSet.as_view({
         'get': 'retrieve'
     })
     request = self.factory.get('/', **self.extra)
     response = view(request)
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.data,
                      {'detail': 'Expected URL keyword argument `owner`.'})
     request = self.factory.get('/', **self.extra)
     response = view(request, owner='bob', pk=self.project.pk)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, self.project_data)
示例#8
0
 def _project_create(self):
     view = ProjectViewSet.as_view({
         'post': 'create'
     })
     data = {
         'name': u'demo',
         'owner': 'http://testserver/api/v1/users/bob'
     }
     request = self.factory.post(
         '/', data=json.dumps(data),
         content_type="application/json", **self.extra)
     response = view(request, owner='bob')
     self.assertEqual(response.status_code, 201)
     data['url'] = 'http://testserver/api/v1/projects/bob/%s' % 1
     self.assertDictContainsSubset(data, response.data)
     self.project_data = response.data
示例#9
0
 def setUp(self):
     super(TestProjectsAPI, self).setUp()
     self.view = ProjectViewSet.as_view({'get': 'list', 'post': 'create'})
示例#10
0
 def setUp(self):
     super(TestProjectsAPI, self).setUp()
     self.view = ProjectViewSet.as_view({
         'get': 'list',
         'post': 'create'
     })