예제 #1
0
 def test_lazy_overrides_non_lazy_users(self):
     # given
     user = User('user')
     user2 = User('user2')
     # when
     result = Task.from_dict({'users': [user]}, lazy={'users': [user2]})
     # then
     self.assertIsInstance(result, Task)
     self.assertEqual([user2], list(result.users))
예제 #2
0
    def test_constructor_sets_is_admin(self):
        # when
        user = User('*****@*****.**', 'hashed_password', False)
        # then
        self.assertFalse(user.is_admin)

        # when
        user = User('*****@*****.**', 'hashed_password', True)
        # then
        self.assertTrue(user.is_admin)
예제 #3
0
 def test_users_non_empty_yields_same(self):
     # given
     user = User('user')
     # when
     result = Task.from_dict({'users': [user]})
     # then
     self.assertIsInstance(result, Task)
     self.assertEqual([user], list(result.users))
예제 #4
0
 def test_generates_repr_string(self):
     # given
     user = User(email='*****@*****.**')
     user.id = 123
     #when
     r = repr(user)
     # then
     self.assertEqual('User(\'[email protected]\', id=123)', r)
예제 #5
0
파일: layer.py 프로젝트: izrik/tudor
 def create_user(self,
                 email,
                 hashed_password=None,
                 is_admin=False,
                 lazy=None):
     return User(email=email,
                 hashed_password=hashed_password,
                 is_admin=is_admin,
                 lazy=lazy)
예제 #6
0
 def test_generates_str_string(self):
     # given
     user = User(email='*****@*****.**')
     user.id = 123
     #when
     r = str(user)
     # then
     fmt = 'User(\'[email protected]\', user id=123, id=[{}])'
     expected = fmt.format(id(user))
     self.assertEqual(expected, r)
예제 #7
0
 def test_unauthorized_nonadmin_cannot_access_task(self):
     # given
     task = Task('task')
     user = User('*****@*****.**')
     self.pl.add(task)
     self.pl.add(user)
     self.pl.commit()
     # when
     result = TaskUserOps.is_user_authorized_or_admin(task, user)
     # then
     self.assertFalse(result)
예제 #8
0
 def test_unauthorized_admin_can_edit_private_task(self):
     # given
     task = Task('task')
     user = User('*****@*****.**', None, True)
     self.pl.add(task)
     self.pl.add(user)
     self.pl.commit()
     # when
     result = TaskUserOps.user_can_edit_task(task, user)
     # then
     self.assertTrue(result)
예제 #9
0
 def test_unauthorized_nonadmin_cannot_view_private_task(self):
     # given
     task = Task('task')
     user = User('*****@*****.**')
     self.pl.add(task)
     self.pl.add(user)
     self.pl.commit()
     # when
     result = TaskUserOps.user_can_view_task(task, user)
     # then
     self.assertFalse(result)
예제 #10
0
 def test_unauthorized_nonadmin_cannot_edit_public_task(self):
     # given
     task = Task('task', is_public=True)
     user = User('*****@*****.**')
     self.pl.add(task)
     self.pl.add(user)
     self.pl.commit()
     # when
     result = TaskUserOps.user_can_edit_task(task, user)
     # then
     self.assertFalse(result)
예제 #11
0
 def test_authorized_admin_can_edit_public_task(self):
     # given
     task = Task('task', is_public=True)
     user = User('*****@*****.**', None, True)
     self.pl.add(task)
     self.pl.add(user)
     task.users.append(user)
     self.pl.commit()
     # when
     result = TaskUserOps.user_can_edit_task(task, user)
     # then
     self.assertTrue(result)
예제 #12
0
 def test_authorized_admin_can_access_task(self):
     # given
     task = Task('task')
     user = User('*****@*****.**', None, True)
     self.pl.add(task)
     self.pl.add(user)
     task.users.append(user)
     self.pl.commit()
     # when
     result = TaskUserOps.is_user_authorized_or_admin(task, user)
     # then
     self.assertTrue(result)
예제 #13
0
 def test_to_dict_returns_correct_values(self):
     # when
     user = User('*****@*****.**', '12345')
     # then
     self.assertEqual(
         {
             'email': '*****@*****.**',
             'hashed_password': '******',
             'is_admin': False,
             'id': None,
             'tasks': []
         }, user.to_dict())
예제 #14
0
 def test_to_dict_all_fields_returns_correct_values(self):
     # when
     user = User('*****@*****.**', '12345')
     # then
     self.assertEqual(
         {
             'email': '*****@*****.**',
             'hashed_password': '******',
             'is_admin': False,
             'id': None,
             'tasks': []
         },
         user.to_dict({
             user.FIELD_ID, user.FIELD_EMAIL, user.FIELD_HASHED_PASSWORD,
             user.FIELD_IS_ADMIN, user.FIELD_TASKS
         }))
예제 #15
0
 def test_to_dict_field_hashed_password_returns_hashed_password(self):
     # when
     user = User('*****@*****.**', '12345')
     # then
     self.assertEqual({'hashed_password': '******'},
                      user.to_dict({user.FIELD_HASHED_PASSWORD}))
예제 #16
0
 def setUp(self):
     self.task = Task('task')
     self.user = User('user')
예제 #17
0
 def test_to_dict_field_is_admin_returns_is_admin(self):
     # when
     user = User('*****@*****.**', '12345')
     # then
     self.assertEqual({'is_admin': False},
                      user.to_dict({user.FIELD_IS_ADMIN}))
예제 #18
0
 def test_constructor_sets_hashed_password(self):
     # when
     user = User('*****@*****.**', 'hashed_password')
     # then
     self.assertEqual('hashed_password', user.hashed_password)
예제 #19
0
 def test_to_dict_field_email_returns_email(self):
     # when
     user = User('*****@*****.**', '12345')
     # then
     self.assertEqual({'email': '*****@*****.**'},
                      user.to_dict({user.FIELD_EMAIL}))
예제 #20
0
 def test_is_authenticated_always_true(self):
     # when
     user = User('*****@*****.**', 'hashed_password')
     # then
     self.assertTrue(user.is_authenticated)
예제 #21
0
 def test_is_anonymous_always_false(self):
     # when
     user = User('*****@*****.**', 'hashed_password')
     # then
     self.assertFalse(user.is_anonymous)
예제 #22
0
 def test_get_id_gets_email(self):
     # when
     user = User('*****@*****.**', 'hashed_password')
     # then
     self.assertEqual('*****@*****.**', user.get_id())
예제 #23
0
 def test_to_dict_field_id_returns_id(self):
     # when
     user = User('*****@*****.**', '12345')
     # then
     self.assertEqual({'id': None}, user.to_dict({user.FIELD_ID}))
예제 #24
0
 def test_to_dict_field_tasks_returns_tasks(self):
     # when
     user = User('*****@*****.**', '12345')
     # then
     self.assertEqual({'tasks': []}, user.to_dict({user.FIELD_TASKS}))
예제 #25
0
 def test_constructor_default_id_is_none(self):
     # when
     user = User('*****@*****.**', 'hashed_password')
     # then
     self.assertIsNone(user.id)
예제 #26
0
 def test_constructor_default_is_admin_is_false(self):
     # when
     user = User('*****@*****.**', 'hashed_password')
     # then
     self.assertFalse(user.is_admin)