class WebcamIsUpAndRunningHandlerTestCase(unittest.TestCase):

    def setUp(self):
        self.handler = WebcamIsUpAndRunningHandler("https://...")
        FakeUrllib2.reset()
        self.handler._urllib2 = FakeUrllib2

    def test_run_ok(self):
        FakeUrllib2.expected_action = FakeUrllib2.HTTP_OK
        self.handler.run()

    def test_run_exception_bad_response(self):
        FakeUrllib2.expected_action = FakeUrllib2.HTTP_URL_ERROR
        self.assertRaises(
            LaboratoryErrors.ImageURLDidNotRetrieveAResponseError,
            self.handler.run
        )

    def test_run_exception_bad_content(self):
        FakeUrllib2.expected_action = FakeUrllib2.HTTP_BAD_CONTENT
        self.assertRaises(
            LaboratoryErrors.InvalidContentTypeRetrievedFromImageURLError,
            self.handler.run
        )

    def test_run_times(self):
        messages = self.handler.run_times()
        self.assertEquals([], messages)
        FakeUrllib2.expected_action = FakeUrllib2.HTTP_BAD_CONTENT
        messages = self.handler.run_times()
        self.assertEquals(WebcamIsUpAndRunningHandler.DEFAULT_TIMES, len(messages))
class WebcamIsUpAndRunningHandlerTestCase(unittest.TestCase):
    def setUp(self):
        self.handler = WebcamIsUpAndRunningHandler("https://...")
        FakeUrllib2.reset()
        self.handler._urllib2 = FakeUrllib2

    def test_run_ok(self):
        FakeUrllib2.expected_action = FakeUrllib2.HTTP_OK
        self.handler.run()

    def test_run_exception_bad_response(self):
        FakeUrllib2.expected_action = FakeUrllib2.HTTP_URL_ERROR
        self.assertRaises(
            LaboratoryErrors.ImageURLDidNotRetrieveAResponseError,
            self.handler.run)

    def test_run_exception_bad_content(self):
        FakeUrllib2.expected_action = FakeUrllib2.HTTP_BAD_CONTENT
        self.assertRaises(
            LaboratoryErrors.InvalidContentTypeRetrievedFromImageURLError,
            self.handler.run)

    def test_run_times(self):
        messages = self.handler.run_times()
        self.assertEquals([], messages)
        FakeUrllib2.expected_action = FakeUrllib2.HTTP_BAD_CONTENT
        messages = self.handler.run_times()
        self.assertEquals(WebcamIsUpAndRunningHandler.DEFAULT_TIMES,
                          len(messages))
 def setUp(self):
     self.handler = WebcamIsUpAndRunningHandler("https://...")
     FakeUrllib2.reset()
     self.handler._urllib2 = FakeUrllib2
 def setUp(self):
     self.handler = WebcamIsUpAndRunningHandler("https://...")
     FakeUrllib2.reset()
     self.handler._urllib2 = FakeUrllib2