예제 #1
0
    def test_unpin(self):
        self.assertEqual(MessageBoardComment.objects.all().count(), 0)
        data = CommentForm(target_object=self.unicef).generate_security_data()
        data.update({"name": "the supplied name", "comment": "Foo"})
        response = self.url_post(self.unicef, reverse("comments-post-comment"),
                                 data)
        self.assertEqual(MessageBoardComment.objects.all().count(), 1)
        response = self.url_post(
            self.unicef,
            reverse(
                "msg_board.messageboardcomment_pin",
                kwargs={"pk": MessageBoardComment.objects.all().first().pk}),
        )
        self.assertEqual(response.status_code, 204)
        self.assertEqual(
            MessageBoardComment.get_all(self.unicef, pinned=True).count(), 1)

        response = self.url_get(
            "unicef", reverse("msg_board.messageboardcomment_pinned"))
        self.assertEqual(len(response.json["results"]), 1)

        response = self.url_post(
            self.unicef,
            reverse(
                "msg_board.messageboardcomment_unpin",
                kwargs={"pk": MessageBoardComment.objects.all().first().pk}),
        )
        self.assertEqual(response.status_code, 204)
        self.assertEqual(
            MessageBoardComment.get_all(self.unicef, pinned=True).count(), 0)

        response = self.url_get(
            "unicef", reverse("msg_board.messageboardcomment_pinned"))
        self.assertEqual(len(response.json["results"]), 0)
예제 #2
0
    def test_unpin_invalid_comment(self):
        self.login(self.admin)

        self.assertEqual(MessageBoardComment.objects.all().count(), 0)
        data = CommentForm(target_object=self.unicef).generate_security_data()
        data.update({"name": "the supplied name", "comment": "Foo"})
        response = self.url_post(self.unicef, reverse("comments-post-comment"),
                                 data)
        self.assertEqual(MessageBoardComment.objects.all().count(), 1)

        # Pin in Nyaruka org
        response = self.url_post(
            self.unicef,
            reverse(
                "msg_board.messageboardcomment_pin",
                kwargs={"pk": MessageBoardComment.objects.all().first().pk}),
        )
        self.assertEqual(response.status_code, 204)

        # Unpin in Unicef org
        response = self.url_post(
            self.unicef,
            reverse("msg_board.messageboardcomment_unpin", kwargs={"pk":
                                                                   9999}))
        self.assertEqual(response.status_code, 404)
예제 #3
0
파일: tests.py 프로젝트: xkmato/casepro
    def test_unpin(self):
        self.assertEqual(MessageBoardComment.objects.all().count(), 0)
        data = CommentForm(target_object=self.unicef).generate_security_data()
        data.update({
            'name': 'the supplied name',
            'comment': 'Foo'
        })
        response = self.url_post(
            self.unicef,
            reverse('comments-post-comment'), data)
        self.assertEqual(MessageBoardComment.objects.all().count(), 1)
        response = self.url_post(
            self.unicef,
            reverse('msg_board.messageboardcomment_pin', kwargs={'pk': MessageBoardComment.objects.all().first().pk})
        )
        self.assertEqual(response.status_code, 204)
        self.assertEqual(MessageBoardComment.get_all(self.unicef, pinned=True).count(), 1)

        response = self.url_get('unicef', reverse('msg_board.messageboardcomment_pinned'))
        self.assertEqual(len(response.json['results']), 1)

        response = self.url_post(
            self.unicef,
            reverse('msg_board.messageboardcomment_unpin', kwargs={'pk': MessageBoardComment.objects.all().first().pk})
        )
        self.assertEqual(response.status_code, 204)
        self.assertEqual(MessageBoardComment.get_all(self.unicef, pinned=True).count(), 0)

        response = self.url_get('unicef', reverse('msg_board.messageboardcomment_pinned'))
        self.assertEqual(len(response.json['results']), 0)
