Example #1
0
def test_add_to_branch(client, request, tester_headers):
    res = client.post('/mjs', headers=tester_headers, data='photoUnits.123')
    assert res.status_code == 200
    res = client.post('/mjs/1', headers=tester_headers, data='photoUnits.123')
    assert res.status_code == 200
    assert len(res.json['story_items']) == 1
    item = res.json['story_items'][0]
    assert item['id'] == 'photoUnits.123'
    assert item['in_branch'] == [True, False, False, False]
Example #2
0
def test_add_to_branch(client, request, tester_headers):
    res = client.post('/mjs',
                headers = tester_headers,
                data = 'photoUnits.123')
    assert res.status_code == 200
    res = client.post('/mjs/1', headers=tester_headers,
                     data = 'photoUnits.123')
    assert res.status_code == 200
    assert len(res.json['story_items']) == 1
    item = res.json['story_items'][0]
    assert item['id'] == 'photoUnits.123'
    assert item['in_branch'] == [True, False, False, False]
Example #3
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
Example #4
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
Example #5
0
def test_add_item_to_mjs(client, request, tester_headers):
    res = client.post('/mjs', headers=tester_headers, data='photoUnits.123')
    assert res.status_code == 200
    assert len(res.json['story_items']) == 1
    item = res.json['story_items'][0]
    assert item['id'] == 'photoUnits.123'
    assert res.json['story_branches'] == 4 * ['']
Example #6
0
def test_add_item_to_mjs(client, request, tester_headers):
    res = client.post('/mjs',
                headers = tester_headers,
                data = 'photoUnits.123')
    assert res.status_code == 200
    assert len(res.json['story_items']) == 1
    item = res.json['story_items'][0]
    assert item['id'] == 'photoUnits.123'
    assert res.json['story_branches'] == 4*['']
Example #7
0
def test_bad_next_login(client, app):
    ''' post a login with bad `next` and ensure the user has the default one '''

    mail = app.extensions.get('mail')
    with mail.record_messages() as outbox:
        ticket = client.post('/login',
                             data={'email': '*****@*****.**', 'next': '/login/badwolf'})
        assert len(outbox) == 1
        urls = re.findall('http\S+', outbox[0].body)
    assert len(urls) == 1
    user = app.user_datastore.get_user('*****@*****.**')
    assert user.next == app.config['DEFAULT_NEXT']
    # cleanup
    app.user_datastore.delete_user(user)
Example #8
0
def test_bad_next_login(client, app):
    ''' post a login with bad `next` and ensure the user has the default one '''

    mail = app.extensions.get('mail')
    with mail.record_messages() as outbox:
        ticket = client.post('/login',
                             data={
                                 'email': '*****@*****.**',
                                 'next': '/login/badwolf'
                             })
        assert len(outbox) == 1
        urls = re.findall('http\S+', outbox[0].body)
    assert len(urls) == 1
    user = app.user_datastore.get_user('*****@*****.**')
    assert user.next == app.config['DEFAULT_NEXT']
    # cleanup
    app.user_datastore.delete_user(user)
Example #9
0
def test_illegal_add_to_branch(client, request, tester_headers):
    res = client.post('/mjs/1', headers=tester_headers,
                     data = 'personalities.456')
    assert res.status_code == 400
Example #10
0
def test_mjs_rename_branch(client, tester_headers):
    res = client.post('/mjs/1/name', headers=tester_headers,
                     data = 'mothers')
    assert res.status_code == 200
    assert res.json['story_branches'] == ['mothers', '', '', '']
Example #11
0
def test_illegal_add_to_branch(client, request, tester_headers):
    res = client.post('/mjs/1',
                      headers=tester_headers,
                      data='personalities.456')
    assert res.status_code == 400
Example #12
0
def test_mjs_rename_branch(client, tester_headers):
    res = client.post('/mjs/1/name', headers=tester_headers, data='mothers')
    assert res.status_code == 200
    assert res.json['story_branches'] == ['mothers', '', '', '']