def test_create_role_duplicate(self): """Makes sure roles can't be created with the same role name.""" create_role('tester') from peewee import IntegrityError with self.assertRaises(IntegrityError): create_role('tester') t = Role.delete().where(Role.role_name == 'test') t.execute()
def test_create_role(self): """Create a role for users.""" create_role('tester') t = Role.select().where(Role.role_name == 'tester') d = Role.delete().where(Role.role_name == 'tester') d.execute() self.assertEqual(str(t), ("<class 'models.Role'> SELECT `t1`.`id`," " `t1`.`role_name` FROM `role` AS t1 " "WHERE (`t1`.`role_name` = %s) ['tester']"))
def test_create_user_no_duplicate(self): """Makes sure users can't have the same username and email.""" Role.create(role_name='tester') create_user('Tester', 'test', '0000000000', 'tester', 'ttest', 'testing', '*****@*****.**') from peewee import IntegrityError with self.assertRaises(IntegrityError): create_user('Tester', 'test', '0000000000', 'tester', 'ttest', 'testing', '*****@*****.**') delete_user = User.delete().where(User.username == 'ttest') delete_user.execute() delete_role = Role.delete().where(Role.role_name == 'tester') delete_role.execute()
def test_create_user(self): """Create an user.""" Role.create(role_name='tester') create_user('Tester', 'test', '0000000000', 'tester', 'ttest', 'testing', '*****@*****.**') user = User.select().where(User.username == 'ttest') delete_user = User.delete().where(User.username == 'ttest') delete_user.execute() delete_role = Role.delete().where(Role.role_name == 'tester') delete_role.execute() self.assertEqual(str(user), ("<class 'models.User'> SELECT `t1`.`id`, `t1`.`first_name`," " `t1`.`second_name`, `t1`.`phone`, `t1`.`role_id`," " `t1`.`username`, `t1`.`password`, `t1`.`email` FROM `user`" " AS t1 WHERE (`t1`.`username` = %s) ['ttest']"))