Exemplo n.º 1
0
def test_custom_json_serializer(session, app):  # noqa
    user, prompt = make_user(), make_prompt()
    composition = make_composition(user=user, prompt=prompt)
    session.add_all([user, prompt, composition])
    session.commit()
    jsonified = jsonify(composition)
    output = json.loads(jsonified.data.decode())
    assert output['created_at'] == composition.created_at.isoformat()
Exemplo n.º 2
0
def test_current_user(db, session):
    user = User(name="sam", institution="UofM")
    entry = Entry(description="desc", template="temp", user=user)
    session.add_all([user, entry])
    session.commit()

    current_users = [user[0] for user in db.session.query(User.name).all()]
    assert user.name in current_users
Exemplo n.º 3
0
def test_many_many_relationship(db, session):
    user = User(name="sam", institution="UofM")
    entry = Entry(description="desc", template="temp", user_saves=user)

    session.add_all([user, entry])
    session.commit()

    assert entry in user.saved_entries
    assert user in entry.user_saves
Exemplo n.º 4
0
def test_created_at(app, db, session):  # noqa
    u = make_user()
    p1 = make_prompt(date=dt.date.today() - dt.timedelta(days=1))
    p2 = make_prompt(date=dt.date.today())
    c1 = make_composition(user=u, prompt=p1)
    c2 = make_composition(user=u, prompt=p2)
    session.add_all([u, p1, p2, c1, c2])
    session.commit()
    assert type(c1.created_at) is dt.datetime
Exemplo n.º 5
0
def test_add_friends_from_fb_ids(app, db, session):  # noqa
    u1, u2, u3, u4, u5 = make_users(5)

    session.add_all([u1, u2, u3, u4, u5])
    session.commit()

    u1.add_friends_from_fb_ids(['fb2', 'fb3', 'fb6'])

    assert set(u1.all_friends) == set([u2, u3])
    assert set(u2.all_friends) == set([u1])
Exemplo n.º 6
0
def test_written_by_friend(session):  # noqa
    u1, u2, u3 = make_users(3)
    p = make_prompt()
    c = make_composition(user=u1, prompt=p)

    session.add_all([u1, u2, u3, p, c])
    session.commit()

    u2.all_friends.append(u1)

    assert u2.written_by_friend(c) is True
    assert u3.written_by_friend(c) is False
Exemplo n.º 7
0
def test_relationship(db, session):
    user = User(name="Sam", institution="UofM")
    entry = Entry(description="Smarty", template="template", user=user)

    print(db.session.execute('show tables').fetchall())
    print(db.session.execute('select * from entries').fetchall())
    print(db.session.execute('select * from test.entries').fetchall())

    session.add_all([user, entry])
    session.commit()

    assert entry in user.submissions
    assert entry.user is user
Exemplo n.º 8
0
def test_views(session):  # noqa
    u1, u2, u3, u4, u5 = make_users(5)
    p = make_prompt()
    c = make_composition(user=u1, prompt=p)

    session.add_all([u1, u2, u3, u4, u5, p, c])
    session.commit()

    u2.views.append(c)
    u4.views.append(c)

    assert set(c.user_views) == set([u2, u4])
    assert u2.viewed(c) is True
    assert u3.viewed(c) is False
Exemplo n.º 9
0
def test_users_who_have_not_written_yet(app, db, session):  # noqa
    user, user2, prompt = make_user(), make_user(), make_prompt()
    session.add_all([user, user2, prompt])
    session.commit()

    assert set([user, user2]) == set(users_who_have_not_written_yet())

    now = datetime.utcnow()
    two_days_ago = now - timedelta(days=2)
    two_minutes_ago = now - timedelta(minutes=2)
    make_composition(user=user, prompt=prompt, created_at=two_days_ago)
    assert set([user, user2]) == set(users_who_have_not_written_yet())

    make_composition(user=user, prompt=prompt, created_at=two_minutes_ago)
    assert set([user2]) == set(users_who_have_not_written_yet())
Exemplo n.º 10
0
def test_existing_user_login(client, session, mocker):  # noqa
    existing, friend_one, friend_two = seed_existing_users()

    session.add_all([existing, friend_one, friend_two])
    session.commit()

    assert existing.all_friends == []

    mocker.patch('requests.get', MockResponse(200, graph_me_with_friends))
    mocker.patch('rr.queries.user_by_fb_id', no_existing_user)
    data = {'timezone': 'US/Pacific', 'access_token': '123'}
    res = client.post(flask.url_for('auth.login'),
                      data=json.dumps(data),
                      headers={'Content-Type': 'application/json'})

    # no new users created
    assert session.query(User).count() == 3

    # fb access token updated
    assert existing.fb_access_token == '123'

    # friends updated
    assert set(existing.friends) == set([friend_one, friend_two])