Ejemplo n.º 1
0
class TestGetURI(unittest.TestCase):
    data = get_test_data()

    def setUp(self):
        self.base_api = BaseAPI()
        self.base_api.set_connection(
            user_name="test_user", password="******", end_point="http://api.test.com", session_verify=False
        )

    def test_get_uri_with_multiple_resaults(self, mock):
        headers = self.data["good-header"]
        response_data = self.data["good-content"]
        self.base_api.set_connection(
            user_name="test", password="******", end_point="http:://test.com", session_verify=False
        )
        mock.get(requests_mock.ANY, json=response_data, headers=headers)

        test = self.base_api.get_uri(search_string="Get/Delete Access Locks", search_spec="test")
        self.assertEquals(test["Get/Delete Access Locks"], "/api/access_lock")
        self.assertEquals(test["Get/Update/Add/Delete User Accounts"], "/api/account")

    def test_get_uri_with_single_resaults(self, mock):
        headers = self.data["good-header"]
        response_data = self.data["get_uri_with_single_resaults"]
        self.base_api.set_connection(
            user_name="test", password="******", end_point="http:://test.com", session_verify=False
        )
        mock.get(requests_mock.ANY, json=response_data, headers=headers)

        test = self.base_api.get_uri(search_string="Get/Delete Access Locks", search_spec="test")
        self.assertEquals(test["Get/Delete Access Locks"], "/api/access_lock")
Ejemplo n.º 2
0
class TestGet(unittest.TestCase):
    data = get_test_data()

    def setUp(self):
        self.base_api = BaseAPI()
        self.base_api.set_connection(
            user_name="test_user", password="******", end_point="http://api.test.com", session_verify=False
        )

    def test__perform_request_returns_requests_object(self, mock):
        headers = self.data["good-header"]
        response_data = self.data["good-content"]
        mock.get(requests_mock.ANY, json=response_data, headers=headers)

        test = self.base_api._perform_request(self.base_api.end_point)

        self.assertIsInstance(test, requests.models.Response)
Ejemplo n.º 3
0
class TestSetConnection(unittest.TestCase):
    data = get_test_data()

    def setUp(self):
        self.base_api = BaseAPI()
        self.base_api.set_connection(
            user_name="test_user", password="******", end_point="http://api.test.com", session_verify=False
        )

    def test_set_connection(self, mock):
        self.assertEqual("test_user", self.base_api.user_name)
        self.assertEqual("test_password", self.base_api.password)
        self.assertEqual("http://api.test.com", self.base_api.end_point)

    def test_set_connection_with_bad_values(self, mock):
        self.assertNotEqual("user", self.base_api.user_name)
        self.assertNotEqual("password", self.base_api.password)
        self.assertNotEqual("http://test.com", self.base_api.end_point)
Ejemplo n.º 4
0
 def setUp(self):
     self.base_api = BaseAPI()
     self.base_api.set_connection(
         user_name="test_user", password="******", end_point="http://api.test.com", session_verify=False
     )