class AdminTest(Test): def setUp(self): Test.setUp(self) self.user = User(username="******", password="******") self.user.add() self.view = View(view_name="Test View") self.view.add()
def create_admin_user(): from EnGo.models.permission import Permission from EnGo.models.user import User admin_permission = Permission(permission_name="Admin") admin_permission.add() admin_user = User(username="******", password=generate_password_hash('0000')) admin_user.add() admin_user.add_permission(admin_permission)
class TestGetAll(UserTest): def setUp(self): UserTest.setUp(self) self.user2 = User(username="******", password="******") self.user2.add() def test_should_return_list_of_all_users(self): users = User.get_all() self.assertEqual(users, [self.user, self.user2])
def create_dev_user(): from EnGo.models.permission import Permission from EnGo.models.user import User dev_permission = Permission.search("Dev") if not dev_permission: dev_permission = Permission(permission_name="Dev") dev_permission.add() dev_user = User(username="******", password=generate_password_hash('0000')) dev_user.add() dev_user.add_permission(dev_permission)
class TestCommitToDb(Test): def setUp(self): Test.setUp(self) self.user = User(username="******", password="******") self.user.add() def test_should_save_changes_made_to_user(self): self.user.username = "******" commit_to_db() self.db.session.rollback() self.assertEqual(self.user.username, "New Name")
class OrderTest(Test): def setUp(self): Test.setUp(self) self.user = User( username="******", password="******" ) self.user.add() self.order = Order( user_id=self.user.id, title="Test Title", description="Test Description", due_date=date.today() ) self.order.add()
class UserPermissionTest(UserTest): def setUp(self): UserTest.setUp(self) self.admin_permission = Permission(permission_name="Admin") self.admin_permission.add() self.admin_view = View(view_name="Admin View") self.admin_view.add() self.admin_view.add_permission(self.admin_permission) self.admin_user = User(username="******", password="******") self.admin_user.add() self.admin_user.add_permission(self.admin_permission) self.quality_permission = Permission(permission_name="quality") self.quality_permission.add() self.quality_view = View(view_name="Quality View") self.quality_view.add() self.quality_view.add_permission(self.quality_permission) self.normal_user = User(username="******", password="******") self.normal_user.add()
class UserTest(Test): def setUp(self): Test.setUp(self) self.user = User(username="******", password="******") self.user.add()
def test_shoul_add_permission_to_user(self): user = User(username="******", password="******") user.add() user.add_permission(self.quality_permission) self.assertIn(self.quality_permission, user.permissions)
def test_should_add_user(self): user = User(username="******", password="******") user.add() self.assertIn(user, self.db.session)