def test_nosyNeighbor_randomStrategy_alertHandled(self, print_mock,
                                                      bip_mock):
        # set-up
        random.seed(0)
        bed_time = "23:30"
        wake_time = "05:30"
        neighbor = NosyNeighbor("Laco", bed_time, wake_time)
        doggo = Doggo("Jake")
        soundalarm = SoundAlarm()

        system = SecuritySystem()
        system.strategy = RandomStrategy()

        system.registerCreator(neighbor)
        system.registerHandler(doggo)
        system.registerHandler(soundalarm)

        # act
        neighbor.check_suspicious_activity(
            "infront of the door",
            "random visitors",
            datetime(2021, 1, 25, 22, 30, 20),
        )

        # assert
        print_mock.assert_called()
        bip_mock.assert_not_called()
Beispiel #2
0
    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()
Beispiel #3
0
    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!")
Beispiel #4
0
    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()
Beispiel #5
0
    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()
Beispiel #6
0
 def setUp(self):
     self.simple_doggo = Doggo("Jake")
Beispiel #7
0
class DoggoTest(unittest.TestCase):
    def setUp(self):
        self.simple_doggo = Doggo("Jake")

    def test_doggoName_nameSet_returnsName(self):
        self.assertEqual(self.simple_doggo.name, "Jake")

    def test_doggoName_complexNameSet_returnsName(self):
        doggo = Doggo("Mr. Puppet")
        self.assertEqual(doggo.name, "Mr. Puppet")

    def test_doggoName_nameSetEmptyString_raisesError(self):
        with self.assertRaises(ValueError):
            doggo = Doggo("")

    def test_doggoName_nameSetNotAlphabetic_raisesError(self):
        with self.assertRaises(ValueError):
            doggo = Doggo("!!!")

    def test_doggoName_nameChanged_raisesError(self):
        doggo = Doggo("Something in line")
        with self.assertRaises(Exception):
            doggo.name = "Something new"

    def test_sound_soundSet_returnSound(self):
        self.simple_doggo.sound = "bark"
        self.assertEqual(self.simple_doggo.sound, "bark")

    def test_sound_default_exist(self):
        self.assertEqual(self.simple_doggo.sound, "Bark!")

    def test_sound_empty_raisesError(self):
        with self.assertRaises(ValueError):
            self.simple_doggo.sound = ""

    def test_doggoNumLegs_default_greaterThanOrEqual0(self):
        self.assertGreaterEqual(self.simple_doggo.num_legs, 0)

    def test_doggoNumLegs_setLessThan0_raisesError(self):
        with self.assertRaises(ValueError):
            self.simple_doggo.num_legs = -1

    @patch('builtins.print')
    def test_bark_default_prints(self, print_mock):
        self.simple_doggo.bark()
        print_mock.assert_called_once_with("Jake barks: Bark!")

    @patch('builtins.print')
    def test_growl_default_prints(self, print_mock):
        self.simple_doggo.growl()
        print_mock.assert_called_once_with("Jake: growl!")

    @patch.object(Doggo, 'bark')
    def test_handleAlert_insideCat1_bark10times(self, bark_mock):
        alert = Alert("inside", "cat", 1)
        self.simple_doggo.handle_alert(alert)
        self.assertEqual(bark_mock.call_count, 10)

    @patch.object(Doggo, 'bark')
    def test_handleAlert_outsideCat1_bark10times(self, bark_mock):
        #alert = Alert("outside", "cat", 1)

        alert_mock = Mock(name="alert_mock")
        alert_mock.where = "outside"
        alert_mock.what = "cat"
        alert_mock.level = 1

        self.simple_doggo.handle_alert(alert_mock)
        self.assertEqual(bark_mock.call_count, 10)

    @patch.object(Doggo, 'growl')
    def test_handleAlert_outsideHuman1_growl(self, growl_mock):
        # alert = Alert("outside", "human", 1)

        alert_mock = Mock(name="alert_mock")
        alert_mock.where = "outside"
        alert_mock.what = "human"
        alert_mock.level = 1

        self.simple_doggo.handle_alert(alert_mock)
        growl_mock.assert_called_once()

    @patch.object(Doggo, "bark")
    def test_handleAlert_insideHuman1_bark(self, bark_mock):
        alert = Alert("inside", "human", 1)
        self.simple_doggo.handle_alert(alert)
        bark_mock.assert_called_once()

    def test_getSpeed_threeLegs_15(self):
        self.simple_doggo.num_legs = 3
        self.assertEqual(self.simple_doggo.get_speed(), 15)

    @patch('builtins.print')
    @patch.object(Doggo, "get_speed")
    def test_getSpeed_threeLegs_15_alternative(self, print_mock,
                                               getSpeed_mock):
        getSpeed_mock.return_value = 10
        self.simple_doggo.run()
        print_mock.assert_called_once()
Beispiel #8
0
 def test_doggoName_nameChanged_raisesError(self):
     doggo = Doggo("Something in line")
     with self.assertRaises(Exception):
         doggo.name = "Something new"
Beispiel #9
0
 def test_doggoName_nameSetNotAlphabetic_raisesError(self):
     with self.assertRaises(ValueError):
         doggo = Doggo("!!!")
Beispiel #10
0
 def test_doggoName_nameSetEmptyString_raisesError(self):
     with self.assertRaises(ValueError):
         doggo = Doggo("")
Beispiel #11
0
 def test_doggoName_complexNameSet_returnsName(self):
     doggo = Doggo("Mr. Puppet")
     self.assertEqual(doggo.name, "Mr. Puppet")
Beispiel #12
0
 def setUp(self):
     self.doggo = Doggo("Jake")
     self.alert3 = Alert("outside", "human", 3)
     self.alert2 = Alert("outside", "human", 2)
     self.alert1 = Alert("outside", "human", 1)