Пример #1
0
    def test_create__call_tags_created_signal(self):
        from mock_django.http import MockHttpRequest
        request = MockHttpRequest(POST=self.data)
        request.user = self.tagger

        with mock_signal_receiver(o2o_tags_created) as tags_created_receiver:
            TagsCreateView.as_view()(request)
            self.assertTrue(tags_created_receiver.called)
Пример #2
0
    def test_create__call_tags_created_signal(self):
        from mock_django.http import MockHttpRequest
        request = MockHttpRequest(POST=self.data)
        request.user = self.tagger

        with mock_signal_receiver(o2o_tags_created) as tags_created_receiver:
            TagsCreateView.as_view()(request)
            self.assertTrue(tags_created_receiver.called)
Пример #3
0
    def test_tag_create__form_invalid(self):
        request = MockHttpRequest(POST={})
        request.user = self.tagger

        response = TagCreateView.as_view()(request)
        tags = O2OTag.objects.all()

        self.assertEqual(400, response.status_code)
        self.assertEqual(0, tags.count())
Пример #4
0
    def test_tag_create__form_invalid(self):
        request = MockHttpRequest(POST={})
        request.user = self.tagger

        response = TagCreateView.as_view()(request)
        tags = O2OTag.objects.all()

        self.assertEqual(400, response.status_code)
        self.assertEqual(0, tags.count())
Пример #5
0
    def test_create__tagger_is_request_user(self):
        request = MockHttpRequest(POST=self.data)
        request.user = self.tagger

        response = TagsCreateView.as_view()(request)
        tags = O2OTag.objects.all()

        self.assertEqual(201, response.status_code)
        self.assertEqual(2, tags.count())
        for t in tags:
            self.assertEqual(self.tagger, t.tagger)
Пример #6
0
    def test_tag_create(self):
        request = MockHttpRequest(POST=self.data)
        request.user = self.tagger

        response = TagCreateView.as_view()(request)
        tag = O2OTag.objects.get()

        self.assertEqual(201, response.status_code)
        self.assertEqual(self.tagger, tag.tagger)
        self.assertEqual(self.tagged, tag.tagged)
        self.assertEqual(self.tagged_in, tag.tagged_in)
Пример #7
0
    def test_create__tagger_is_request_user(self):
        request = MockHttpRequest(POST=self.data)
        request.user = self.tagger

        response = TagsCreateView.as_view()(request)
        tags = O2OTag.objects.all()

        self.assertEqual(201, response.status_code)
        self.assertEqual(2, tags.count())
        for t in tags:
            self.assertEqual(self.tagger, t.tagger)
Пример #8
0
    def test_tag_create(self):
        request = MockHttpRequest(POST=self.data)
        request.user = self.tagger

        response = TagCreateView.as_view()(request)
        tag = O2OTag.objects.get()

        self.assertEqual(201, response.status_code)
        self.assertEqual(self.tagger, tag.tagger)
        self.assertEqual(self.tagged, tag.tagged)
        self.assertEqual(self.tagged_in, tag.tagged_in)
Пример #9
0
    def test_save__tagger_is_request_user(self):
        tag_form = TagFormAuthenticated(self.data)
        tag_form.is_valid()
        request = MockHttpRequest(POST=self.data)
        request.user = self.tagger

        tag = tag_form.save(request=request)
        expected_tag = O2OTag.objects.get()

        self.assertIsInstance(tag, O2OTag)
        self.assertEqual(expected_tag, tag)
Пример #10
0
    def test_save__tagger_is_request_user(self):
        tags_form = TagFormAuthenticatedSet(self.data)
        tags_form.clean()
        request = MockHttpRequest(POST=self.data)
        request.user = self.tagger

        tags = tags_form.save(request)
        expected_tags = list(O2OTag.objects.filter())

        self.assertIsInstance(tags, QuerySet)
        self.assertListEqual(expected_tags, list(tags))
Пример #11
0
    def test_tag_create__form_invalid(self):
        data = {
            'form-TOTAL_FORMS': u'2',
            'form-INITIAL_FORMS': u'0',
            'form-MAX_NUM_FORMS': u'',
            'form-0-tagged_object_id': self.tagged.pk,
            'form-0-tagged_content_type': self.tagged_content_type.pk,
        }
        request = MockHttpRequest(POST=data)
        request.user = self.tagger

        response = TagsCreateView.as_view()(request)
        tags = O2OTag.objects.all()

        self.assertEqual(400, response.status_code)
        self.assertEqual(0, tags.count())
Пример #12
0
    def test_tag_create__form_invalid(self):
        data = {
            'form-TOTAL_FORMS': u'2',
            'form-INITIAL_FORMS': u'0',
            'form-MAX_NUM_FORMS': u'',
            'form-0-tagged_object_id': self.tagged.pk,
            'form-0-tagged_content_type': self.tagged_content_type.pk,
        }
        request = MockHttpRequest(POST=data)
        request.user = self.tagger

        response = TagsCreateView.as_view()(request)
        tags = O2OTag.objects.all()

        self.assertEqual(400, response.status_code)
        self.assertEqual(0, tags.count())