예제 #1
0
def test_chef_get_dish(client):
    res = client.get('/dish/1')
    assert res.status_code == 200
    dish = res.json['result']
    assert dish['name'] == 'pizza'
    assert [i['name']
            for i in dish['ingredient']] == ['tomato', 'cheese', 'flour']
예제 #2
0
def test_get_movies(client):  # noqa
    movie_a = MovieDocumentFactory(title=u"quatre garçons plein d'avenir")
    movie_b = MovieDocumentFactory(title=u"les tontons flingueurs")

    resp = client.get("/api/movies/")
    assert resp.status_code == 200

    data = resp.json.get("data")
    assert data == [{"title": movie_b.title}, {"title": movie_a.title}]
예제 #3
0
def test_trips_page_get(client):
    # Assumses that it has a path of "/api/v1.0/trips/"
    test_url = url+'/api/v1.0/trips/'
    rv = client.get(
        test_url,
        content_type='application/json',
    )
    # Assumes that it will return a 404 response
    assert rv.status_code == 405
    # Assumes that it will return error method not allowed
    assert rv.json == {"error": "method not allowed"}
예제 #4
0
def test_nonexits_page_get(client):
    # Assumses that it hasn't got a path of "/"
    test_url = url+'/'
    rv = client.get(
        test_url,
        content_type='application/json',
    )
    # Assumes that it will return a 404 response
    assert rv.status_code == 404
    # Assumes that response is in json format
    assert rv.content_type == 'application/json'
    # Assumes that it will return error not found
    assert rv.json == {'error': 'not found'}
예제 #5
0
def test_admin_list_recipes(client, admin_headers):
    '''Reading recipes with admin token'''
    response = client.get('/recipes', headers=admin_headers)
    assert response.status_code == 200
    assert len(response.json['result']) == 2
예제 #6
0
def test_readonly_list_recipes(client, readonly_headers):
    '''Can read recipes with the read only token'''
    response = client.get('/recipes', headers=readonly_headers)
    assert response.status_code == 200
    assert len(response.json['result']) == 2
예제 #7
0
def test_guest_access(client):
    '''Request without access tokens is denied'''
    response = client.get('/recipes')
    assert response.status_code == 401
def test_non_admin(client):
  assert client.get('/users', headers={'authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJwcm9maWxlIjp7InVzZXJuYW1lIjoiYm9iIiwiZmlyc3ROYW1lIjoiUm9iZXJ0IiwibGFzdE5hbWUiOiJTbWl0aCJ9LCJyb2xlIjoidXNlciJ9.J4uKGkWGQVornTb0UXNgH0qJB-mUiKIWoPwsbpZgrELKiRd_ZTVVcIXu91HHX8YSuFh9Go_Vq2XNxSbJkyur4X_H8Q3GeXoRt6auoeLJ3DezG_VZMyJpuMr7tdQ3c2bnWRS5-mJittfDicNBH0_vf78OV4zGTdtDOJQTHqypDsI'}).data == bytes(json.dumps({'error': 'Authorization header is not for user with necessary permissions.'}), 'utf-8')
def test_malformed_token(client):
  assert client.get('/users', headers={'authorization': 'Bearer aslkfh'}).data == bytes(json.dumps({'error': 'Authorization header malformed.'}), 'utf-8')
def test_admin_permissions(client):
  assert client.get('/users', headers={'authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJwcm9maWxlIjp7InVzZXJuYW1lIjoiZ3JhbmRfbWFndXMiLCJmaXJzdE5hbWUiOiJSZWdpbmFsZCIsImxhc3ROYW1lIjoiTWNGYW5jeXBhbnRzIn0sInJvbGUiOiJhZG1pbmlzdHJhdG9yIn0.ly954u9VOb5ol9BUkUCabLCFWLSVp67AFw6PnZuMYv3PDVxVOxxUVSTxvUt6WI5BV4VEFfIRtduuSIfmrFaUfesypTvuZkXqdlakb8oed9rSLreWPYlMeH8AOXMhAPS5tO0kRQEffY4ef77lGop96RUFiB9csZ_toZmHB3ydRb0'}).data == bytes(user_data, 'utf-8')