Ejemplo n.º 1
0
 def test_image_daemon_error_ret(self):
     imagetickets.uhttp.response = FakeResponse(
         status=300, data=b'{"image_daemon_message":"content"}')
     try:
         imagetickets.remove_ticket("uuid")
     except se.ImageDaemonError as e:
         self.assertTrue("image_daemon_message=content" in e.value)
Ejemplo n.º 2
0
def test_res_header_error(fake_connection):
    fake_response = FakeResponse(status=300)
    fake_response.headers["content-length"] = "invalid"
    fake_connection.response = fake_response

    with pytest.raises(se.ImageDaemonError):
        imagetickets.remove_ticket("uuid")
Ejemplo n.º 3
0
 def test_image_daemon_error_ret(self):
     imagetickets.uhttp.response = FakeResponse(
         status=300, data=b'{"image_daemon_message":"content"}')
     try:
         imagetickets.remove_ticket("uuid")
     except se.ImageDaemonError as e:
         self.assertTrue("image_daemon_message=content" in e.value)
Ejemplo n.º 4
0
 def test_image_daemon_error_ret(self):
     imagetickets.UnixHTTPConnection.response = FakeResponse(
         status=300, data=b'{"image_daemon_message":"content"}')
     try:
         imagetickets.remove_ticket("uuid")
     except se.ImageDaemonError as e:
         self.assertTrue(six.text_type("image_daemon_message") in e.value)
         self.assertTrue(six.text_type("content") in e.value)
Ejemplo n.º 5
0
    def test_remove_ticket(self):
        imagetickets.remove_ticket("uuid")
        expected = [
            ("request", ("DELETE", "/tickets/uuid"), {"body": None}),
        ]

        self.assertEqual(imagetickets.uhttp.__calls__, expected)
        self.assertTrue(imagetickets.uhttp.closed)
Ejemplo n.º 6
0
    def test_remove_ticket(self):
        imagetickets.remove_ticket("uuid")
        expected = [
            ("request", ("DELETE", "/tickets/uuid"), {
                "body": None
            }),
        ]

        self.assertEqual(imagetickets.uhttp.__calls__, expected)
        self.assertTrue(imagetickets.uhttp.closed)
Ejemplo n.º 7
0
def test_remove_ticket(fake_connection):
    fake_connection.response = FakeResponse(status=204, reason="No Content")
    imagetickets.remove_ticket("uuid")
    expected = [
        ("request", ("DELETE", "/tickets/uuid"), {
            "body": None
        }),
    ]

    assert fake_connection.__calls__ == expected
    assert fake_connection.closed
Ejemplo n.º 8
0
    def test_remove_ticket_with_content_length(self):
        # Legacy imageio daemon used to return "Content-Length: 0". This is not
        # correct according to RFC 7230, but we must support it.
        imagetickets.uhttp.response = FakeResponse(
            status=204, reason="No Content")
        imagetickets.remove_ticket("uuid")
        expected = [
            ("request", ("DELETE", "/tickets/uuid"), {"body": None}),
        ]

        self.assertEqual(imagetickets.uhttp.__calls__, expected)
        self.assertTrue(imagetickets.uhttp.closed)
Ejemplo n.º 9
0
    def test_remove_ticket(self):
        # New imageio daemon will not return Content-Length header, as
        # specified in RFC 7230.
        imagetickets.uhttp.response = FakeResponse(
            status=204, reason="No Content", headers={})
        imagetickets.remove_ticket("uuid")
        expected = [
            ("request", ("DELETE", "/tickets/uuid"), {"body": None}),
        ]

        self.assertEqual(imagetickets.uhttp.__calls__, expected)
        self.assertTrue(imagetickets.uhttp.closed)
Ejemplo n.º 10
0
    def test_remove_ticket(self):
        # New imageio daemon will not return Content-Length header, as
        # specified in RFC 7230.
        imagetickets.UnixHTTPConnection.response = FakeResponse(
            status=204, reason="No Content", headers={})
        imagetickets.remove_ticket("uuid")
        expected = [
            ("request", ("DELETE", "/tickets/uuid"), {"body": None}),
        ]

        self.assertEqual(imagetickets.UnixHTTPConnection.__calls__, expected)
        self.assertTrue(imagetickets.UnixHTTPConnection.closed)