예제 #4
0
파일: tests.py 프로젝트: xkmato/casepro
    def test_unpin_invalid_comment(self):
        self.login(self.admin)

        self.assertEqual(MessageBoardComment.objects.all().count(), 0)
        data = CommentForm(target_object=self.unicef).generate_security_data()
        data.update({
            'name': 'the supplied name',
            'comment': 'Foo'
        })
        response = self.url_post(
            self.unicef,
            reverse('comments-post-comment'), data)
        self.assertEqual(MessageBoardComment.objects.all().count(), 1)

        # Pin in Nyaruka org
        response = self.url_post(
            self.unicef,
            reverse('msg_board.messageboardcomment_pin', kwargs={'pk': MessageBoardComment.objects.all().first().pk})
        )
        self.assertEqual(response.status_code, 204)

        # Unpin in Unicef org
        response = self.url_post(
            self.unicef,
            reverse('msg_board.messageboardcomment_unpin', kwargs={'pk': 9999})
        )
        self.assertEqual(response.status_code, 404)
예제 #5
0
파일: tests.py 프로젝트: xkmato/casepro
    def test_list(self):
        data = CommentForm(self.unicef).generate_security_data()
        data.update({'comment': 'Foo'})
        self.url_post('unicef', reverse('comments-post-comment'), data)

        data = CommentForm(self.unicef).generate_security_data()
        data.update({'comment': 'Bar'})
        self.url_post('unicef', reverse('comments-post-comment'), data)

        response = self.url_get('unicef', reverse('msg_board.messageboardcomment_list'))

        comment1, comment2 = list(MessageBoardComment.objects.order_by('pk'))

        self.assertEqual(response.json, {'results': [
            {
                'id': comment2.pk,
                'comment': "Bar",
                'user': {'id': self.user1.pk, 'name': "Evan"},
                'submitted_on': format_iso8601(comment2.submit_date),
                'pinned_on': None
            },
            {
                'id': comment1.pk,
                'comment': "Foo",
                'user': {'id': self.user1.pk, 'name': "Evan"},
                'submitted_on': format_iso8601(comment1.submit_date),
                'pinned_on': None
            }
        ]})
예제 #6
0
    def test_unpin(self):
        self.assertEqual(MessageBoardComment.objects.all().count(), 0)
        data = CommentForm(target_object=self.unicef).generate_security_data()
        data.update({'name': 'the supplied name', 'comment': 'Foo'})
        response = self.url_post(self.unicef, reverse('comments-post-comment'),
                                 data)
        self.assertEqual(MessageBoardComment.objects.all().count(), 1)
        response = self.url_post(
            self.unicef,
            reverse(
                'msg_board.messageboardcomment_pin',
                kwargs={'pk': MessageBoardComment.objects.all().first().pk}))
        self.assertEqual(response.status_code, 204)
        self.assertEqual(
            MessageBoardComment.get_all(self.unicef, pinned=True).count(), 1)

        response = self.url_get(
            'unicef', reverse('msg_board.messageboardcomment_pinned'))
        self.assertEqual(len(response.json['results']), 1)

        response = self.url_post(
            self.unicef,
            reverse(
                'msg_board.messageboardcomment_unpin',
                kwargs={'pk': MessageBoardComment.objects.all().first().pk}))
        self.assertEqual(response.status_code, 204)
        self.assertEqual(
            MessageBoardComment.get_all(self.unicef, pinned=True).count(), 0)

        response = self.url_get(
            'unicef', reverse('msg_board.messageboardcomment_pinned'))
        self.assertEqual(len(response.json['results']), 0)
예제 #7
0
 def test_post_comment(self):
     data = CommentForm(self.unicef).generate_security_data()
     data.update({"name": "the supplied name", "comment": "Foo"})
     response = self.url_post("unicef", reverse("comments-post-comment"),
                              data)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(MessageBoardComment.objects.all().count(), 1)
     self.assertEqual(MessageBoardComment.objects.all().first().comment,
                      "Foo")
