Пример #1
0
def test_get_municipality_versions_by_datetime(get):
    municipality = MunicipalityFactory(name="Cabour")
    municipality.version = 2
    municipality.name = "Cabour2"
    municipality.save()
    # Artificialy change versions periods.
    period = [datetime(2015, 1, 1), datetime(2016, 1, 1)]
    Version.update(period=period).where(Version.sequential == 1).execute()
    period = [datetime(2016, 1, 1), None]
    Version.update(period=period).where(Version.sequential == 2).execute()
    # Should work with a simple datetime.
    resp = get('/municipality/{}/versions/2015-06-01T01:02:03+00:00'.format(
        municipality.id))
    assert resp.status_code == 200
    assert resp.json['data']['name'] == 'Cabour'
    # Should work with a naive datetime too.
    resp = get('/municipality/{}/versions/2015-06-01 01:02:03'.format(
        municipality.id))
    assert resp.status_code == 200
    assert resp.json['data']['name'] == 'Cabour'
    # Should work with a simple date too.
    resp = get('/municipality/{}/versions/2015-06-01'.format(municipality.id))
    assert resp.status_code == 200
    assert resp.json['data']['name'] == 'Cabour'
    # Now ask in the range of the second version
    resp = get('/municipality/{}/versions/2016-06-01'.format(municipality.id))
    assert resp.status_code == 200
    assert resp.json['data']['name'] == 'Cabour2'
    # Asking for the common bound should return the new version.
    resp = get('/municipality/{}/versions/2016-01-01 00:00:00'.format(
        municipality.id))
    assert resp.status_code == 200
    assert resp.json['data']['name'] == 'Cabour2'
Пример #2
0
def test_can_get_deleted_municipality_version(get):
    municipality = MunicipalityFactory(name="Cabour")
    municipality.version = 2
    municipality.name = "Cabour2"
    municipality.save()
    resp = get('/municipality/{}/versions/2'.format(municipality.id))
    assert resp.status_code == 200
    assert resp.json['data']['name'] == 'Cabour2'
Пример #3
0
def test_get_municipality_versions(get):
    municipality = MunicipalityFactory(name="Cabour")
    municipality.version = 2
    municipality.name = "Cabour2"
    municipality.save()
    resp = get('/municipality/{}/versions'.format(municipality.id))
    assert resp.status_code == 200
    assert len(resp.json['collection']) == 2
    assert resp.json['total'] == 2
    assert resp.json['collection'][0]['data']['name'] == 'Cabour'
    assert resp.json['collection'][1]['data']['name'] == 'Cabour2'