def test_trigger_do_not_increase_version_if_error(): instance = TriggerConcurrentModel() assert instance.pk is None assert instance.version == 0 with mock.patch('demo.models.TriggerConcurrentModel.save', side_effect=IntegrityError): with pytest.raises(IntegrityError): instance.save() assert instance.version == 0
def test_trigger_external_update(): instance = TriggerConcurrentModel() assert instance.pk is None assert instance.version == 0 instance.save() assert instance.version == 1 with connection.cursor() as c: c.execute("UPDATE {} SET username='******' WHERE id='{}'".format(instance._meta.db_table, instance.pk)) obj = refetch(instance) assert obj.version == 2
def test_trigger_external_update(): instance = TriggerConcurrentModel() assert instance.pk is None assert instance.version == 0 instance.save() assert instance.version == 1 with connection.cursor() as c: c.execute("UPDATE {} SET username='******' WHERE id='{}'".format( instance._meta.db_table, instance.pk)) obj = refetch(instance) assert obj.version == 2
def test_trigger(): instance = TriggerConcurrentModel() assert instance.pk is None assert instance.version == 0 instance.username = next(nextname) instance.save() # insert instance = refetch(instance) assert instance.version == 1 instance.username = next(nextname) instance.save() # update assert instance.version == 2 instance.username = next(nextname) instance.save() # update assert instance.version == 3 instance.username = next(nextname) instance.save(refetch=True) # update assert instance.version == 4 copy = refetch(instance) copy.save() with pytest.raises(RecordModifiedError): instance.save()
def test_trigger(): instance = TriggerConcurrentModel() assert instance.pk is None assert instance.version == 0 instance.username = next(nextname) instance.save() # insert instance = refetch(instance) assert instance.version == 1 instance.username = next(nextname) instance.save() # update assert instance.version == 2 instance.username = next(nextname) instance.save() # update assert instance.version == 3 copy = refetch(instance) copy.save() with pytest.raises(RecordModifiedError): instance.save()