def test_model_with_zero_pk(self): beatles = Band(name='The Beatles', members=[ BandMember(name='John Lennon'), BandMember(name='Paul McCartney'), ]) beatles.save() beatles.pk = 0 beatles.members.commit() beatles.save()
def test_model_with_zero_pk(self): beatles = Band(name='The Beatles', members=[ BandMember(name='John Lennon'), BandMember(name='Paul McCartney'), ]) beatles.save() beatles.pk = 0 beatles.members.commit() beatles.save() self.assertEqual(Band.objects.get(pk=0).name, 'The Beatles')
def test_integrity_error_with_none_pk(self): beatles = Band(name='The Beatles', members=[ BandMember(name='John Lennon'), BandMember(name='Paul McCartney'), ]) beatles.save() beatles.pk = None self.assertRaises(IntegrityError, lambda: beatles.members.commit()) # this should work fine, as Django will end up cloning this entity beatles.save()
def test_integrity_error_with_none_pk(self): beatles = Band(name='The Beatles', members=[ BandMember(name='John Lennon'), BandMember(name='Paul McCartney'), ]) beatles.save() beatles.pk = None self.assertRaises(IntegrityError, lambda: beatles.members.commit()) # this should work fine, as Django will end up cloning this entity beatles.save() self.assertEqual(Band.objects.get(pk=beatles.pk).name, 'The Beatles')