def _filter_or_exclude(self, negate, *args, **kwargs): if self.gr_field in kwargs: instance = kwargs.pop(self.gr_field) kwargs.update(**{ self.ct_field: ct(instance), self.fk_field: instance.pk }) return super(GenericQuerySet, self)._filter_or_exclude(negate, *args, **kwargs)
def test_success_redirect_when_content_object_hasnt_absolute_url(self): resp = self.client.post(self.url, { 'message': 'Test comment', 'user_name': 'Anonymous', 'user_email': '*****@*****.**', 'content_type': ct(self.post).pk, 'object_pk': self.post.pk, }) self.assertEqual('/', urlparse.urlparse(resp['location']).path)
def test_signal_fired(self): comment_created.connect(signal_handler, sender=Comment) with self.assertRaises(SignalFired): self.client.post(self.url, { 'message': 'Test comment', 'user_name': 'Anonymous', 'user_email': '*****@*****.**', 'content_type': ct(self.post).pk, 'object_pk': self.post.pk, }) comment_created.disconnect(signal_handler, sender=Comment)
def test_authenticated_user_create_comment(self): self.client.post(self.url, { 'message': 'Test comment', 'user_name': 'Anonymous', 'user_email': '*****@*****.**', 'content_type': ct(self.post).pk, 'object_pk': self.post.pk, }) comment = Comment.objects.get() self.assertIsNone(comment.parent) self.assertEqual(self.user, comment.user) self.assertEqual('Test comment', comment.message) self.assertEqual('Anonymous', comment.user_name) self.assertEqual('*****@*****.**', comment.user_email)
def test_ct_works_for_model_class(): assert isinstance(ct(JustModel), ContentType)
def test_ct_works_for_model_instances(): assert isinstance(ct(JustModel(name='Oh wow')), ContentType)
def get_for_model(self, model): return self.get_queryset().filter(**{self.ct_field: ct(model)})
def get_for_object(self, content_object): return self.get_queryset().filter(**{ self.ct_field: ct(content_object), self.fk_field: content_object.pk })
def get_for_model(self, model): return self.filter(**{self.gr_field: ct(model)})