예제 #8
0
파일: tests.py 프로젝트: xkmato/casepro
 def test_post_comment(self):
     data = CommentForm(self.unicef).generate_security_data()
     data.update({
         'name': 'the supplied name',
         'comment': 'Foo',
     })
     response = self.url_post(
         'unicef',
         reverse('comments-post-comment'), data)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(MessageBoardComment.objects.all().count(), 1)
     self.assertEqual(MessageBoardComment.objects.all().first().comment, 'Foo')
예제 #9
0
 def test_post_comment(self):
     data = CommentForm(self.unicef).generate_security_data()
     data.update({
         'name': 'the supplied name',
         'comment': 'Foo',
     })
     response = self.url_post('unicef', reverse('comments-post-comment'),
                              data)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(MessageBoardComment.objects.all().count(), 1)
     self.assertEqual(MessageBoardComment.objects.all().first().comment,
                      'Foo')
예제 #10
0
    def test_pin_of_comment_in_another_org(self):
        self.login(self.admin)

        self.assertEqual(MessageBoardComment.objects.all().count(), 0)
        data = CommentForm(target_object=self.nyaruka).generate_security_data()
        data.update({'name': 'the supplied name', 'comment': 'Foo'})
        response = self.url_post(self.nyaruka,
                                 reverse('comments-post-comment'), data)
        self.assertEqual(MessageBoardComment.objects.all().count(), 1)

        # pin in Unicef org
        response = self.url_post(
            self.unicef,
            reverse(
                'msg_board.messageboardcomment_pin',
                kwargs={'pk': MessageBoardComment.objects.all().first().pk}))
        self.assertEqual(response.status_code, 404)
예제 #11
0
    def test_list(self):
        data = CommentForm(self.unicef).generate_security_data()
        data.update({"comment": "Foo"})
        self.url_post("unicef", reverse("comments-post-comment"), data)

        data = CommentForm(self.unicef).generate_security_data()
        data.update({"comment": "Bar"})
        self.url_post("unicef", reverse("comments-post-comment"), data)

        response = self.url_get("unicef",
                                reverse("msg_board.messageboardcomment_list"))

        comment1, comment2 = list(MessageBoardComment.objects.order_by("pk"))

        self.assertEqual(
            response.json,
            {
                "results": [
                    {
                        "id": comment2.pk,
                        "comment": "Bar",
                        "user": {
                            "id": self.user1.pk,
                            "name": "Evan"
                        },
                        "submitted_on": format_iso8601(comment2.submit_date),
                        "pinned_on": None,
                    },
                    {
                        "id": comment1.pk,
                        "comment": "Foo",
                        "user": {
                            "id": self.user1.pk,
                            "name": "Evan"
                        },
                        "submitted_on": format_iso8601(comment1.submit_date),
                        "pinned_on": None,
                    },
                ]
            },
        )
예제 #12
0
    def test_list(self):
        data = CommentForm(self.unicef).generate_security_data()
        data.update({'comment': 'Foo'})
        self.url_post('unicef', reverse('comments-post-comment'), data)

        data = CommentForm(self.unicef).generate_security_data()
        data.update({'comment': 'Bar'})
        self.url_post('unicef', reverse('comments-post-comment'), data)

        response = self.url_get('unicef',
                                reverse('msg_board.messageboardcomment_list'))

        comment1, comment2 = list(MessageBoardComment.objects.order_by('pk'))

        self.assertEqual(
            response.json, {
                'results':
                [{
                    'id': comment2.pk,
                    'comment': "Bar",
                    'user': {
                        'id': self.user1.pk,
                        'name': "Evan"
                    },
                    'submitted_on': format_iso8601(comment2.submit_date),
                    'pinned_on': None
                }, {
                    'id': comment1.pk,
                    'comment': "Foo",
                    'user': {
                        'id': self.user1.pk,
                        'name': "Evan"
                    },
                    'submitted_on': format_iso8601(comment1.submit_date),
                    'pinned_on': None
                }]
            })