Exemplo n.º 1
0
    def test_commit_from_draft_with_contributor_with_data(self):
        self.observation.status = 'draft'
        self.observation.save()

        url = reverse('api:project_single_observation',
                      kwargs={
                          'project_id': self.project.id,
                          'observation_id': self.observation.id
                      })
        request = self.factory.patch(url)
        request.DATA = {
            'properties': {
                'key': 'updated'
            },
            'meta': {
                'status': "active",
            }
        }
        request.user = self.creator

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
        ref = Observation.objects.get(pk=self.observation.id)
        self.assertEqual(ref.status, 'pending')
        self.assertEqual(ref.properties.get('key'), 'updated')
Exemplo n.º 2
0
    def test_update_user(self):
        url = reverse('api:project_single_observation', kwargs={
            'project_id': self.project.id,
            'observation_id': self.observation.id
        })
        request = self.factory.patch(url)
        request.data = {'properies': {'text': 'blah'}}
        request.user = self.viewer

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
Exemplo n.º 3
0
    def test_update_user(self):
        url = reverse('api:project_single_observation', kwargs={
            'project_id': self.project.id,
            'observation_id': self.observation.id
        })
        request = self.factory.patch(url)
        request.data = {'properies': {'text': 'blah'}}
        request.user = self.viewer

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
Exemplo n.º 4
0
    def test_flag_with_moderator(self):
        url = reverse('api:project_single_observation', kwargs={
            'project_id': self.project.id,
            'observation_id': self.observation.id
        })
        request = self.factory.patch(url)
        request.data = {'meta': {'status': "pending"}}
        request.user = self.moderator

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
        ref = Observation.objects.get(pk=self.observation.id)
        self.assertEqual(ref.status, 'pending')
Exemplo n.º 5
0
    def test_flag_with_moderator(self):
        url = reverse('api:project_single_observation', kwargs={
            'project_id': self.project.id,
            'observation_id': self.observation.id
        })
        request = self.factory.patch(url)
        request.data = {'meta': {'status': "pending"}}
        request.user = self.moderator

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
        ref = Observation.objects.get(pk=self.observation.id)
        self.assertEqual(ref.status, 'pending')
Exemplo n.º 6
0
    def test_flag_with_anonymous(self):
        url = reverse('api:project_single_observation',
                      kwargs={
                          'project_id': self.project.id,
                          'observation_id': self.observation.id
                      })
        request = self.factory.patch(url)
        request.DATA = {'meta': {'status': "pending"}}
        request.user = AnonymousUser()

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
        self.assertEqual(
            Observation.objects.get(pk=self.observation.id).status, 'active')
Exemplo n.º 7
0
    def test_flag_with_anonymous(self):
        url = reverse('api:project_single_observation', kwargs={
            'project_id': self.project.id,
            'observation_id': self.observation.id
        })
        request = self.factory.patch(url)
        request.DATA = {'meta': {'status': "pending"}}
        request.user = AnonymousUser()

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
        self.assertEqual(
            Observation.objects.get(pk=self.observation.id).status,
            'active'
        )
Exemplo n.º 8
0
    def test_approve_pending_with_admin(self):
        self.observation.status = 'pending'
        self.observation.save()

        url = reverse('api:project_single_observation',
                      kwargs={
                          'project_id': self.project.id,
                          'observation_id': self.observation.id
                      })
        request = self.factory.patch(url)
        request.DATA = {'meta': {'status': "active"}}
        request.user = self.admin

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
        self.assertEqual(
            Observation.objects.get(pk=self.observation.id).status, 'active')
Exemplo n.º 9
0
    def test_flag_with_anonymous(self):
        if not User.objects.filter(display_name='AnonymousUser').exists():
            UserFactory.create(display_name='AnonymousUser')

        url = reverse('api:project_single_observation',
                      kwargs={
                          'project_id': self.project.id,
                          'observation_id': self.observation.id
                      })
        request = self.factory.patch(url)
        request.data = {'meta': {'status': "pending"}}
        request.user = AnonymousUser()

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
        self.assertEqual(
            Observation.objects.get(pk=self.observation.id).status, 'active')
