Beispiel #1
0
def test_wrong_id_failure(client, add_user):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    city = add_city()
    _ = client.delete(endpoint=endpoint,
                      city_id=129129129129192,
                      check_status=404)
    assert City.query.get(city.id)
Beispiel #2
0
def test_malformed_params_failure(client, add_user, address):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)
    city = add_city()

    resp = client.post(endpoint=endpoint,
                       data=dict(address=address, city_id=city.id),
                       check_status=400)
    assert 'errors' in resp
    assert len(resp['errors']) == 1
Beispiel #3
0
def test_not_admin_failure(client, add_user):
    _ = add_user(role=ROLE_USER, log_him_in=True)
    city = add_city()

    resp = client.post(endpoint=endpoint,
                       data=dict(address=get_random_str(), city_id=city.id),
                       check_status=403)
    assert 'errors' in resp
    assert len(resp['errors']) == 1
Beispiel #4
0
def test_default(client, add_user):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    city = add_city()
    resp = client.get(endpoint=endpoint)
    assert 'total' in resp
    assert resp['total'] == 1
    assert 'results' in resp
    assert len(resp['results']) == 1
    assert 'id' in resp['results'][0]
    assert resp['results'][0]['id'] == city.id

    city2 = add_city()
    resp = client.get(endpoint=endpoint)
    assert 'total' in resp
    assert resp['total'] == 2
    assert 'results' in resp
    assert len(resp['results']) == 2
    assert {r['id'] for r in resp['results']} == {city.id, city2.id}
Beispiel #5
0
def test_default(client, add_user):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    city = add_city()
    resp = client.delete(
        endpoint=endpoint,
        city_id=city.id,
    )
    assert 'id' in resp
    assert resp['id'] == city.id
    assert not City.query.get(resp['id'])
Beispiel #6
0
def test_default(client, add_user, address):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)
    city = add_city()

    resp = client.post(endpoint=endpoint,
                       data=dict(address=address, city_id=city.id))
    assert 'id' in resp
    location = Location.query.get(resp['id'])
    assert location

    assert 'address' in resp
    assert resp['address'] == location.address == address
    assert 'city' in resp
    assert 'id' in resp['city']
    assert resp['city']['id'] == city.id
Beispiel #7
0
def test_search_mode(client, add_user):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    common_string = 'FGHJ#$%^&12'
    ids = {
        add_city(name=f'prefixXXX{common_string}').id,
        add_city(name=f'prefixXXX{common_string}postfix123').id,
        add_city(name=f'{common_string}postfix123').id,
        add_city(name=common_string).id
    }
    # Add some noise
    for _ in range(10):
        add_city()

    # Search
    resp = client.get(endpoint=endpoint, query=common_string)
    assert 'total' in resp
    assert resp['total'] == 4

    assert 'results' in resp
    assert len(resp['results']) == 4
    assert {r['id'] for r in resp['results']} == ids
Beispiel #8
0
def test_not_admin_failure(client, add_user):
    _ = add_user(role=ROLE_USER, log_him_in=True)

    city = add_city()
    _ = client.delete(endpoint=endpoint, city_id=city.id, check_status=403)