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': '*****@*****.**'} ]
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()
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()
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
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
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} ]
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
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.']} }
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
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 }] }
def logged_in_user(self, team): user = UserFactory() TeamMembershipFactory(team=team, user=user) return user
def logged_in_user(self, team): return UserFactory(memberships=[ TeamMembershipFactory.build(team=team, is_admin=False) ])
def logged_in_user(self): return UserFactory()
def logged_in_user(self): return UserFactory(password='******')
def logged_in_user(self): return UserFactory(email='*****@*****.**')