def test_num_datasets(self):
     self._publish_xls_form_to_project()
     request = self.factory.post('/', data={}, **self.extra)
     request.user = self.user
     self.project_data = ProjectSerializer(
         self.project, context={'request': request}).data
     self.assertEqual(self.project_data['num_datasets'], 1)
class TestProjectSerializer(TransactionTestCase):
    def setUp(self):
        self.serializer = ProjectSerializer()

    def test_get_project_permissions_none(self):
        perms = self.serializer.get_project_permissions(None)
        self.assertEqual(perms, [])
class TestProjectSerializer(TransactionTestCase):

    def setUp(self):
        self.serializer = ProjectSerializer()

    def test_get_project_permissions_none(self):
        perms = self.serializer.get_project_permissions(None)
        self.assertEqual(perms, [])
Exemple #4
0
    def starred(self, request, *args, **kwargs):
        """Return projects starred for this user."""
        user_profile = self.get_object()
        user = user_profile.user
        projects = user.project_stars.all()
        serializer = ProjectSerializer(projects,
                                       context={'request': request},
                                       many=True)

        return Response(data=serializer.data)
 def test_last_submission_date(self):
     self._publish_xls_form_to_project()
     self._make_submissions()
     request = self.factory.post('/', data={}, **self.extra)
     request.user = self.user
     self.project_data = ProjectSerializer(
         self.project, context={'request': request}).data
     date_created = self.xform.instances.order_by(
         '-date_created').values_list('date_created', flat=True)[0]
     self.assertEqual(str(self.project_data['last_submission_date']),
                      str(date_created))
    def test_projects_tags(self):
        self._project_create()
        view = ProjectViewSet.as_view({
            'get': 'labels',
            'post': 'labels',
            'delete': 'labels'
        })
        list_view = ProjectViewSet.as_view({
            'get': 'list',
        })
        project_id = self.project.pk
        # no tags
        request = self.factory.get('/', **self.extra)
        response = view(request, pk=project_id)
        self.assertNotEqual(response.get('Last-Modified'), None)
        self.assertEqual(response.data, [])
        # add tag "hello"
        request = self.factory.post('/', data={"tags": "hello"}, **self.extra)
        response = view(request, pk=project_id)
        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.data, [u'hello'])

        # check filter by tag
        request = self.factory.get('/', data={"tags": "hello"}, **self.extra)

        request.user = self.user
        self.project_data = ProjectSerializer(
            self.project, context={'request': request}).data
        response = list_view(request, pk=project_id)
        self.assertNotEqual(response.get('Last-Modified'), None)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, [self.project_data])

        request = self.factory.get('/', data={"tags": "goodbye"}, **self.extra)
        response = list_view(request, pk=project_id)
        self.assertNotEqual(response.get('Last-Modified'), None)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, [])

        # remove tag "hello"
        request = self.factory.delete('/', **self.extra)
        response = view(request, pk=project_id, label='hello')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.get('Last-Modified'), None)
        self.assertEqual(response.data, [])
Exemple #7
0
    def test_get_starred_projects(self):
        self._project_create()

        # add star as bob
        view = ProjectViewSet.as_view({'get': 'star', 'post': 'star'})
        request = self.factory.post('/', **self.extra)
        response = view(request, pk=self.project.pk)

        # get starred projects
        view = ConnectViewSet.as_view({
            'get': 'starred',
        })
        request = self.factory.get('/', **self.extra)
        response = view(request, user=self.user)

        self.assertEqual(response.status_code, 200)

        request.user = self.user
        self.project_data = ProjectSerializer(self.project,
                                              context={
                                                  'request': request
                                              }).data
        self.assertEqual(response.data, [self.project_data])
Exemple #8
0
    def _project_create(self, project_data={}, merge=True):
        view = ProjectViewSet.as_view({'post': 'create'})

        if merge:
            data = {
                'name': u'demo',
                'owner':
                'http://testserver/api/v1/users/%s' % self.user.username,
                'metadata': {
                    'description': 'Some description',
                    'location': 'Naivasha, Kenya',
                    'category': 'governance'
                },
                'public': False
            }
            data.update(project_data)
        else:
            data = project_data

        request = self.factory.post('/',
                                    data=json.dumps(data),
                                    content_type="application/json",
                                    **self.extra)
        response = view(request, owner=self.user.username)
        self.assertEqual(response.status_code, 201)
        self.project = Project.objects.filter(name=data['name'],
                                              created_by=self.user)[0]
        data['url'] = 'http://testserver/api/v1/projects/%s'\
            % self.project.pk
        self.assertDictContainsSubset(data, response.data)

        request.user = self.user
        self.project_data = ProjectSerializer(self.project,
                                              context={
                                                  'request': request
                                              }).data
 def setUp(self):
     self.serializer = ProjectSerializer()
 def setUp(self):
     self.serializer = ProjectSerializer()