def test_cameraAlertCreated_doggoAlertIgnored(self, print_mock): # setup camera = Camera("Camera1", ["outside", "garage"]) doggo = Doggo("Jake") system = SecuritySystem() system.strategy = EverybodyStrategy() system.registerCreator(camera) system.registerHandler(doggo) camera.detect_movement("lizzard", "outside", datetime(2020, 11, 26, 13, 20)) print_mock.assert_not_called()
def test_cameraAlertCreated_doggoAlertHandled(self, print_mock): # setup camera = Camera("Camera1", ["outside", "garage"]) doggo = Doggo("Jake") system = SecuritySystem() system.strategy = EverybodyStrategy() system.registerCreator(camera) system.registerHandler(doggo) # act camera.detect_movement("human", "outside", datetime(2020, 11, 26, 13, 20)) # assert print_mock.assert_called_once_with("Jake: growl!")
def test_registerCreator_camera_isInCreator(self): #setup camera_mock = Camera("Testcamera", ["outside"]) #act self.security.registerCreator(camera_mock) #assert self.assertIn(camera_mock, self.security.creators) self.assertEqual(camera_mock.security_system, self.security)
def test_cameraAlertCreated_doggoAsSecondHandlerAlertIgnored( self, print_mock): # setup camera = Camera("Camera1", ["outside", "garage"]) doggo = Doggo("Jake") soundalarm = SoundAlarm() system = SecuritySystem() system.strategy = OldestFirstStrategy() system.registerCreator(camera) system.registerHandler(soundalarm) system.registerHandler(doggo) # act camera.detect_movement("human", "outside", datetime(2020, 11, 26, 23, 20)) # assert print_mock.assert_not_called()
def test_cameraAlertCreated_soundAsFirstHandlerAlertHandled( self, bip_mock): # setup camera = Camera("Camera1", ["outside", "garage"]) camera.night_mode = True doggo = Doggo("Jake") soundalarm = SoundAlarm() system = SecuritySystem() system.strategy = OldestFirstStrategy() system.registerCreator(camera) system.registerHandler(soundalarm) system.registerHandler(doggo) # act camera.detect_movement("human", "outside", datetime(2020, 11, 26, 23, 20)) # assert bip_mock.assert_called()
def test_cameraEmailer(self, sendMessage_mock): # setup camera = Camera("Camera1", ["outside", "garage"]) emailer = Emailer("*****@*****.**") emailer.alert_recipient = "*****@*****.**" self.system = SecuritySystem() self.system.strategy = EverybodyStrategy() self.system.registerCreator(camera) self.system.registerHandler(emailer) # act camera.detect_movement("human", "outside", datetime(2020, 11, 26, 13, 20)) # assert sendMessage_mock.assert_called_once_with( "*****@*****.**", "Alert", """You've got an Alert! What: human; Where: outside; Level: 2""", )
class CameraTest(unittest.TestCase): def setUp(self): self.camera = Camera("Camera1", ["backyard", "outside"]) self.connectedCamera = Camera("Camera2", ["backyard", "outside"]) self.system = Mock(name="SecuritySystem") self.connectedCamera.security_system = self.system def test_isConnected_securitySystemNotNone_true(self): # setUp # set up everything you need to run the test self.camera.security_system = self.system self.assertTrue(self.camera.is_connected()) # @patch.object(SecuritySystem, 'createAlert') def test_createAlert_humanOutside2_systemCreateAlert(self): #setup #act self.connectedCamera.create_alert("outside", "human", 2) #assert self.system.createAlert.assert_called_once() @patch.object(Camera, 'create_alert') def test_detectMovement_connected_createAlert(self, create_alert_mock): self.connectedCamera.detect_movement("human", "outside", datetime(2020, 11, 26, 13, 20)) create_alert_mock.assert_called_once_with("outside", "human", 2) @patch.object(Camera, 'create_alert') def test_detectMovement_nightTimeNmodeon_createAlert(self, create_alert_mock): self.connectedCamera.night_mode = True self.connectedCamera.detect_movement("human", "outside", datetime(2020, 11, 26, 23, 20)) create_alert_mock.assert_called_once_with("outside", "human", 3) #@patch.object(Camera, 'detect_movement') @patch('builtins.print') def test_detectMovement_dayTimeNmodeon_standby(self, print_mock): self.connectedCamera.night_mode = True self.connectedCamera.detect_movement("human", "outside", datetime(2020, 11, 26, 13, 20)) print_mock.assert_called_once_with("standing by") def test_detectMovement_unknownLocation_raise(self): with self.assertRaises(Exception): self.connectedCamera.detect_movement("human", "inside", datetime(2020, 11, 26, 13, 20))
def setUp(self): self.camera = Camera("Camera1", ["backyard", "outside"]) self.connectedCamera = Camera("Camera2", ["backyard", "outside"]) self.system = Mock(name="SecuritySystem") self.connectedCamera.security_system = self.system