class TestAuthentication(TestCase): def setUp(self): # Create connection to DB self.firebase = firebase_class() # Get database instance self.db = self.firebase.get_db() self.authentication = Authentication(self.firebase, self.db) def test_Authentication(self): # Test 1: Login with valid credentials # fake the input() value by returning the credentials as if they were entered # store the printed console items in the fake_out variable for assertions later with mock.patch('builtins.input', return_value="[email protected] 123456789"), mock.patch( 'sys.stdout', new=StringIO()) as fake_out: self.authentication.login() self.assertTrue("Login Successful!" in fake_out.getvalue().strip()) # Test 2: Exit command with mock.patch('builtins.input', return_value="exit"), mock.patch( 'sys.stdout', new=StringIO()) as fake_out, self.assertRaises(SystemExit): self.authentication.login() self.assertTrue( "Thanks for using SocialPy!" in fake_out.getvalue().strip())
class NFR_PR_8(TestCase): def setUp(self): # Create connection to DB self.firebase = firebase_class() # Get database instance self.db = self.firebase.get_db() self.authentication = Authentication(self.firebase,self.db) def testCommandParser(self): # Test 1: Login with valid credentials with mock.patch('builtins.input', return_value="[email protected] 123456789"): start = time.time() self.authentication.login() self.assertTrue(time.time()-start <= 4)
def setUp(self): # Create connection to DB self.firebase = firebase_class() # Get database instance self.db = self.firebase.get_db() self.authentication = Authentication(self.firebase, self.db)