def test_enabled(self): """Testing function enabled.""" # Test existing attribute user_ = _insert_random_user() modify = user.Modify(user_.username) # Test modification new = bool(randint(0, 1)) modify.enabled(new) result = user.User(user_.username) self.assertEqual(result.enabled, new)
def test_role(self): """Testing function role.""" # Test existing attribute user_ = _insert_random_user() modify = user.Modify(user_.username) # Test modification new = randint(0, 99) modify.role(new) result = user.User(user_.username) self.assertEqual(result.role, new)
def test_password(self): """Testing function password.""" # Test existing attribute user_ = _insert_random_user() modify = user.Modify(user_.username) # Test modification new = data.hashstring(str(random())) modify.password(new) result = user.User(user_.username) self.assertTrue(result.valid_password(new))
def test_last_name(self): """Testing function last_name.""" # Test existing attribute user_ = _insert_random_user() modify = user.Modify(user_.username) # Test modification new = data.hashstring(str(random())) modify.last_name(new) result = user.User(user_.username) self.assertEqual(result.last_name, new)
def resolve_authenticate(self, info, **kwargs): """Filter by row by User.username and User.password.""" # Initialize key variables result = None # Determine valid password username_ = kwargs.get('username') password_ = kwargs.get('password') user_object = table_user.User(username_) valid = user_object.valid_password(password_) lookup = username_ if bool(valid) is True else '' # Get data and return if bool(valid) is True: with db.db_query(20152, close=False) as session: result = session.query(UserModel).filter( UserModel.username == lookup.encode()) return result
def test___init__(self): """Testing function __init__.""" # Try bad username test = user.User(data.hashstring(str(random()))) self.assertIsNone(test.first_name) self.assertIsNone(test.last_name) self.assertIsNone(test.role) self.assertIsNone(test.password_expired) self.assertIsNone(test.enabled) self.assertFalse(test.exists) # Test all the attributes self.assertEqual(self.result.first_name, self.expected.first_name) self.assertEqual(self.result.last_name, self.expected.last_name) self.assertEqual(self.result.role, self.expected.role) self.assertEqual(self.result.password_expired, bool(self.expected.password_expired)) self.assertEqual(self.result.enabled, bool(self.expected.enabled))
class TestUser(unittest.TestCase): """Checks all functions and methods.""" # Add an entry to the database expected = _random_user() user.insert_row(expected) result = user.User(expected.username) def test___init__(self): """Testing function __init__.""" # Try bad username test = user.User(data.hashstring(str(random()))) self.assertIsNone(test.first_name) self.assertIsNone(test.last_name) self.assertIsNone(test.role) self.assertIsNone(test.password_expired) self.assertIsNone(test.enabled) self.assertFalse(test.exists) # Test all the attributes self.assertEqual( self.result.first_name, self.expected.first_name) self.assertEqual( self.result.last_name, self.expected.last_name) self.assertEqual( self.result.role, self.expected.role) self.assertEqual( self.result.password_expired, bool(self.expected.password_expired)) self.assertEqual( self.result.enabled, bool(self.expected.enabled)) def test_valid_password(self): """Testing function valid_password.""" # Test with a valid password result = self.result.valid_password(self.expected.password) self.assertTrue(result) # Test with an invalid password result = self.result.valid_password(data.hashstring(str(random()))) self.assertFalse(result)