def test_can_get_deleted_municipality(get): municipality = MunicipalityFactory() municipality.mark_deleted() resp = get('/municipality/{}'.format(municipality.id)) assert resp.status_code == 410 assert resp.json['id'] == municipality.id assert len(municipality.versions) == 2
def test_cannot_restore_municipality_without_changing_version(client): municipality = MunicipalityFactory() municipality.mark_deleted() data = municipality.serialize({'*': {}}) resp = client.put('/municipality/{}'.format(municipality.id), data=data) assert resp.status_code == 409 assert models.Municipality.raw_select().where( models.Municipality.pk == municipality.pk).get().deleted_at
def test_get_collection_without_deleted(get): municipality1 = MunicipalityFactory() municipality2 = MunicipalityFactory() municipality2.mark_deleted() resp = get('/municipality') assert resp.status_code == 200 assert resp.json['total'] == 1 assert resp.json['collection'][0]['id'] == municipality1.id
def test_cannot_restore_municipality_with_invalid_data(client): municipality = MunicipalityFactory() municipality.mark_deleted() data = municipality.serialize({'*': {}}) data['name'] = '' data['version'] = 3 resp = client.put('/municipality/{}'.format(municipality.id), data=data) assert resp.status_code == 422 assert models.Municipality.raw_select().where( models.Municipality.pk == municipality.pk).get().deleted_at
def test_can_restore_municipality(client): municipality = MunicipalityFactory() municipality.mark_deleted() data = municipality.serialize({'*': {}}) data['version'] = 3 resp = client.put('/municipality/{}'.format(municipality.id), data=data) assert resp.status_code == 200 assert not models.Municipality.get( models.Municipality.pk == municipality.pk).deleted_at assert len(municipality.versions) == 3
def test_cannot_patch_on_deleted_municipality(patch): municipality = MunicipalityFactory() municipality.mark_deleted() resp = patch('/municipality/{}'.format(municipality.id), data={}) assert resp.status_code == 410