Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
 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)
Пример #4
0
 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)
Пример #5
0
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)
Пример #6
0
 def get_success_url(self):
     return reverse('{}:list'.format(self.model_name))
Пример #7
0
 def get_success_url(self):
     return reverse(
         '{}:read'.format(
             self.model_name
         ), args=(self.object.pk,)
     )
Пример #8
0
 def test_create_view(self):
     expected = 'Lorem ipsum'
     url = reverse('post:create')
     self.client.post(url, {'title': expected, 'body': expected})
Пример #9
0
 def test_list_view(self):
     url = reverse('post:list')
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
Пример #10
0
 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)
Пример #11
0
 def test_create_view(self):
     expected = 'Lorem ipsum'
     url = reverse('post:create')
     self.client.post(url, {'title': expected, 'body': expected})
Пример #12
0
 def test_list_view(self):
     url = reverse('post:list')
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
Пример #13
0
 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)
Пример #14
0
 def get_success_url(self):
     return reverse('{}:list'.format(self.model_name))
Пример #15
0
 def get_success_url(self):
     return reverse('{}:read'.format(self.model_name),
                    args=(self.object.pk, ))