Ejemplo n.º 1
0
    def test_invalid_parameter(self):
        field = 13
        data = 13
        with assert_raises(Exception):
            self._ua.add_field(field, data)

        field = 13
        data = ""
        with assert_raises(Exception):
            self._ua.add_field(field, data)
            str(self._ua)
Ejemplo n.º 2
0
    def test_invalid_parameter(self):
        field = 13
        data = 13
        with assert_raises(Exception):
            self._ua.add_field(field, data)

        field = 13
        data = ""
        with assert_raises(Exception):
            self._ua.add_field(field, data)
            str(self._ua)
Ejemplo n.º 3
0
    def test_apply_post_303_to_503(self):
        redirect = 'http://test2'
        self.http.add_response(status=303, headers={'location': redirect})
        self.http.add_response(status=503, payload='Forbidden')

        with assert_raises(HTTPResponseException):
            self.connector.apply('POST', self.resource)
Ejemplo n.º 4
0
def test_weak_raises_disconnect():
    d = Dummy()
    w = weak(d.spam)
    del d
    gc.collect()

    with assert_raises(instance_of(Disconnect)):
        w()
Ejemplo n.º 5
0
    def test_apply_post_200_invalid_json(self):
        payload = '{"flobadob"}'
        self.http.add_response(
            payload=payload)

        with assert_raises(ValueError):
            self.connector.apply(
                'POST',
                self.resource)
Ejemplo n.º 6
0
    def test_apply_get_301_infinite_loop(self):
        self.http.add_response(status=301, headers={'location': 'http://test'})
        self.http.add_response(status=301, headers={'location': 'http://test'})

        with assert_raises(HTTPResponseException) as ei:
            self.connector.apply('GET', self.resource, {'url': 'http://test'})

        exc = ei.exception
        assert_that(exc.code, equal_to(301))
Ejemplo n.º 7
0
    def test_error_code(self):
        self.http.add_response(status=400)

        with assert_raises(HTTPError):
            self.connector.apply(
                'GET',
                self.resource,
                {
                    'url': 'http://test'
                })
Ejemplo n.º 8
0
    def test_cant_redefine(self):
        with assert_raises(ValueError) as cm:
            self._ua.add_field("OS", {
                "name": "Haiku",
                "version": "1.0-alpha3"
            })

        the_exception = cm.exception
        assert_that(str(the_exception),
                    equal_to("Unable to redefine field OS"))
Ejemplo n.º 9
0
    def test_apply_get_200_invalid_json(self):
        payload = '{"flobadob"}'
        self.http.add_response(payload=payload)

        with assert_raises(ValueError):
            self.connector.apply(
                'GET',
                self.resource,
                {
                    'url': 'http://test'
                })
Ejemplo n.º 10
0
    def test_cant_redefine(self):
        with assert_raises(ValueError) as cm:
            self._ua.add_field(
                "OS",
                {
                    "name": "Haiku",
                    "version": "1.0-alpha3"
                }
            )

        the_exception = cm.exception
        assert_that(str(the_exception), equal_to("Unable to redefine field OS"))
Ejemplo n.º 11
0
    def test_apply_get_301_to_503(self):
        payload = 'Forbidden'
        redirect = 'http://test2/'
        self.http.add_response(status=301, headers={'location': redirect})
        self.http.add_response(status=503, payload=payload)

        with assert_raises(HTTPResponseException) as ei:
            self.connector.apply('GET', self.resource, {'url': 'http://test'})

        exc = ei.exception
        assert_that(exc.code, equal_to(503))
        assert_that(self.resource.location, equal_to(redirect))
Ejemplo n.º 12
0
    def test_apply_post_303_to_503(self):
        redirect = 'http://test2'
        self.http.add_response(
            status=303,
            headers={'location': redirect}
        )
        self.http.add_response(
            status=503,
            payload='Forbidden')

        with assert_raises(HTTPError):
            self.connector.apply(
                'POST',
                self.resource)
Ejemplo n.º 13
0
    def test_apply_get_301_infinite_loop(self):
        self.http.add_response(
            status=301,
            headers={'location': 'http://test'})
        self.http.add_response(
            status=301,
            headers={'location': 'http://test'})

        with assert_raises(HTTPError) as ei:
            self.connector.apply(
                'GET',
                self.resource,
                {
                    'url': 'http://test'
                })

        exc = ei.exception
        assert_that(exc.code, equal_to(301))
Ejemplo n.º 14
0
    def test_apply_get_301_to_503(self):
        payload = 'Forbidden'
        redirect = 'http://test2/'
        self.http.add_response(
            status=301,
            headers={'location': redirect})
        self.http.add_response(
            status=503,
            payload=payload)

        with assert_raises(HTTPError) as ei:
            self.connector.apply(
                'GET',
                self.resource,
                {
                    'url': 'http://test'
                })

        exc = ei.exception
        assert_that(exc.code, equal_to(503))
        assert_that(self.resource.location, equal_to(redirect))
Ejemplo n.º 15
0
    def test_get_unavailable_key(self):
        key = "test"

        with assert_raises(KeyError):
            self._order[key]
Ejemplo n.º 16
0
    def test_get_invalid_key(self):
        key = {"1": "2"}

        with assert_raises(TypeError):
            self._order[key]
Ejemplo n.º 17
0
    def test_set_invalid_key(self):
        key = {"1": "2"}
        value = "testValue"

        with assert_raises(TypeError):
            self._order.parse({key: value})
Ejemplo n.º 18
0
def test_disallows_publish_without_all_parameters():
    change = signal('change', 'attribute', 'type')
    p = change('name')
    with assert_raises(instance_of(TypeError)):
        p(Source())
Ejemplo n.º 19
0
def test_define_with_unhashable_raises():
    change = signal('change', 'context')
    with assert_raises(instance_of(TypeError)):
        change([])
Ejemplo n.º 20
0
    def test_get_unavailable_key(self):
        key = "test"

        with assert_raises(KeyError):
            self._order[key]
Ejemplo n.º 21
0
    def test_get_invalid_key(self):
        key = {"1": "2"}

        with assert_raises(TypeError):
            self._order[key]
Ejemplo n.º 22
0
    def test_set_invalid_key(self):
        key = {"1": "2"}
        value = "testValue"

        with assert_raises(TypeError):
            self._order.parse({key: value})