Beispiel #1
0
def test_user_select(db_session):
    assert db_session.query(User).one_or_none() is None

    UserFactory.create_batch(5)
    db_session.commit()

    assert len(db_session.query(User).all()) == 5
Beispiel #2
0
 def test_returns_correct_data(self, client, logged_in_user):
     team = TeamFactory(slug='my-team')
     TeamMembershipFactory(user=logged_in_user, team=team)
     TeamMembershipFactory(
         user=UserFactory(email='*****@*****.**'),
         team=team,
         is_admin=True
     )
     user = UserFactory(email='*****@*****.**')
     TeamMembershipFactory(
         user=user,
         team=team,
         is_admin=False
     )
     TeamMembershipFactory(
         user=user,
         team=TeamFactory(),
         is_admin=True
     )
     TeamMembershipFactory(
         user=UserFactory(),
         team=TeamFactory()
     )
     response = client.get(
         url_for('api.users', team_slug='my-team')
     )
     assert response.status_code == 200
     assert response.json == [
         {'id': 1, 'is_admin': False, 'email': '*****@*****.**'},
         {'id': 2, 'is_admin': True, 'email': '*****@*****.**'},
         {'id': 3, 'is_admin': False, 'email': '*****@*****.**'}
     ]
Beispiel #3
0
def test_user_insert_same_uuid(db_session):
    test_uuid = uuid4()
    with pytest.raises(IntegrityError):
        UserFactory.create(uuid=test_uuid)
        db_session.commit()
        UserFactory.create(uuid=test_uuid)
        db_session.commit()
Beispiel #4
0
def test_user_update_same_provider_user_id(db_session):
    UserFactory.create(provider_user_id="1")
    obj = UserFactory.create(provider_user_id="2")
    db_session.commit()

    with pytest.raises(IntegrityError):
        obj.provider_user_id = "1"
        db_session.commit()
Beispiel #5
0
def test_oauth_insert_same_provider_user_id(db_session):
    with pytest.raises(IntegrityError):
        test_user = UserFactory()
        test_oauth = OAuthFactory.create(provider_user_id="1")
        test_oauth.user = test_user
        db_session.commit()
        test_user_2 = UserFactory()
        test_oauth_2 = OAuthFactory.create(provider_user_id="1")
        test_oauth_2.user = test_user_2
        db_session.commit()
Beispiel #6
0
def test_user_insert_same_uuid(db_session):
    test_uuid = uuid4()

    with pytest.raises(IntegrityError):
        test_user = UserFactory()
        test_oauth = OAuthFactory.create(uuid=test_uuid)
        test_oauth.user = test_user
        db_session.commit()
        test_user_2 = UserFactory()
        test_oauth_2 = OAuthFactory.create(uuid=test_uuid)
        test_oauth_2.user = test_user_2
        db_session.commit()
Beispiel #7
0
def test_user_insert(db_session):
    obj = UserFactory.create()
    db_session.commit()

    assert db_session.query(User).one()
    assert db_session.query(User).filter(User.id == obj.id).one()
    assert db_session.query(User).filter(User.uuid == obj.uuid).one()
Beispiel #8
0
def test_user_service_get_create_oauth(service, db_perm_session):
    assert len(service.db_session.query(User).all()) == 0
    assert len(service.db_session.query(OAuth).all()) == 0

    obj = service.get_create_oauth(provider="google",
                                   provider_user_id="test",
                                   token={})

    assert obj.provider_user_id == "test"
    assert obj.user is None

    test_user = UserFactory.create()
    obj = OAuthFactory.create()
    obj.user = test_user
    db_perm_session.commit()

    assert len(service.db_session.query(User).all()) == 1
    assert len(service.db_session.query(OAuth).all()) == 1

    obj = service.get_create_oauth(
        provider=test_user.oauth.provider,
        provider_user_id=test_user.oauth.provider_user_id,
        token={})

    assert obj.id == test_user.oauth.id
    assert obj.uuid == test_user.oauth.uuid
    assert obj.user == test_user
