示例#1
0
class dsl_test:

    def setup(self):
        self.dsl = Dsl("www.caelum.com.br")

    def should_add_a_processor(self):
        processor = ExecuteRequestProcessor()
        assert self.dsl.use(processor) == self.dsl
        assert self.dsl.processors[0] == processor

    def should_configure_the_content_type(self):
        self.dsl.as_("content")
        assert self.dsl.headers["Content-Type"] == "content"
        
    def should_configure_valid_http_methods(self):
        for verb in Dsl.HTTP_VERBS:
            method = self.dsl.__getattr__(verb)
            assert method.config == self.dsl
            assert self.dsl.verb == verb.upper()
    
    def should_fail_when_asked_to_use_an_invalid_http_method(self):
        try:
            self.dsl.poop
            raise AssertionError("should have failed")
        except AttributeError:
            pass

    def should_configure_the_callback_method(self):
        def callback(*args):
            pass
        
        self.dsl.async(callback)
        assert self.dsl.callback == callback
        
示例#2
0
class dsl_test:
    def setup(self):
        self.dsl = Dsl("www.caelum.com.br")

    def should_add_a_processor(self):
        processor = ExecuteRequestProcessor()
        assert self.dsl.use(processor) == self.dsl
        assert self.dsl.processors[0] == processor

    def should_configure_the_content_type(self):
        self.dsl.as_("content")
        assert self.dsl.headers["Content-Type"] == "content"

    def should_configure_valid_http_methods(self):
        for verb in Dsl.HTTP_VERBS:
            method = self.dsl.__getattr__(verb)
            assert method.config == self.dsl
            assert self.dsl.verb == verb.upper()

    def should_fail_when_asked_to_use_an_invalid_http_method(self):
        try:
            self.dsl.poop
            raise AssertionError("should have failed")
        except AttributeError:
            pass

    def should_configure_the_callback_method(self):
        def callback(*args):
            pass

        self.dsl. async (callback)
        assert self.dsl.callback == callback
示例#3
0
 def setup(self):
     self.dsl = Dsl("www.caelum.com.br")
示例#4
0
class dsl_test:

    def setup(self):
        self.dsl = Dsl("www.caelum.com.br")

    def test_add_a_process_method(self):
        processor = ExecuteRequestProcessor()
        assert self.dsl.use(processor) == self.dsl
        assert self.dsl.processors[0] == processor

    def test_configure_content_type(self):
        self.dsl.as_("content")
        assert self.dsl.headers["Content-Type"] == "content"

    def test_configure_get(self):
        self.dsl.process_flow = method_called(self.dsl)
        self.dsl.get()
        assert self.dsl.verb == "GET"
        assert self.dsl.method_was_called

    def test_configure_delete(self):
        self.dsl.process_flow = method_called(self.dsl)
        self.dsl.delete()
        assert self.dsl.verb == "DELETE"
        assert self.dsl.method_was_called

    def test_configure_head(self):
        self.dsl.process_flow = method_called(self.dsl)
        self.dsl.head()
        assert self.dsl.verb == "HEAD"
        assert self.dsl.method_was_called

    def test_configure_trace(self):
        self.dsl.process_flow = method_called(self.dsl)
        self.dsl.trace()
        assert self.dsl.verb == "TRACE"
        assert self.dsl.method_was_called

    def test_configure_options(self):
        self.dsl.process_flow = method_called(self.dsl)
        self.dsl.options()
        assert self.dsl.verb == "OPTIONS"
        assert self.dsl.method_was_called

    def test_configure_post(self):
        self.dsl.process_flow = method_called(self.dsl)
        self.dsl.post({})
        assert self.dsl.verb == "POST"
        assert self.dsl.method_was_called

    def test_configure_patch(self):
        self.dsl.process_flow = method_called(self.dsl)
        self.dsl.patch({})
        assert self.dsl.verb == "PATCH"
        assert self.dsl.method_was_called

    def test_configure_put(self):
        self.dsl.process_flow = method_called(self.dsl)
        self.dsl.put({})
        assert self.dsl.verb == "PUT"
        assert self.dsl.method_was_called
示例#5
0
 def setup(self):
     self.dsl = Dsl("www.caelum.com.br")
示例#6
0
 def should_configure_simple_auth_if_no_auth_method_is_specified(self):
     dsl = Dsl('http://caelum.com.br').auth('user', 'pass')
     assert dsl.credentials == ('user', 'pass', 'simple')
     assert dsl.uri == "http://caelum.com.br"
示例#7
0
 def should_configure_simple_auth_credentials(self):
     dsl = Dsl('http://caelum.com.br').auth('user', 'pass', 'simple')
     assert dsl.credentials == ('user', 'pass', 'simple')
     assert dsl.uri == "http://caelum.com.br"