Example #1
0
def test_status_is_readonly(post):
    municipality = MunicipalityFactory()
    data = municipality.serialize({'*': {}})
    data['status'] = 'deleted'
    data['version'] = 2
    resp = post('/municipality/{}'.format(municipality.id), data=data)
    assert resp.status_code == 200
Example #2
0
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
Example #3
0
def test_cannot_change_deleted_at_with_put(put):
    municipality = MunicipalityFactory()
    data = municipality.serialize({'*': {}})
    data['deleted_at'] = utcnow().isoformat()
    data['version'] = 2
    resp = put('/municipality/{}'.format(municipality.id), data=data)
    assert resp.status_code == 200
    assert not models.Municipality.get(
        models.Municipality.pk == municipality.pk).deleted_at
Example #4
0
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
Example #5
0
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