Exemple #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)
Exemple #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)
    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)
Exemple #4
0
def test_weak_raises_disconnect():
    d = Dummy()
    w = weak(d.spam)
    del d
    gc.collect()

    with assert_raises(instance_of(Disconnect)):
        w()
Exemple #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)
    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))
Exemple #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'
                })
Exemple #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"))
Exemple #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'
                })
Exemple #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"))
    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))
Exemple #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)
Exemple #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))
Exemple #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))
Exemple #15
0
    def test_get_unavailable_key(self):
        key = "test"

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

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

        with assert_raises(TypeError):
            self._order.parse({key: value})
Exemple #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())
Exemple #19
0
def test_define_with_unhashable_raises():
    change = signal('change', 'context')
    with assert_raises(instance_of(TypeError)):
        change([])
Exemple #20
0
    def test_get_unavailable_key(self):
        key = "test"

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

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

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