그래서 난에 대해 테스트 할 수있는 모델 객체 생성하기 위해 설정 methiod있는 테스트 클래스가 있습니다장고 PK 문제가 증가 된 테스트
class UserProjectTests(TestCase):
fixtures = ['admin_test.json']
def setUp(self):
...
self.project1 = Project.objects.create(
user=self.user_profile1,
product=self.product1,
module=self.module1,
model=self.model1,
zipcode=90210
)
self.project1.save()
def test_module_created(self):
...
def test_model_created(self):
...
def test_product_created(self):
...
def test_project_created(self):
#! what happened to pk<4???
result1 = Project.objects.get(pk=4)
self.assertEquals(result1.zipcode, 90210)
def test_user_cannot_edit_project_they_dont_own(self):
...
내 질문은 - 왜 얻을 pk=4
전화를해야 할 테스트 데이터베이스의 유일한 개체? 이 테스트를 몇 가지 기능으로 옮기면 테스트를 통과해야하는 쿼리가 줄어 듭니다. pk가 자동으로 증가하기 때문에 매번 setup이 실행될 때 처녀 db로 시작하지 않는 것 같습니다.
아무도 왜 이것이 내게 말할 수 있습니까? 어떤 테스트 기능이 나타나는지에 관계없이 pk = 1을 사용할 수 있으려면 어떻게해야합니까? 정말이 DB의 유일한 객체가 될 것으로 예상되는 경우
그냥 관심 밖 - 테스트 주자는 테이블을 플러시하는 데'truncate '를 사용하지 않습니까? 자동 증가 값을 0으로 반환했다고 생각했습니다. –