class TestDataBase(unittest.TestCase): def setUp(self): self._db = DataBase(StringIO('testu\tP4ssw0rd\n')) def test_create_user(self): self._db.create_user('username', 'Mypass1234') self.assertEquals(self._db._users['username'].password, 'Mypass1234') def test_succesful_login(self): self.assertEquals(self._db.login('testu', 'P4ssw0rd'), 'Logged In') self.assertEquals(self._db._users['testu'].status, 'Active') def test_invalid_login(self): self.assertEquals(self._db.login('inv', 'alid'), 'Access Denied') self.assertEquals(self._db._users['testu'].status, 'Inactive') def test_change_password_succesfully(self): result = self._db.change_password('testu', 'P4ssw0rd', 'dr0wss4P') self.assertEquals(result, 'SUCCESS') self.assertEquals(self._db._users['testu'].password, 'dr0wss4P') def test_change_password_when_user_does_not_exist(self): result = self._db.change_password('nonexisting', 'P4ssw0r', 'r0wss4P') self.assertEquals(result, 'Changing password failed: Access Denied') def test_change_password_with_wrong_old_password(self): result = self._db.change_password('testu', 'wrong', 'r0wss4P') self.assertEquals(result, 'Changing password failed: Access Denied') def test_change_password_with_invalid_new_password(self): result = self._db.change_password('testu', 'P4ssw0rd', 'short') self.assertEquals( result, 'Changing password failed: Password must ' 'be 7-12 characters long') result = self._db.change_password('testu', 'P4ssw0rd', 'invalid') self.assertEquals( result, 'Changing password failed: Password must be ' 'a combination of lowercase and uppercase ' 'letters and numbers')
class TestDataBase(unittest.TestCase): def setUp(self): self._db = DataBase(StringIO('testu\tP4ssw0rd\n')) def test_create_user(self): self._db.create_user('username', 'Mypass1234') self.assertEquals(self._db._users['username'].password, 'Mypass1234') def test_succesful_login(self): self.assertEquals(self._db.login('testu', 'P4ssw0rd'), 'Logged In') self.assertEquals(self._db._users['testu'].status, 'Active') def test_invalid_login(self): self.assertEquals(self._db.login('inv', 'alid'), 'Access Denied') self.assertEquals(self._db._users['testu'].status, 'Inactive') def test_change_password_succesfully(self): result = self._db.change_password('testu', 'P4ssw0rd', 'dr0wss4P') self.assertEquals(result, 'SUCCESS') self.assertEquals(self._db._users['testu'].password, 'dr0wss4P') def test_change_password_when_user_does_not_exist(self): result = self._db.change_password('nonexisting', 'P4ssw0r', 'r0wss4P') self.assertEquals(result, 'Changing password failed: Access Denied') def test_change_password_with_wrong_old_password(self): result = self._db.change_password('testu', 'wrong', 'r0wss4P') self.assertEquals(result, 'Changing password failed: Access Denied') def test_change_password_with_invalid_new_password(self): result = self._db.change_password('testu', 'P4ssw0rd', 'short') self.assertEquals(result, 'Changing password failed: Password must ' 'be 7-12 characters long') result = self._db.change_password('testu', 'P4ssw0rd', 'invalid') self.assertEquals(result, 'Changing password failed: Password must be ' 'a combination of lowercase and uppercase ' 'letters and numbers')
def setUp(self): self._db = DataBase(StringIO('testu\tP4ssw0rd\n'))