Ejemplo n.º 1
0
    def setUp(self):
        db.session.close()
        db.drop_all()
        db.create_all()

        User.query.delete()
        UserSettings.query.delete()

        add_user('marcel', '1234')
Ejemplo n.º 2
0
    def test_all_user_asc(self):
        """
        Tests all users are returned in ascending order.
        """
        add_user('super_user', 'a')
        add_user('another_user', 'a')

        all_users = User.query.order_by(User.username.asc()).all()
        users = [[user.id, user.username] for user in all_users]
        self.assertListEqual(users, User.all_user_asc())
Ejemplo n.º 3
0
 def test_share_all_permission(self):
     """
     Tests the getter of all sharing permission.
     """
     user = add_user('user', '123')
     other_user = add_user('other', '123')
     user.share_all_with(other_user)
     self.assertTrue(
         user.has_general_read_permission(other_user),
         msg=f'{other_user} has no permission to view photos of {user}')
Ejemplo n.º 4
0
    def test_duplicate_user(self):
        """
        Tests that a user can be added only once.
        """
        with self.client:
            self.assertNotIn('lea',
                             [user.username for user in User.query.all()])

            add_user('lea', '12345')
            add_user('lea', '12345')
            self.assertEqual(1, [user.username
                                 for user in User.query.all()].count('lea'))
Ejemplo n.º 5
0
    def test_user_is_allowed_to_view_sharing(self):
        """
        Tests if getter of permissions works correctly.
        """
        other_user = add_user('test', '123')
        lea = add_user('lea', '1234')

        self.user.share_all_with([other_user, lea])
        settings = UserSettings.query.filter_by(user_id=self.user.id).first()
        self.assertTrue(settings.has_all_sharing(other_user),
                        msg=f'{other_user} is not in '
                        f'{settings.share_all}')
Ejemplo n.º 6
0
    def test_add_multiple_users_to_sharing(self):
        """
        Tests sharing photos with multiple users.
        """
        first_user = add_user('first', '5678')
        second_user = add_user('second', '9876')
        user_list = [first_user, second_user]

        self.user.share_all_with(user_list)
        settings = UserSettings.query.get(self.user.id)

        self.assertListEqual(user_list, settings.share_all)
Ejemplo n.º 7
0
    def test_add_user(self):
        """
        Tests if a new user can be added.
        """
        with self.client:
            if 'lea' in [user.username for user in User.query.all()]:
                lea = User.query.filter_by(username='******').first()
                db.session.delete(lea)
                db.session.commit()
            self.assertNotIn('lea',
                             [user.username for user in User.query.all()])

            add_user('lea', '12345')
            self.assertIn('lea', [user.username for user in User.query.all()])
Ejemplo n.º 8
0
 def setUp(self):
     super().setUp()
     self.patcher = patch('flask_login.utils._get_user')
     self.mock_current_user = self.patcher.start()
     user = add_user('marcel', '1234')
     self.mock_current_user.return_value = user
     self.mock_current_user.id = user.id
Ejemplo n.º 9
0
 def test_unshare(self):
     """
     Tests if user can revoke sharing.
     """
     other_user = add_user('other_user', '1234')
     self.user.share_all_with(other_user)
     self.user.share_all_with([])
     self.assertNotIn(other_user, self.user.settings.share_all)
Ejemplo n.º 10
0
 def test_shared_individual_photo(self):
     """
     Tests sharing an individual photo with another user.
     """
     db.session.add(self.photo)
     db.session.commit()
     other_user = add_user('other', 'user')
     response = self.client.post('/image/example.jpg', data=dict(share_with=[other_user.id]))
     self.assertEqual(status.HTTP_200_OK, response.status_code)
Ejemplo n.º 11
0
 def test_add_user_to_sharing(self):
     """
     Tests if the share with does work correctly.
     """
     other_user = add_user('lea', '1234')
     self.user.share_all_with(other_user)
     db.session.commit()
     settings = UserSettings.query.get(self.user.id)
     self.assertListEqual([other_user], settings.share_all)
Ejemplo n.º 12
0
 def test_request_sharing_with(self):
     """
     The post part of sharing photos of the settings route.
     """
     other_user = add_user('share_with_user', '123')
     print(f'{other_user.id}')
     response = self.client.post('/settings',
                                 data=dict(share_with=[other_user.id]))
     self.assertEqual(status.HTTP_200_OK, response.status_code)
Ejemplo n.º 13
0
 def test_show_shared(self):
     """
     Tests if an user can see photos that others shared with him/her/it.
     """
     other_user = add_user('sharer', 'sharing')
     other_photo = Photo(filename='other-photo.jpg', user=other_user.id)
     db.session.add(other_photo)
     db.session.commit()
     other_user.share_all_with(current_user)
     photos = current_user.get_media()
     self.assertIn(other_photo, photos)
Ejemplo n.º 14
0
 def test_only_show_allowed_photos(self):
     """
     Tests if the user can only see photos he/she/it has permission to view.
     """
     owner = add_user('owner', '123')
     other_photo = Photo(filename='example.jpg', url='/photos/example.jpg',
                         user=owner.id)
     db.session.add(other_photo)
     db.session.commit()
     response = self.client.get('/image/example.jpg')
     self.assertEqual(status.HTTP_401_UNAUTHORIZED, response.status_code)
Ejemplo n.º 15
0
 def test_sharing_via_individual_multiple(self):
     """
     Tests sharing for an individual photo with multiple users.
     """
     third_user = add_user('third', '3')
     self.photo.share_with([self.other_user, third_user])
     self.assertTrue(
         self.photo.has_read_permission(self.other_user),
         msg=
         f'{self.other_user} has no permission for this photo by {self.user}.'
     )
     self.assertTrue(
         self.photo.has_read_permission(third_user),
         msg=f'{third_user} has no permission for this photo by {self.user}.'
     )
Ejemplo n.º 16
0
 def setUp(self):
     super().setUp()
     self.user = add_user('settings_user', 'settings')
Ejemplo n.º 17
0
 def setUp(self):
     super().setUp()
     self.user = add_user('marcel', '123')
     self.other_user = add_user('lea', '654')
     self.photo.user = self.user.id