class FirstTest(TestCase):
@classmethod
def setUpTestData(cls):
User.objects.create(username = 'johndoe', password = 'goodtobehere123')
...
def test_case_one(self):
user = User.objects.get(pk=1)
# some assertions here
...
class SecondTest(TestCase):
@classmethod
def setUpTestData(cls):
User.objects.create(username = 'janedoe', password = 'nicetobethere456')
def test_case_one(self):
user = User.objects.get(pk=1)
# some assertions here
...
class FirstTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.user = User.objects.create(username = 'johndoe', password = 'goodtobehere123')
...
def test_case_one(self):
self.assertEqual(self.user.somefunc(), something)
# some assertions here
...
class SecondTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.user = User.objects.create(username = 'janedoe', password = 'nicetobethere456')
...
def test_case_one(self):
self.assertEqual(self.user.somefunc(), something)
# some assertions here
...
class ViewTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.user = User.objects.create(username = 'johndoe', password = 'goodtobehere123')
...
def setUp(self):
self.item = Item.objects.create(
category = 1,
item_content = 'content content',
)
def test_item_update(self):
# the view will update the item and return HTTP status code 200.
# if the item is not exist, raise Http404
self.c = Client()
resp = self.c.post(
reverse('update_item', kwargs={"pk":self.item.pk}),
data = {
"category": 2,
"content": "item content",
}
)
self.assertEqual(resp.status_code, 200)
self.assertEqual(self.item.category, 2)
def test_item_delete(self):
# the view will delete the item and return HTTP status code 200.
# if the item is not exist, raise Http404
self.c = Client()
resp = self.c.post(
reverse('delete_item'),
data = {
"pk": self.item.pk
}
)
self.assertEqual(resp.status_code, 200)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f1f9855a-3461-45a1-bdee-2ec901a7f718%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/18e1efaa-a625-4c66-b669-f99cdb04fe0e%40googlegroups.com.
This is my first time. lol
Great! Thank you for the explanation, it's what exactly I want to know, really helps a lot. ;-)