Esempio n. 1
0
class test_Rest_API(Test_Helper):

    def setUp(self):
        self.name = 'temp-unit-test-api'
        super().setUp()
        self.rest_api = Rest_API(self.name)

    def test_add_method_http(self):
        from_path   =  '/'
        from_method = 'GET'
        to_method   = 'GET'
        to_uri      = 'http://httpbin.org/robots.txt'
        self.rest_api.add_method_http(from_path, from_method, to_method, to_uri)
        self.result = self.rest_api.test_method(from_path, from_method)

    def test_create(self):
        self.result = self.rest_api.create()

    def test_id(self):
        self.result = self.rest_api.id()

    def test_exists(self):
        self.result = self.rest_api.exists()

    #def test_resource(self):
    #

    def test_resource_id(self):
        self.result = self.rest_api.resource_id('/')
Esempio n. 2
0
class test_Rest_API(Test_Helper):

    test_rest_api_name = 'temp-unit-test-api'

    @staticmethod
    def setup_test_enviroment__Rest_API(
            cls):  # todo: refactor into separate class
        rest_api = Rest_API(cls.test_rest_api_name)
        rest_api.create()

    @staticmethod
    def teardown_test_enviroment__Rest_API(cls):
        rest_api = Rest_API(cls.test_rest_api_name)
        assert rest_api.delete().not_exists()

    @classmethod
    def setUpClass(cls) -> None:
        cls.setup_test_enviroment__Rest_API(cls)

    @classmethod
    def tearDownClass(cls):
        cls.teardown_test_enviroment__Rest_API(cls)

    def setUp(self):
        super().setUp()
        self.rest_api = Rest_API(self.test_rest_api_name)

    def test__init__(self):
        assert self.rest_api.api_name == self.test_rest_api_name
        assert self.rest_api.api_id is None

    def test_add_method_http(self):
        from_path = '/'
        from_method = 'GET'
        to_method = 'GET'
        to_uri = 'http://httpbin.org/robots.txt'
        self.rest_api.add_method_http(from_path, from_method, to_method,
                                      to_uri)
        assert len(
            self.rest_api.test_method(from_path, from_method).get('log')) > 0

    def test_create(self):
        current_id = self.rest_api.id()
        self.rest_api.create(
        )  # note: calling create on a method that already exists will not do anything
        assert self.rest_api.api_id == current_id  # confirm value is set

    def test_id(self):
        assert self.rest_api.id() == self.rest_api.api_id

    def test_exists(self):
        assert self.rest_api.exists() is True

    #def test_resource(self):
    #

    def test_resource_id(self):
        self.rest_api.resource_id('/') == self.rest_api.api_id