def test_view(self): self.is_callable(self.user) data = {'image': get_image(), } self.is_postable(user=self.user, data=data, to=self.dummy.get_absolute_url()) data = {'image': get_image(), 'next': '/?foo=bar'} self.is_postable(user=self.user, data=data, to='/?foo=bar') data = {'image': get_image(), } self.is_postable(user=self.user, data=data, to='/?foo=bar') self.is_not_callable(post=True, user=self.user, kwargs={ 'content_type': 'dummymodel', 'object_id': 999}) self.is_not_callable(post=True, user=self.user, kwargs={ 'content_type': 'foobarmodel', 'object_id': 1}) self.is_not_callable(post=True, user=self.user, kwargs={ 'content_type': 'dummymodel', 'object_id': self.other_dummy.pk }) self.is_not_callable(user=self.user, kwargs={ 'content_type': ContentType.objects.get_for_model( self.gallery).model, 'object_id': self.gallery.pk, })
def test_view(self): self.is_callable(self.user) data = {'image': get_image(), 'next': '/?foo=bar'} self.is_postable(user=self.user, to='/?foo=bar', data=data) data = {'image': get_image(), } try: self.is_postable(user=self.user, data=data) except Exception as err: self.assertTrue('No content object' in '{}'.format(err), msg=( 'If no content object and no ``next`` parameter given,' ' view should raise an exception'))
def test_view(self): self.image.image = get_image() self.image.save() self.is_not_callable(user=self.image.user) data = {'x': 10, 'x2': 15, 'y': 2, 'y2': 10, 'w': 5, 'h': 8} self.is_postable(user=self.image.user, data=data, ajax=True) self.is_not_callable(user=self.image2.user, ajax=True, post=True)
def test_view(self): self.is_callable(self.user) data = {'image': get_image(), 'next': '/?foo=bar'} self.is_postable(user=self.user, to='/?foo=bar', data=data) data = { 'image': get_image(), } try: self.is_postable(user=self.user, data=data) except Exception as err: self.assertTrue( 'No content object' in '{}'.format(err), msg=('If no content object and no ``next`` parameter given,' ' view should raise an exception'))
def upload_to_gallery(self): kwargs = {'c_type': self.c_type, 'obj_id': self.profile.id} self.is_postable(data={'image': get_image()}, ajax=True, user=self.profile.user, kwargs=kwargs, msg=('Upload should be valid.'))
def test_view(self): self.is_callable(self.user) data = { 'image': get_image(), } self.is_postable(user=self.user, data=data, to=self.dummy.get_absolute_url()) data = {'image': get_image(), 'next': '/?foo=bar'} self.is_postable(user=self.user, data=data, to='/?foo=bar') data = { 'image': get_image(), } self.is_postable(user=self.user, data=data, to='/?foo=bar') self.is_not_callable(post=True, user=self.user, kwargs={ 'content_type': 'dummymodel', 'object_id': 999 }) self.is_not_callable(post=True, user=self.user, kwargs={ 'content_type': 'foobarmodel', 'object_id': 1 }) self.is_not_callable(post=True, user=self.user, kwargs={ 'content_type': 'dummymodel', 'object_id': self.other_dummy.pk }) self.is_not_callable(user=self.user, kwargs={ 'content_type': ContentType.objects.get_for_model( self.gallery).model, 'object_id': self.gallery.pk, })
def test_mixin(self): form = DummyModelForm(instance=mixer.blend('test_app.DummyModel'), data={'user': mixer.blend('auth.User').pk}, files={'images': get_image()}) self.assertTrue(form.is_valid(), msg=('Should be valid, but returned: {}'.format( form.errors.items()))) form.save()
def test_form(self): form = UserMediaImageForm( mixer.blend('auth.User'), None, None, files={'image': get_image()}) self.assertTrue(form.is_valid(), msg=( 'Should be valid but returned: %s' % form.errors.items())) result = form.save() self.assertIn('.jpg', result.image.url)
def test_mixin(self): form = DummyModelForm( instance=mixer.blend('test_app.DummyModel'), data={'user': mixer.blend('auth.User').pk}, files={'images': get_image()}) self.assertTrue(form.is_valid(), msg=( 'Should be valid, but returned: {}'.format( form.errors.items()))) form.save()
def test_view(self): self.is_not_callable(post=True, user=self.gallery.user_connection, msg=('Should only be callable via AJAX.')) self.is_postable(data={'logo': get_image()}, ajax=True, user=self.gallery.user_connection, msg=('Upload should be valid.')) new_kwargs = { 'c_type': 'foo', 'obj_id': self.gallery.id, 'field': 'logo', } self.is_not_callable( ajax=True, post=True, kwargs=new_kwargs, user=self.gallery.user_connection, msg=('Should only be callable, if content type exists.')) new_kwargs = { 'c_type': self.c_type, 'obj_id': self.gallery.id, 'field': 'foobar', } self.is_not_callable(ajax=True, post=True, kwargs=new_kwargs, user=self.gallery.user_connection, msg=('Should only be callable, if field exists.')) new_kwargs = { 'c_type': self.c_type, 'obj_id': '999', 'field': 'logo', } self.is_not_callable( ajax=True, post=True, kwargs=new_kwargs, user=self.gallery.user_connection, msg=('Should only be callable, if content object exists.')) new_kwargs = { 'c_type': self.c_type, 'obj_id': self.other_gallery.pk, 'field': 'logo', } self.is_not_callable( ajax=True, post=True, kwargs=new_kwargs, user=self.gallery.user_connection, msg=('Should only be callable, if the current user owns the' ' chosen vendor.'))
def test_view(self): self.is_not_callable(user=self.profile.user, msg=('Should only be callable via AJAX.')) self.is_not_callable( user=self.profile.user, ajax=True, kwargs={ 'c_type': 'foo', 'obj_id': self.profile.id }, msg=('Should only be callable, if content type exists.')) self.is_not_callable( user=self.profile.user, ajax=True, kwargs={ 'c_type': self.c_type, 'obj_id': 999 }, msg=('Should only be callable, if content object exists.')) self.is_not_callable( user=self.profile.user, ajax=True, kwargs={ 'c_type': self.c_type, 'obj_id': self.other_profile.pk }, msg=('Should only be callable, if the current user owns the' ' chosen profile.')) self.is_not_callable( user=self.profile.user, ajax=True, kwargs={ 'c_type': ContentType.objects.get_for_model(self.invalid_content_object), 'obj_id': self.invalid_content_object.pk }, msg=("Should only be callable, if the content object is one of" " the user's items.")) self.upload_to_gallery() self.upload_to_gallery() self.upload_to_gallery() self.upload_to_gallery() self.upload_to_gallery() resp = self.is_postable(data={'image': get_image()}, ajax=True, user=self.profile.user, msg=('Upload should be valid.')) self.assertEqual(resp.content, b'Maximum amount limit exceeded.', msg=('Should return an error message.'))
def setUp(self): self.dummy = mixer.blend('test_app.DummyModel') self.user = self.dummy.user self.image = mixer.blend('user_media.UserMediaImage', user=self.user) self.image.content_object = self.dummy self.image.image = get_image() self.image.save() self.image_no_content_object = mixer.blend( 'user_media.UserMediaImage', user=self.user) self.other_image = mixer.blend('user_media.UserMediaImage')
def setUp(self): self.dummy = mixer.blend('test_app.DummyModel') self.user = self.dummy.user self.image = mixer.blend('user_media.UserMediaImage', user=self.user) self.image.content_object = self.dummy self.image.image = get_image() self.image.save() self.image_no_content_object = mixer.blend('user_media.UserMediaImage', user=self.user) self.other_image = mixer.blend('user_media.UserMediaImage')
def test_form(self): form = UserMediaImageForm(mixer.blend('auth.User'), None, None, files={'image': get_image()}) self.assertTrue(form.is_valid(), msg=('Should be valid but returned: %s' % form.errors.items())) result = form.save() self.assertIn('.jpg', result.image.url)
def test_view(self): self.is_not_callable(post=True, user=self.gallery.user_connection, msg=('Should only be callable via AJAX.')) self.is_postable( data={'logo': get_image()}, ajax=True, user=self.gallery.user_connection, msg=('Upload should be valid.')) new_kwargs = { 'c_type': 'foo', 'obj_id': self.gallery.id, 'field': 'logo', } self.is_not_callable( ajax=True, post=True, kwargs=new_kwargs, user=self.gallery.user_connection, msg=('Should only be callable, if content type exists.')) new_kwargs = { 'c_type': self.c_type, 'obj_id': self.gallery.id, 'field': 'foobar', } self.is_not_callable( ajax=True, post=True, kwargs=new_kwargs, user=self.gallery.user_connection, msg=('Should only be callable, if field exists.')) new_kwargs = { 'c_type': self.c_type, 'obj_id': '999', 'field': 'logo', } self.is_not_callable( ajax=True, post=True, kwargs=new_kwargs, user=self.gallery.user_connection, msg=('Should only be callable, if content object exists.')) new_kwargs = { 'c_type': self.c_type, 'obj_id': self.other_gallery.pk, 'field': 'logo', } self.is_not_callable( ajax=True, post=True, kwargs=new_kwargs, user=self.gallery.user_connection, msg=('Should only be callable, if the current user owns the' ' chosen vendor.'))
def test_view(self): self.is_not_callable(user=self.profile.user, msg=('Should only be callable via AJAX.')) self.is_not_callable( user=self.profile.user, ajax=True, kwargs={'c_type': 'foo', 'obj_id': self.profile.id}, msg=('Should only be callable, if content type exists.')) self.is_not_callable( user=self.profile.user, ajax=True, kwargs={'c_type': self.c_type, 'obj_id': 999}, msg=('Should only be callable, if content object exists.')) self.is_not_callable( user=self.profile.user, ajax=True, kwargs={'c_type': self.c_type, 'obj_id': self.other_profile.pk}, msg=('Should only be callable, if the current user owns the' ' chosen profile.')) self.is_not_callable( user=self.profile.user, ajax=True, kwargs={ 'c_type': ContentType.objects.get_for_model( self.invalid_content_object), 'obj_id': self.invalid_content_object.pk }, msg=("Should only be callable, if the content object is one of" " the user's items.")) self.upload_to_gallery() self.upload_to_gallery() self.upload_to_gallery() self.upload_to_gallery() self.upload_to_gallery() resp = self.is_postable( data={'image': get_image()}, ajax=True, user=self.profile.user, msg=('Upload should be valid.')) self.assertEqual(resp.content, b'Maximum amount limit exceeded.', msg=( 'Should return an error message.'))
def upload_to_gallery(self): kwargs = {'c_type': self.c_type, 'obj_id': self.profile.id} self.is_postable( data={'image': get_image()}, ajax=True, user=self.profile.user, kwargs=kwargs, msg=('Upload should be valid.'))