Ejemplo n.º 11
0
def test_res_read_error(fake_connection):
    fake_connection.response = FakeResponse(status=300)
    err_msg = "Environment error message"

    def read(amt=None):
        raise EnvironmentError(err_msg)

    fake_connection.response.read = read

    with pytest.raises(se.ImageDaemonError) as e:
        imagetickets.remove_ticket("uuid")
        assert err_msg in e.value
Ejemplo n.º 12
0
    def test_remove_ticket_with_content_length(self):
        # Legacy imageio daemon used to return "Content-Length: 0". This is not
        # correct according to RFC 7230, but we must support it.
        imagetickets.UnixHTTPConnection.response = FakeResponse(
            status=204, reason="No Content")
        imagetickets.remove_ticket("uuid")
        expected = [
            ("request", ("DELETE", "/tickets/uuid"), {"body": None}),
        ]

        self.assertEqual(imagetickets.UnixHTTPConnection.__calls__, expected)
        self.assertTrue(imagetickets.UnixHTTPConnection.closed)
Ejemplo n.º 13
0
    def test_res_read_error(self):
        imagetickets.uhttp.response.status = 300
        err_msg = "Environment error message"

        def read(amt=None):
            raise EnvironmentError(err_msg)

        imagetickets.uhttp.response.read = read

        try:
            imagetickets.remove_ticket("uuid")
        except se.ImageDaemonError as e:
            self.assertTrue(err_msg in e.value)
Ejemplo n.º 14
0
    def test_res_read_error(self):
        imagetickets.uhttp.response.status = 300
        err_msg = "Environment error message"

        def read(amt=None):
            raise EnvironmentError(err_msg)

        imagetickets.uhttp.response.read = read

        try:
            imagetickets.remove_ticket("uuid")
        except se.ImageDaemonError as e:
            self.assertTrue(err_msg in e.value)
Ejemplo n.º 15
0
    def test_res_read_error(self):
        imagetickets.UnixHTTPConnection.response = FakeResponse(
            status=300, data=b'{"image_daemon_message":"ignored"}')
        err_msg = "Environment error message"

        def read(amt=None):
            raise EnvironmentError(err_msg)

        imagetickets.UnixHTTPConnection.response.read = read

        try:
            imagetickets.remove_ticket("uuid")
        except se.ImageDaemonError as e:
            self.assertTrue(err_msg in e.value)
Ejemplo n.º 16
0
    def test_res_read_error(self):
        imagetickets.uhttp.response = FakeResponse(
            status=300, data=b'{"image_daemon_message":"ignored"}')
        err_msg = "Environment error message"

        def read(amt=None):
            raise EnvironmentError(err_msg)

        imagetickets.uhttp.response.read = read

        try:
            imagetickets.remove_ticket("uuid")
        except se.ImageDaemonError as e:
            self.assertTrue(err_msg in e.value)
Ejemplo n.º 17
0
def test_remove_ticket_error(fake_connection):
    fake_connection.response = FakeResponse(status=409, data=b'Conflict')
    with pytest.raises(se.ImageDaemonError) as e:
        imagetickets.remove_ticket("uuid")
    assert "Conflict" in str(e.value)
Ejemplo n.º 18
0
 def test_res_header_error(self):
     imagetickets.UnixHTTPConnection.response = FakeResponse(
         status=300, headers={"content-length": "invalid"})
     with self.assertRaises(se.ImageDaemonError):
         imagetickets.remove_ticket("uuid")
Ejemplo n.º 19
0
 def test_res_invalid_json_ret(self):
     imagetickets.UnixHTTPConnection.response = FakeResponse(
         status=300, data=b"not a json string")
     with self.assertRaises(se.ImageDaemonError):
         imagetickets.remove_ticket("uuid")
Ejemplo n.º 20
0
 def test_res_header_error(self):
     imagetickets.uhttp.response = FakeResponse(
         status=300, headers={"content-length": "invalid"})
     with self.assertRaises(se.ImageDaemonError):
         imagetickets.remove_ticket("uuid")
Ejemplo n.º 21
0
 def test_res_invalid_json_ret(self):
     imagetickets.uhttp.response = FakeResponse(
         status=300, data=b"not a json string")
     with self.assertRaises(se.ImageDaemonError):
         imagetickets.remove_ticket("uuid")