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)
Beispiel #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)
    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())
Beispiel #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())
    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)
    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)
Beispiel #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)
Beispiel #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)
    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)
    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))
Beispiel #11
0
    def test_call(self):
        class MockUser:
            pass

        result = MockHttpRequest(user=MockUser())

        self.assertTrue(isinstance(result.user, MockUser))
    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())
Beispiel #13
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())
Beispiel #14
0
    def test_call(self):
        result = MockHttpRequest()
        meta = {
            'REMOTE_ADDR': '127.0.0.1',
            'SERVER_PORT': '8000',
            'HTTP_REFERER': '',
            'SERVER_NAME': 'testserver',
        }

        self.assertTrue(isinstance(result, WsgiHttpRequest))
        self.assertEqual('/', result.path)
        self.assertEqual('GET', result.method)
        self.assertEqual(meta, result.META)
        self.assertEqual({}, result.GET)
        self.assertEqual({}, result.POST)
        self.assertTrue(isinstance(result.user, AnonymousUser))