Exemplo n.º 10
0
    def test_commit_from_draft_with_contributor_who_is_moderator(self):
        self.observation.status = 'draft'
        self.observation.save()

        url = reverse('api:project_single_observation',
                      kwargs={
                          'project_id': self.project.id,
                          'observation_id': self.observation.id
                      })
        request = self.factory.patch(url)
        request.data = {'meta': {'status': "active"}}
        request.user = self.creator

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
        self.assertEqual(
            Observation.objects.get(pk=self.observation.id).status, 'pending')
Exemplo n.º 11
0
    def test_update_under_review(self):
        CommentFactory.create(**{
            'commentto': self.observation,
            'review_status': 'open'
        })
        url = reverse('api:project_single_observation', kwargs={
            'project_id': self.project.id,
            'observation_id': self.observation.id
        })
        request = self.factory.patch(url)
        request.data = {'meta': {'status': 'active'}}
        request.user = self.admin

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)

        ref = Observation.objects.get(pk=self.observation.id)
        self.assertEqual(ref.status, 'review')
Exemplo n.º 12
0
    def test_suspend_pending_with_admin(self):
        self.observation.status = 'active'
        self.observation.save()

        url = reverse('api:project_single_observation', kwargs={
            'project_id': self.project.id,
            'observation_id': self.observation.id
        })
        request = self.factory.patch(url)
        request.data = {'meta': {'status': "pending"}}
        request.user = self.admin

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
        self.assertEqual(
            Observation.objects.get(pk=self.observation.id).status,
            'pending'
        )
Exemplo n.º 13
0
    def test_commit_from_draft_with_contributor_who_is_moderator(self):
        self.observation.status = 'draft'
        self.observation.save()

        url = reverse('api:project_single_observation', kwargs={
            'project_id': self.project.id,
            'observation_id': self.observation.id
        })
        request = self.factory.patch(url)
        request.data = {'meta': {'status': "active"}}
        request.user = self.creator

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
        self.assertEqual(
            Observation.objects.get(pk=self.observation.id).status,
            'pending'
        )
Exemplo n.º 14
0
    def test_update_under_review(self):
        CommentFactory.create(**{
            'commentto': self.observation,
            'review_status': 'open'
        })
        url = reverse('api:project_single_observation', kwargs={
            'project_id': self.project.id,
            'observation_id': self.observation.id
        })
        request = self.factory.patch(url)
        request.data = {'meta': {'status': 'active'}}
        request.user = self.admin

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)

        ref = Observation.objects.get(pk=self.observation.id)
        self.assertEqual(ref.status, 'review')
Exemplo n.º 15
0
    def test_flag_with_anonymous(self):
        if not User.objects.filter(display_name='AnonymousUser').exists():
            UserF.create(display_name='AnonymousUser')

        url = reverse('api:project_single_observation', kwargs={
            'project_id': self.project.id,
            'observation_id': self.observation.id
        })
        request = self.factory.patch(url)
        request.data = {'meta': {'status': "pending"}}
        request.user = AnonymousUser()

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
        self.assertEqual(
            Observation.objects.get(pk=self.observation.id).status,
            'active'
        )
Exemplo n.º 16
0
    def test_approve_pending_with_admin_empty_properties(self):
        self.observation.properties = None
        self.observation.status = 'pending'
        self.observation.save()

        url = reverse('api:project_single_observation', kwargs={
            'project_id': self.project.id,
            'observation_id': self.observation.id
        })
        request = self.factory.patch(url)
        request.DATA = {'meta': {'status': "active"}}
        request.user = self.admin

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
        self.assertEqual(
            Observation.objects.get(pk=self.observation.id).status,
            'active'
        )
Exemplo n.º 17
0
    def test_commit_from_draft_with_contributor_with_data(self):
        self.observation.status = 'draft'
        self.observation.save()

        url = reverse('api:project_single_observation', kwargs={
            'project_id': self.project.id,
            'observation_id': self.observation.id
        })
        request = self.factory.patch(url)
        request.DATA = {
            'properties': {
                'key': 'updated'
            },
            'meta': {
                'status': "active",
            }
        }
        request.user = self.creator

        view = SingleContributionAPIView()
        view.update_and_respond(request, self.observation)
        ref = Observation.objects.get(pk=self.observation.id)
        self.assertEqual(ref.status, 'pending')
        self.assertEqual(ref.properties.get('key'), 'updated')