Beispiel #1
0
 def test_GetCount(self):
     # checked IOError exception already so not checking that
     user = User(None, "Name", "123456", "*****@*****.**", "h 43, Delhi", False)
     count = 0
     with mock.patch("FileHandling.readFirstLine") as mockRead, \
             mock.patch("FileHandling.writeFirstLine") as mockWrite:
         mockRead.return_value = count
         self.assertEqual(0, user._getCount())
         mockRead.assert_called_with("users/count")
         mockWrite.assert_called_with("1", "users/count")
         count = count + 1
         mockRead.return_value = count
         self.assertEqual(1, user._getCount())
         mockRead.assert_called_with("users/count")
         mockWrite.assert_called_with("2", "users/count")
Beispiel #2
0
    def test__AddingUser(self):
        user = User(None, "Name", "123456", "*****@*****.**", "h 43, Delhi", False)
        with mock.patch("FileHandling.readFirstLine", side_effect=IOError) as mockRead, \
                mock.patch("FileHandling.writeFirstLine") as mockWrite:
            user.userId = user._getCount()
            self.assertEqual(0, user.userId)
            mockRead.assert_called_once_with("users/count")
            mockWrite.assert_called_once_with("0", "users/count")

        with mock.patch("FileHandling.writeFirstLine") as mockWrite:
            user._writeFirstLine()
            string = "[email protected]====h 43, Delhi====0"
            mockWrite.assert_called_once_with(string, "users/0-Name")