Beispiel #9
0
def test_user_dict(db_session):
    obj = UserFactory.create()
    db_session.commit()
    obj_dict = obj.to_dict()
    assert len(obj_dict.keys()) == 3
    for key in ["name", "email", "picture"]:
        assert key in obj_dict
Beispiel #10
0
 def test_returns_404_for_team_not_part_of(self, client, logged_in_user):
     team = TeamFactory(slug='not-mine')
     user = UserFactory()
     TeamMembershipFactory(user=user, team=team)
     response = client.delete(url_for(
         'api.remove_user', team_slug='not-mine', user_id=user.id
     ))
     assert response.status_code == 404
Beispiel #11
0
def test_user_insert_oauth(db_session):
    user = UserFactory.create()
    oauth = OAuthFactory.create()
    oauth.user = user
    db_session.commit()

    assert db_session.query(User).one()
    assert db_session.query(OAuth).one()
    assert db_session.query(User).filter(User.oauth == oauth).one()
Beispiel #12
0
 def test_deletes_membership(self, client, logged_in_user):
     team = TeamFactory(slug='mine')
     user = UserFactory()
     TeamMembershipFactory(user=user, team=team)
     TeamMembershipFactory(user=logged_in_user, team=team)
     response = client.delete(url_for(
         'api.remove_user', team_slug='mine', user_id=user.id
     ))
     assert response.status_code == 200
     assert TeamMembership.query.filter_by(user=user).count() == 0
Beispiel #13
0
def test_user_single_parent_constraint(db_session):
    obj = UserFactory.create()
    obj2 = UserFactory.create()

    assert obj.oauth is None
    assert obj2.oauth is None

    test_oauth = OAuthFactory.create()
    obj.oauth = test_oauth
    db_session.commit()

    assert obj.oauth is not None
    assert obj2.oauth is None

    res = obj.oauth
    obj2.oauth = res
    db_session.commit()

    assert obj.oauth is None
    assert obj2.oauth is not None
    assert obj2.oauth == res
Beispiel #14
0
 def test_returns_correct_data(self, client, logged_in_user, data):
     team = TeamFactory(slug='mine')
     UserFactory(email='*****@*****.**')
     TeamMembershipFactory(team=team, user=logged_in_user, is_admin=True)
     response = client.post(
         url_for('api.users_invite', team_slug='mine'),
         data=json.dumps(data),
         content_type='application/json'
     )
     assert response.status_code == 201
     assert response.json == [
         {'is_admin': True, 'email': '*****@*****.**', 'id': 1},
         {'is_admin': False, 'email': '*****@*****.**', 'id': 2}
     ]
Beispiel #15
0
def test_user_delete(db_session):
    obj = UserFactory.create()
    obj.oauth = OAuthFactory.create()
    db_session.commit()

    assert db_session.query(User).one()
    assert db_session.query(OAuth).one()

    result = db_session.query(User).filter(User.id == obj.id).delete()
    assert result == 1
    db_session.commit()

    assert db_session.query(User).one_or_none() is None
    assert db_session.query(OAuth).one_or_none() is None
Beispiel #16
0
 def test_user_from_other_team_cant_delete(self, logged_in_user, client,
                                           team):
     other_team = TeamFactory()
     tab_item = TabItemFactory(
         team=other_team,
         person=PersonFactory(team=other_team),
         adder=UserFactory(
             memberships=[TeamMembershipFactory.build(team=other_team)]),
         added_at=datetime.datetime.now())
     assert TabItem.query.count() == 1
     response = client.delete(
         url_for('api.tab_items_delete',
                 team_slug=other_team.slug,
                 tab_item_id=tab_item.id))
     assert response.status_code == 404
     assert TabItem.query.count() == 1
