Install
pip install django-test-plus
Usage
from test_plus.test import TestCase
class MyTestCase(TestCase):
...
Methods
reverse(url_name, *args, **kwargs)
Can use reverse
easily
def test_sth(self):
url = self.reverse('my-url-name', pk=12)
Http GET methos
def test_get_url(self):
response = self.get('url-name')
# When using django testcase
respone = self.client.get(reverse('my-url-name'))
self.assertEqual(response.context['test'], 1)
# became easy
respone = self.get(reverse('my-url-name'))
self.respone_200()
# can pass query : /search/?query=testing
self.get('search', data={'query': 'testing'})
Http POST methos
def test_post_url(self):
respone = self.post(
'my-url-name',
data={
'title': 'test title',
}
)
'backend > django' 카테고리의 다른 글
django: how to know previous page in django (0) | 2018.03.18 |
---|---|
django admin을 잘 쓰자! - 장고 어드민 cookbook (0) | 2018.03.13 |
django model test - model_mommy (0) | 2018.02.26 |
django hitcount: counting hit (views) in django (0) | 2018.02.20 |
django: reversed forloop in template (0) | 2018.02.19 |