Esempio n. 1
0
def test_datasets_create():
    """Creating a named and described dataset works."""
    def request_callback(request):
        payload = json.loads(request.body.decode())
        resp_body = {
            'owner': username,
            'id': 'new',
            'name': payload['name'],
            'description': payload['description'],
            'created': '2015-09-19',
            'modified': '2015-09-19'
        }
        headers = {}
        return (200, headers, json.dumps(resp_body))

    responses.add_callback(
        responses.POST,
        'https://api.mapbox.com/datasets/v1/{0}?access_token={1}'.format(
            username, access_token),
        match_querystring=True,
        callback=request_callback)

    response = Datasets(access_token=access_token).create(
        name='things', description='a collection of things')
    assert response.status_code == 200
    assert response.json()['name'] == 'things'
    assert response.json()['description'] == 'a collection of things'
Esempio n. 2
0
def test_datasets_create():
    """Creating a named and described dataset works."""

    def request_callback(request):
        payload = json.loads(request.body.decode())
        resp_body = {
            'owner': username,
            'id': 'new',
            'name': payload['name'],
            'description': payload['description'],
            'created': '2015-09-19',
            'modified': '2015-09-19'}
        headers = {}
        return (200, headers, json.dumps(resp_body))

    responses.add_callback(
        responses.POST,
        'https://api.mapbox.com/datasets/v1/{0}?access_token={1}'.format(
            username, access_token),
        match_querystring=True,
        callback=request_callback)

    response = Datasets(access_token=access_token).create(
        name='things', description='a collection of things')
    assert response.status_code == 200
    assert response.json()['name'] == 'things'
    assert response.json()['description'] == 'a collection of things'
Esempio n. 3
0
def test_datasets_list():
    """Listing datasets works"""

    body = '''
[
  {
    "owner": "testuser",
    "id": "ds1",
    "created": "2015-09-19",
    "modified": "2015-09-19"
  },
  {
    "owner": "testuser",
    "id": "ds2",
    "created": "2015-09-19",
    "modified": "2015-09-19"
  }
]
'''

    responses.add(
        responses.GET,
        'https://api.mapbox.com/datasets/v1/{0}?access_token={1}'.format(
            username, access_token),
        match_querystring=True,
        body=body,
        status=200,
        content_type='application/json')

    response = Datasets(access_token=access_token).list()
    assert response.status_code == 200
    assert [item['id'] for item in response.json()] == ['ds1', 'ds2']
Esempio n. 4
0
def test_datasets_list():
    """Listing datasets works"""

    body = '''
[
  {
    "owner": "testuser",
    "id": "ds1",
    "created": "2015-09-19",
    "modified": "2015-09-19"
  },
  {
    "owner": "testuser",
    "id": "ds2",
    "created": "2015-09-19",
    "modified": "2015-09-19"
  }
]
'''

    responses.add(
        responses.GET,
        'https://api.mapbox.com/datasets/v1/{0}?access_token={1}'.format(
            username, access_token),
        match_querystring=True,
        body=body, status=200,
        content_type='application/json')

    response = Datasets(access_token=access_token).list()
    assert response.status_code == 200
    assert [item['id'] for item in response.json()] == ['ds1', 'ds2']
Esempio n. 5
0
def test_read_feature():
    """Feature read works."""

    responses.add(
        responses.GET,
        'https://api.mapbox.com/datasets/v1/{0}/{1}/features/{2}?access_token={3}'.format(
            username, 'test', '1', access_token),
        match_querystring=True,
        body=json.dumps({'type': 'Feature', 'id': '1'}),
        status=200,
        content_type='application/json')

    response = Datasets(access_token=access_token).read_feature('test', '1')
    assert response.status_code == 200
    assert response.json()['type'] == 'Feature'
    assert response.json()['id'] == '1'
Esempio n. 6
0
def test_read_feature():
    """Feature read works."""

    responses.add(
        responses.GET,
        'https://api.mapbox.com/datasets/v1/{0}/{1}/features/{2}?access_token={3}'.format(
            username, 'test', '1', access_token),
        match_querystring=True,
        body=json.dumps({'type': 'Feature', 'id': '1'}),
        status=200,
        content_type='application/json')

    response = Datasets(access_token=access_token).read_feature('test', '1')
    assert response.status_code == 200
    assert response.json()['type'] == 'Feature'
    assert response.json()['id'] == '1'
Esempio n. 7
0
def test_dataset_read():
    """Dataset name and description reading works."""

    responses.add(
        responses.GET,
        'https://api.mapbox.com/datasets/v1/{0}/{1}?access_token={2}'.format(
            username, 'test', access_token),
        match_querystring=True,
        body=json.dumps(
            {'name': 'things', 'description': 'a collection of things'}),
        status=200,
        content_type='application/json')

    response = Datasets(access_token=access_token).read_dataset('test')
    assert response.status_code == 200
    assert response.json()['name'] == 'things'
    assert response.json()['description'] == 'a collection of things'
Esempio n. 8
0
def test_dataset_read():
    """Dataset name and description reading works."""

    responses.add(
        responses.GET,
        'https://api.mapbox.com/datasets/v1/{0}/{1}?access_token={2}'.format(
            username, 'test', access_token),
        match_querystring=True,
        body=json.dumps(
            {'name': 'things', 'description': 'a collection of things'}),
        status=200,
        content_type='application/json')

    response = Datasets(access_token=access_token).read_dataset('test')
    assert response.status_code == 200
    assert response.json()['name'] == 'things'
    assert response.json()['description'] == 'a collection of things'
Esempio n. 9
0
def test_dataset_list_features():
    """Features retrieval work"""

    responses.add(
        responses.GET,
        'https://api.mapbox.com/datasets/v1/{0}/{1}/features?access_token={2}'.
        format(username, 'test', access_token),
        match_querystring=True,
        body=json.dumps({'type': 'FeatureCollection'}),
        status=200,
        content_type='application/json')

    response = Datasets(access_token=access_token).list_features('test')
    assert response.status_code == 200
    assert response.json()['type'] == 'FeatureCollection'
Esempio n. 10
0
def test_dataset_list_features():
    """Features retrieval work"""

    responses.add(
        responses.GET,
        'https://api.mapbox.com/datasets/v1/{0}/{1}/features?access_token={2}'.format(
            username, 'test', access_token),
        match_querystring=True,
        body=json.dumps({'type': 'FeatureCollection'}),
        status=200,
        content_type='application/json')

    response = Datasets(access_token=access_token).list_features('test')
    assert response.status_code == 200
    assert response.json()['type'] == 'FeatureCollection'