Exemplo n.º 1
0
def test_login_scenario(client, app):
    ''' login scenario, starting with sending the ticket '''

    mail = app.extensions.get('mail')
    with mail.record_messages() as outbox:
        ticket = client.post('/login',
                             data={'email': '*****@*****.**', 'next': '/mjs'})
        assert len(outbox) == 1
        urls = re.findall('http\S+', outbox[0].body)
    assert len(urls) == 1
    login_url = urls[0]
    res = client.get(login_url, headers={'Accept': 'application/json'})
    assert res.status_code == 200
    assert res.json['meta']['code'] == 200
    # test the token we got
    token = res.json['response']['user']['authentication_token']
    res = client.get('/', headers={'Authentication-Token': token})
    assert "private" in res.data
    # now get the user
    res = client.get('/user', headers={'Authentication-Token': token,
                                       'Referer': login_url})
    assert res.status_code == 200
    assert res.json['email'] == '*****@*****.**'
    hash = res.json['hash']
    assert hash == hashlib.md5('*****@*****.**').hexdigest()
    # now let's get the public stroy
    res = client.get('/v1/story/'+hash)
    assert res.status_code == 200
    assert res.json['hash'] == hash
Exemplo n.º 2
0
def test_login_scenario(client, app):
    ''' login scenario, starting with sending the ticket '''

    mail = app.extensions.get('mail')
    with mail.record_messages() as outbox:
        ticket = client.post('/login',
                             data={
                                 'email': '*****@*****.**',
                                 'next': '/mjs'
                             })
        assert len(outbox) == 1
        urls = re.findall('http\S+', outbox[0].body)
    assert len(urls) == 1
    res = client.get(urls[0], headers={'Accept': 'application/json'})
    assert res.status_code == 200
    assert res.json['meta']['code'] == 200
    token = res.json['response']['user']['authentication_token']
    res = client.get('/', headers={'Authentication-Token': token})
    assert "private" in res.data
    # now get the user
    res = client.get('/user', headers={'Authentication-Token': token})
    assert res.status_code == 200
    assert res.json['email'] == '*****@*****.**'
    hash = res.json['hash']
    assert hash == hashlib.md5('*****@*****.**').hexdigest()
    # now let's get the public stroy
    res = client.get('/v1/story/' + hash)
    assert res.status_code == 200
    assert res.json['hash'] == hash
Exemplo n.º 3
0
def test_get_geo_places_bad_param_key(client, app):
    app.data_db['places'].insert(places_tester)

    url = '/v1/geo/places'
    parameters = {
        'ne_lat': '51.41976382669737',
        'bad_key': '12.579345703125002',
        'sw_lat': '48.31973404047173',
        'sw_lng': '9.195556640625002'
    }
    parameters = urllib.urlencode(parameters)
    ful_url = url + '?' + parameters
    with app.app_context():
        res = client.get(ful_url)
    assert res.status_code == 400
Exemplo n.º 4
0
def test_get_geo_places_bad_param_key(client, app):
    app.data_db['places'].insert(places_tester)

    url = '/v1/geo/places'
    parameters = {
        'ne_lat': '51.41976382669737',
        'bad_key': '12.579345703125002',
        'sw_lat': '48.31973404047173',
        'sw_lng': '9.195556640625002'
    }
    parameters = urllib.urlencode(parameters)
    ful_url = url + '?' + parameters
    with app.app_context():
        res = client.get(ful_url)
    assert res.status_code == 400
Exemplo n.º 5
0
def test_get_geo_places(client, app):
    app.data_db['places'].insert(places_tester)

    url = '/v1/geo/places'
    parameters = {
        'ne_lat': '51.41976382669737',
        'ne_lng': '12.579345703125002',
        'sw_lat': '48.31973404047173',
        'sw_lng': '9.195556640625002'
    }
    parameters = urllib.urlencode(parameters)
    ful_url = url + '?' + parameters
    with app.app_context():
        res = client.get(ful_url)
    assert res.status_code == 200
    assert len(res.json) == 1
    assert res.json[0]['Header']['En'] == 'test_place'
Exemplo n.º 6
0
def test_get_geo_places(client, app):
    app.data_db['places'].insert(places_tester)

    url = '/v1/geo/places'
    parameters = {
        'ne_lat': '51.41976382669737',
        'ne_lng': '12.579345703125002',
        'sw_lat': '48.31973404047173',
        'sw_lng': '9.195556640625002'
    }
    parameters = urllib.urlencode(parameters)
    ful_url = url + '?' + parameters
    with app.app_context():
        res = client.get(ful_url)
    assert res.status_code == 200
    assert len(res.json) == 1
    assert res.json[0]['Header']['En'] == 'test_place'
Exemplo n.º 7
0
def test_fsearch_api(client):
    res = client.get('/v1/person?last_name=Douani')
    assert 'items' in res.json
    assert int(res.json['total']) > 5
Exemplo n.º 8
0
def test_public_story(app, client, tester):
    res = client.get('/v1/story/'+str(tester.hash))
    assert res.status_code == 200
    assert 'story_items' in res.json
    assert 'name' in res.json
    assert len(res.json['story_branches']) == 4
Exemplo n.º 9
0
def test_mjs_in_user_data(client, request, tester_headers):
    res = client.get('/user',
                     headers=tester_headers)
    assert 'story_items' in res.json
    assert len(res.json['story_branches']) == 4
Exemplo n.º 10
0
def test_dummy_token(client):
    res = client.get('/', headers={'Authentication-Token': 'dfdfdfdf'})
    assert "public" in res.data
Exemplo n.º 11
0
def test_api_public_view(client):
    res = client.get('/')
    assert res.json == {'access': 'public'}
Exemplo n.º 12
0
def test_dummy_token(client):
    res = client.get('/', headers={'Authentication-Token': 'dfdfdfdf'})
    assert "public" in res.data
Exemplo n.º 13
0
def test_api_public_view(client):
    res = client.get('/')
    assert res.json == {'access': 'public'}
Exemplo n.º 14
0
def test_public_story(app, client, tester):
    res = client.get('/v1/story/' + str(tester.hash))
    assert res.status_code == 200
    assert 'story_items' in res.json
    assert 'name' in res.json
    assert len(res.json['story_branches']) == 4
Exemplo n.º 15
0
def test_mjs_in_user_data(client, request, tester_headers):
    res = client.get('/user', headers=tester_headers)
    assert 'story_items' in res.json
    assert len(res.json['story_branches']) == 4