def test_can_delete_redirect_with_other_identifier(client): municipality = factories.MunicipalityFactory(insee='54321') Redirect.add(identifier='insee', value='12345', instance=municipality) assert Redirect.select().count() resp = client.delete('/municipality/insee:54321/redirects/insee:12345') assert resp.status_code == 204 assert not Redirect.select().count()
def test_cannot_duplicate_redirection(): position = factories.PositionFactory() Redirect.add(position, "pk", "939") assert Redirect.select().count() == 1 Redirect.add(position, "pk", "939") assert Redirect.select().count() == 1 assert Redirect.follow("Position", "pk", "939") == [position.id]
def test_cannot_duplicate_redirection(): position = factories.PositionFactory() Redirect.add(position, 'pk', '939') assert Redirect.select().count() == 1 Redirect.add(position, 'pk', '939') assert Redirect.select().count() == 1 assert Redirect.follow('Position', 'pk', '939') == [position.id]
def test_should_not_be_deleted_if_instance_remove_fails(): housenumber = factories.HouseNumberFactory() position = factories.PositionFactory(housenumber=housenumber) Redirect.add(position, 'pk', 32) assert Redirect.select().count() == 1 with pytest.raises(peewee.IntegrityError): housenumber.delete_instance() assert Redirect.select().count() == 1
def test_should_not_be_deleted_if_instance_remove_fails(): housenumber = factories.HouseNumberFactory() position = factories.PositionFactory(housenumber=housenumber) Redirect.add(position, "pk", 32) assert Redirect.select().count() == 1 with pytest.raises(peewee.IntegrityError): housenumber.delete_instance() assert Redirect.select().count() == 1
def test_can_create_multiple_redirections(): position1 = factories.PositionFactory() position2 = factories.PositionFactory() Redirect.add(position1, 'pk', '939') assert Redirect.select().count() == 1 Redirect.add(position2, 'pk', '939') assert Redirect.select().count() == 2 redirects = Redirect.follow('Position', 'pk', '939') assert position1.id in redirects assert position2.id in redirects
def test_can_create_multiple_redirections(): position1 = factories.PositionFactory() position2 = factories.PositionFactory() Redirect.add(position1, "pk", "939") assert Redirect.select().count() == 1 Redirect.add(position2, "pk", "939") assert Redirect.select().count() == 2 redirects = Redirect.follow("Position", "pk", "939") assert position1.id in redirects assert position2.id in redirects
def test_multiple_redirects_should_return_300(get): municipality1 = MunicipalityFactory(insee="23456") municipality2 = MunicipalityFactory(insee="34567") # Let's say this municipality has been split. Redirect.add(municipality1, 'insee', '12345') Redirect.add(municipality2, 'insee', '12345') resp = get('/municipality/insee:12345') assert resp.status_code == 300 assert '/municipality/{}'.format(municipality1.id) in resp.headers['Link'] assert '/municipality/{}'.format(municipality1.id) in resp.json['choices'] assert '/municipality/{}'.format(municipality2.id) in resp.headers['Link'] assert '/municipality/{}'.format(municipality2.id) in resp.json['choices']
def test_resource_update_should_propagate_if_target_is_becomming_source(): municipality = factories.MunicipalityFactory(insee="12345") municipality.insee = "54321" municipality.increment_version() municipality.save() assert Redirect.select().count() == 1 assert Redirect.follow("municipality", "insee", "12345") == [municipality.id] municipality2 = factories.MunicipalityFactory(insee="12321") # Should also update '12345' Redirect.add(municipality2, "insee", "54321") municipality.delete_instance() assert Redirect.select().count() == 2 assert Redirect.follow("municipality", "insee", "54321") == [municipality2.id] assert Redirect.follow("municipality", "insee", "12345") == [municipality2.id]
def test_resource_update_should_propagate_if_target_is_becomming_source(): municipality = factories.MunicipalityFactory(insee='12345') municipality.insee = '54321' municipality.increment_version() municipality.save() assert Redirect.select().count() == 1 assert Redirect.follow('municipality', 'insee', '12345') == [ municipality.id] municipality2 = factories.MunicipalityFactory(insee='12321') # Should also update '12345' Redirect.add(municipality2, 'insee', '54321') municipality.delete_instance() assert Redirect.select().count() == 2 assert Redirect.follow('municipality', 'insee', '54321') == [ municipality2.id] assert Redirect.follow('municipality', 'insee', '12345') == [ municipality2.id]
def test_cannot_create_cyclic_redirect(): position = factories.PositionFactory(ign="123456789") with pytest.raises(ValueError): Redirect.add(position, "ign", "123456789") assert not Redirect.select().count()
def test_can_list_redirects(client): municipality = factories.MunicipalityFactory(insee='54321') Redirect.add(identifier='insee', value='12345', instance=municipality) resp = client.get('/municipality/insee:54321/redirects') assert resp.status_code == 200 assert resp.json['collection'] == ['insee:12345']
def test_deleting_resource_should_remove_redirects_pointing_to_it(): position = factories.PositionFactory() Redirect.add(position, "pk", 32) assert Redirect.select().count() == 1 position.delete_instance() assert not Redirect.select().count()
def test_can_point_from_an_identifier_to_another(): municipality = factories.MunicipalityFactory() Redirect.add(municipality, 'insee', '12345') assert Redirect.select().count() == 1 assert Redirect.follow('municipality', 'insee', '12345') == [ municipality.id]
def test_can_remove_a_redirect(): position = factories.PositionFactory() Redirect.add(position, 'pk', 32) assert Redirect.select().count() == 1 Redirect.remove(position, 'pk', 32) assert not Redirect.select().count()
def test_cannot_create_cyclic_redirect(): position = factories.PositionFactory(ign='123456789') with pytest.raises(ValueError): Redirect.add(position, 'ign', '123456789') assert not Redirect.select().count()
def test_cannot_create_redirect_with_invalid_identifier(): position = factories.PositionFactory() with pytest.raises(ValueError): Redirect.add(position, 'invalid', '939') assert not Redirect.select().count()
def test_can_remove_a_redirect(): position = factories.PositionFactory() Redirect.add(position, "pk", 32) assert Redirect.select().count() == 1 Redirect.remove(position, "pk", 32) assert not Redirect.select().count()
def test_deleting_resource_should_remove_redirects_pointing_to_it(): position = factories.PositionFactory() Redirect.add(position, 'pk', 32) assert Redirect.select().count() == 1 position.delete_instance() assert not Redirect.select().count()
def test_cannot_create_redirect_with_invalid_identifier(): position = factories.PositionFactory() with pytest.raises(ValueError): Redirect.add(position, "invalid", "939") assert not Redirect.select().count()
def test_can_point_from_an_identifier_to_another(): municipality = factories.MunicipalityFactory() Redirect.add(municipality, "insee", "12345") assert Redirect.select().count() == 1 assert Redirect.follow("municipality", "insee", "12345") == [municipality.id]