Re: Problems from writing test cases.

2018-12-13 Thread ANi
> > Great! Thank you for the explanation, it's what exactly I want to know, >> really helps a lot. ;-) >> > nm於 2018年12月13日星期四 UTC+8下午10時25分36秒寫道: > > Regarding the first question and the problem with retrieving the user with > `pk=1`: > When you run your tests, Django creates a test database

Re: Problems from writing test cases.

2018-12-13 Thread ANi
> > Great! Thank you for the explanation, it's what exactly I want to know, >> really helps a lot. ;-) >> >> nm於 2018年12月13日星期四 UTC+8下午10時25分36秒寫道: > > Regarding the first question and the problem with retrieving the user with > `pk=1`: > When you run your tests, Django creates a test database w

Re: Problems from writing test cases.

2018-12-13 Thread nm
Regarding the first question and the problem with retrieving the user with `pk=1`: When you run your tests, Django creates a test database where all the objects created by the test cases are stored, and which is destroyed after all the tests are run. Each user you create gets a *new* pk. The pk

Re: Problems from writing test cases.

2018-12-12 Thread ANi
> > This is my first time. lol > > I thought we can access the data by using ORM as we usually do rather than set it to a class variable. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails

Re: Problems from writing test cases.

2018-12-11 Thread Yarving Liu
I never tried UT like below: class SecondTest(TestCase): @classmethod def setUpTestData(cls): User.objects.create(username = 'janedoe', password = 'nicetobethere456') Thank you the same. On Tue, Dec 11, 2018 at 12:45 PM ANi wrote: > Oh. ok :) > > Then I tried to call again the

Re: Problems from writing test cases.

2018-12-10 Thread ANi
Oh. ok :) Then I tried to call again the item object by its pk, and it works. item = Item.objects.get(pk=self.item.pk) and sorry for the test_item_delete(). I passed the wrong parameter so the view got a None to retrieve the item object, that's why it returns 404. thank you so much. -- You

Re: Problems from writing test cases.

2018-12-10 Thread Yarving Liu
For the: self.assertEqual(self.item.category, 2) this is because you defined self.item in setUp, and self.category = 1. Others have no idea, expect answers the same. On Tue, Dec 11, 2018 at 12:00 PM ANi wrote: > Hello, > I am now trying to write test cases for my project, but I find some > pr

Problems from writing test cases.

2018-12-10 Thread ANi
Hello, I am now trying to write test cases for my project, but I find some problems. 1. class FirstTest(TestCase): @classmethod def setUpTestData(cls): User.objects.create(username = 'johndoe', password = 'goodtobehere123') ... def test_case_one(self): user =