Beispiel #17
0
 def test_returns_400_when_inviting_already_invited_user(
     self, client, logged_in_user, data
 ):
     data['is_admin'] = False
     team = TeamFactory(slug='mine')
     TeamMembershipFactory(team=team, user=logged_in_user, is_admin=True)
     other_user = UserFactory(email='*****@*****.**')
     TeamMembershipFactory(team=team, user=other_user)
     response = client.post(
         url_for('api.users_invite', team_slug='mine'),
         data=json.dumps(data),
         content_type='application/json'
     )
     assert response.status_code == 400
     assert response.json == {
         'errors': {'email': ['User is already part of the team.']}
     }
Beispiel #18
0
 def test_invites_existing_user(
     self, client, logged_in_user, data
 ):
     data['is_admin'] = True
     team = TeamFactory(slug='mine')
     TeamMembershipFactory(team=team, user=logged_in_user, is_admin=True)
     UserFactory(email='*****@*****.**')
     response = client.post(
         url_for('api.users_invite', team_slug='mine'),
         data=json.dumps(data),
         content_type='application/json'
     )
     assert response.status_code == 201
     user = User.query.filter_by(email='*****@*****.**').one()
     assert user.is_invite is False
     assert user.first_name == 'Pekka'
     assert user.last_name == 'Puupää'
     membership = TeamMembership.query.filter_by(user=user).one()
     assert membership.is_admin is True
Beispiel #19
0
def test_user_update_oauth(db_session):
    user = UserFactory.create()
    db_session.commit()
    assert db_session.query(User).one()
    assert db_session.query(OAuth).one_or_none() is None

    oauth = OAuthFactory.create()
    oauth.user = user
    db_session.commit()
    assert db_session.query(User).one()
    assert db_session.query(OAuth).one()
    assert db_session.query(User).filter(User.oauth == oauth).one()

    result = db_session.query(OAuth).filter(OAuth.id == oauth.id).delete()
    db_session.commit()
    assert result == 1
    assert db_session.query(User).one()
    assert db_session.query(User).one().oauth is None
    assert db_session.query(OAuth).one_or_none() is None
Beispiel #20
0
    def test_doesnt_return_extra_data(self, client, logged_in_user):
        team = TeamFactory(slug='mine')
        TeamMembershipFactory(team=team, user=logged_in_user)
        person = PersonFactory(team=team, name='Jaska Jokunen')

        tab_item = TabItemFactory(team=team,
                                  adder=logged_in_user,
                                  person=person)

        new_team = TeamFactory()
        new_user = UserFactory()
        new_person = PersonFactory(team=new_team)
        TabItemFactory(team=new_team, adder=new_user, person=new_person)

        response = client.get(url_for('api.tab_items', team_slug='mine'))
        assert response.status_code == 200
        assert response.json == {
            'meta': {
                'page': 0,
                'per_page': 50,
                'count': 1
            },
            'data': [{
                'adder': {
                    'name': 'Pekka Puupää',
                    'id': 1
                },
                'price': '2.00',
                'total': '2.00',
                'person': {
                    'name': 'Jaska Jokunen',
                    'id': 1
                },
                'name': 'Beer',
                'added_at': tab_item.added_at.isoformat(),
                'id': 1,
                'amount': 1,
                'can_be_deleted': True
            }]
        }
Beispiel #21
0
 def logged_in_user(self, team):
     user = UserFactory()
     TeamMembershipFactory(team=team, user=user)
     return user
Beispiel #22
0
 def logged_in_user(self, team):
     return UserFactory(memberships=[
         TeamMembershipFactory.build(team=team, is_admin=False)
     ])
Beispiel #23
0
 def logged_in_user(self):
     return UserFactory()
 def logged_in_user(self):
     return UserFactory(password='******')
Beispiel #25
0
def test_user_insert_same_provider_user_id(db_session):
    with pytest.raises(IntegrityError):
        UserFactory.create(provider_user_id="1")
        db_session.commit()
        UserFactory.create(provider_user_id="1")
        db_session.commit()
Beispiel #26
0
 def logged_in_user(self):
     return UserFactory(email='*****@*****.**')