def test_specified_actions(self, actions): post = Post.objects.create(title='test', body='test') crud(Post, actions) for action in ACTIONS: reload_urlconf() args = () if action in ACTIONS_REQUIRED_OBJ: args = (post.pk, ) if action in actions: response = self.client.get( reverse('post:{}'.format(action), args=args)) self.assertEqual(response.status_code, 200) else: with self.assertRaises(NoReverseMatch): reverse('post:{}'.format(action), args=args)
def test_specified_actions(self, actions): post = Post.objects.create(title='test', body='test') crud(Post, actions) for action in ACTIONS: reload_urlconf() args = () if action in ACTIONS_REQUIRED_OBJ: args = (post.pk,) if action in actions: response = self.client.get( reverse('post:{}'.format(action), args=args) ) self.assertEqual(response.status_code, 200) else: with self.assertRaises(NoReverseMatch): reverse('post:{}'.format(action), args=args)
def test_update_view(self): expected = 'Lorem ipsum' post = Post.objects.create(title='test', body='body test') url = reverse('post:update', args=(post.pk, )) self.client.post(url, {'title': expected, 'body': expected}) post = Post.objects.get(pk=post.pk) self.assertEqual(expected, post.title) self.assertEqual(expected, post.body)
def test_update_view(self): expected = 'Lorem ipsum' post = Post.objects.create(title='test', body='body test') url = reverse('post:update', args=(post.pk,)) self.client.post(url, {'title': expected, 'body': expected}) post = Post.objects.get(pk=post.pk) self.assertEqual(expected, post.title) self.assertEqual(expected, post.body)
def crud(obj, action): obj_name = obj._meta.model_name args = [] if action not in site.get_actions(obj.__class__): return '#not_found' if action in ACTIONS_REQUIRED_OBJ: args = [obj.pk] return reverse('{}:{}'.format(obj_name, action), args=args)
def get_success_url(self): return reverse('{}:list'.format(self.model_name))
def get_success_url(self): return reverse( '{}:read'.format( self.model_name ), args=(self.object.pk,) )
def test_create_view(self): expected = 'Lorem ipsum' url = reverse('post:create') self.client.post(url, {'title': expected, 'body': expected})
def test_list_view(self): url = reverse('post:list') response = self.client.get(url) self.assertEqual(response.status_code, 200)
def test_urls(self, name, code, args=True): args = (0, ) if args else () url = reverse(name, args=args) response = self.client.get(url) self.assertEqual(response.status_code, code)
def test_urls(self, name, code, args=True): args = (0,) if args else () url = reverse(name, args=args) response = self.client.get(url) self.assertEqual(response.status_code, code)
def get_success_url(self): return reverse('{}:read'.format(self.model_name), args=(self.object.pk, ))