예제 #1
0
 def test_exclude_pk(self):
     # in
     user_row1 = dict2row(self.user_dict, User)
     self.assertIsNotNone(user_row1.role_id)
     # not in
     user_row2 = dict2row(self.user_dict, User, exclude_pk=True)
     self.assertIsNone(user_row2.role_id)
예제 #2
0
 def test_exclude(self):
     # in
     user_row1 = dict2row(self.user_dict, User)
     self.assertIsNotNone(user_row1.username)
     # not in
     user_row2 = dict2row(self.user_dict, User, exclude={'username'})
     self.assertIsNone(user_row2.username)
예제 #3
0
 def test_exclude_underscore(self):
     # in
     user_row1 = dict2row(self.user_dict, User)
     self.assertIsNotNone(user_row1._secret)
     # not in
     user_row2 = dict2row(self.user_dict,
                          User,
                          exclude={'password'},
                          exclude_underscore=True)
     self.assertIsNone(user_row2._secret)
예제 #4
0
 def test_only(self):
     user_row = dict2row(self.user_dict,
                         User,
                         rel={'role': Role},
                         only={'id', 'role'})
     self.assertEqual(user_row.id, self.user_dict['id'])
     self.assertIsNone(user_row.username)
     self.assertIsNone(user_row.password)
     self.assertIsNotNone(user_row.role)
예제 #5
0
 def test_rel(self):
     user_row = dict2row(self.user_dict,
                         User,
                         rel={
                             'role': Role,
                             'permissions': Permission
                         })
     self.assertEqual(len(user_row.role.permissions),
                      len(self.user.role.permissions))
예제 #6
0
 def test_empty(self):
     with self.assertRaises(AttributeError):
         dict2row(self.user_dict, object)
     with self.assertRaises(TypeError):
         dict2row([], User)
예제 #7
0
 def test_fk_suffix(self):
     user_row = dict2row(self.user_dict,
                         User,
                         rel={'role': Role},
                         fk_suffix='x')
     self.assertTrue(hasattr(user_row, 'rolex'))
예제 #8
0
 def test_default(self):
     user_row = dict2row(self.user_dict, User)
     self.assertIsInstance(user_row, User)
     self.assertEqual(user_row.username, self.user.username)
     self.assertEqual(user_row.password, self.user.password)