def test_json_policies_api_set_virtual_directory1(self, mock_put): ''' Tests when requests gets a successful response from forum ''' test_name = sys._getframe().f_code.co_name #mock_get.return_value = self.loadMock(test_name) mock_resp = helper._mock_response(test_name=test_name) mock_put.return_value = mock_resp model = VirtualDirectory() # noqa: E501 model.name = test_name model.acl_policy = "" model.description = "" model.enabled = False model.error_template = "" model.listener_policy = "" model.remote_path = "" model.remote_policy = "" model.request_filter_policy = "" model.request_process = "" model.request_process_type = "TASK_LIST" model.response_process = "" model._response_process_type = "TASK_LIST" model.use_remote_policy = False model.virtual_host = "" model.virtual_path = "/bob" created = self._api.set_virtual_directory('bill', 'bob',model) self.assertIsInstance(created, VirtualDirectory) self.assertEqual(created, model) self.assertEqual(created.name, test_name)
def test_json_policies_api_set1(self, mock_put): ''' Tests when requests gets a successful response from forum ''' test_name = sys._getframe().f_code.co_name #mock_get.return_value = self.loadMock(test_name) mock_resp = helper._mock_response(test_name=test_name) mock_put.return_value = mock_resp model = JsonPolicies() # noqa: E501 model.name = test_name model.remote_path = test_name model.listener_policy = test_name model.virtual_path = test_name model.remote_policy = test_name model.description = test_name model.request_process_type = "TASK_LIST" model.response_process_type = "TASK_LIST" model.idp_group = test_name model.request_process = test_name model.response_process = test_name created = self._api.set(test_name, model) self.assertIsInstance(created, JsonPolicies) self.assertEqual(created, model) self.assertEqual(created.name, test_name)
def test_http_remote_policy_api_set1(self, mock_put): ''' Tests when requests gets a successful response from forum ''' test_name = sys._getframe().f_code.co_name #mock_get.return_value = self.loadMock(test_name) mock_resp = helper._mock_response(test_name=test_name) mock_put.return_value = mock_resp model = HttpRemotePolicy() # noqa: E501 model.proxy_policy = "" model.ssl_initiation_policy = "" model.tcp_connection_timeout = 0 model.http_authentication_user_policy = "" model.use_chunking = False model.tcp_read_timeout = 0 model.name = test_name model.enable_ssl = False model.remote_authentication = "NONE" model.remote_port = 0 model.enabled = False model.remote_server = "" model.process_response = False created = self._api.set(test_name, model) self.assertIsInstance(created, HttpRemotePolicy) self.assertEqual(created, model) self.assertEqual(created.name, test_name)
def test_key_pairs_api_get5(self, mock_get): ''' Tests we get an exception if what comes back from the forum was somehow not json ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(test_name=test_name) mock_get.return_value = mock_resp with self.assertRaises(ValueError) as e: key_pair = self._api.get("doesntexit")
def test_documents_api_get2(self, mock_get): ''' Tests when requests gets a 404 response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(status=404,raise_for_status="bill not found") mock_get.return_value = mock_resp taskList = self._api.get("bill") self.assertEqual(taskList, None)
def test_task_list_groups_api_delete1(self, mock_delete): ''' Tests when requests gets a successful response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response() mock_delete.return_value = mock_resp deleted = self._api.delete("bill") self.assertTrue(deleted)
def test_json_policies_api_get2(self, mock_get): ''' Tests when requests gets a 404 response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(status=404,raise_for_status="bill not found") mock_get.return_value = mock_resp jsonPolices = self._api.get("bill") self.assertEqual(jsonPolices, None)
def test_key_pairs_api_get4(self, mock_get): ''' Tests the when requests gets a successful response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(test_name=test_name) mock_get.return_value = mock_resp key_pair = self._api.get("doesntexit") self.assertIsNone(key_pair)
def test_json_policies_api_get_virtual_directory2(self, mock_get): ''' Tests when requests gets a 404 response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(status=404,raise_for_status="bob not found") mock_get.return_value = mock_resp virtual_directory = self._api.get_virtual_directory('bill', 'bob') self.assertEqual(virtual_directory, None)
def test_task_list_groups_api_delete2(self, mock_delete): ''' Tests when requests gets a 404 response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(status=404, raise_for_status="bill not found") mock_delete.return_value = mock_resp deleted = self._api.delete("bill") self.assertTrue(deleted)
def test_http_listener_policy_api_get1(self, mock_get): ''' Tests the when requests gets a successful response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(test_name=test_name) mock_get.return_value = mock_resp httpListenerPolicy = self._api.get("bill") self.assertTrue(isinstance(httpListenerPolicy, HttpListenerPolicy)) self.assertEqual(httpListenerPolicy.name, "bill")
def test_task_list_groups_api_get1(self, mock_get): ''' Tests the when requests gets a successful response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(test_name=test_name) mock_get.return_value = mock_resp taskListGroup = self._api.get(test_name) self.assertIsInstance(taskListGroup, TaskListGroup) self.assertEqual(taskListGroup.name, test_name)
def test_ssl_termination_policy_api_get2(self, mock_get): ''' Tests when requests gets a 404 response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(status=404, raise_for_status="bill not found") mock_get.return_value = mock_resp have_state = self._api.get("bill") self.assertEqual(have_state, None)
def test_ssl_termination_policy_api_get1(self, mock_get): ''' Tests the when requests gets a successful response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(test_name=test_name) mock_get.return_value = mock_resp have_state = self._api.get("bill") self.assertTrue(isinstance(have_state, SslTerminationPolicy)) self.assertEqual(have_state.name, "bill")
def test_http_listener_policy_api_get2(self, mock_get): ''' Tests when requests gets a 404 response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(status=404, raise_for_status="bill not found") mock_get.return_value = mock_resp httpListenerPolicy = self._api.get("bill") self.assertEqual(httpListenerPolicy, None)
def test__request_DELETE(self, mock_delete): ''' Tests _request successful response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(test_name=test_name) mock_delete.return_value = mock_resp resp_text = self._api._request("DELETE", "/test") self.assertEqual(resp_text, "TEST")
def test_json_policies_api_delete_virtual_directory1(self, mock_delete): ''' Tests when requests gets a successful response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response() mock_delete.return_value = mock_resp deleted = self._api.delete_virtual_directory("bill","bob") self.assertTrue(deleted)
def test_json_policies_api_get_virtual_directory1(self, mock_get): ''' Tests the when requests gets a successful response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(test_name=test_name) mock_get.return_value = mock_resp virtual_directory = self._api.get_virtual_directory('bill', 'bob') self.assertTrue(isinstance(virtual_directory, VirtualDirectory)) self.assertEqual(virtual_directory.name, "bob")
def test_json_policies_api_delete_virtual_directory2(self, mock_delete): ''' Tests when requests gets a 404 response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(status=404,raise_for_status="bill not found") mock_delete.return_value = mock_resp deleted = self._api.delete_virtual_directory("bill","bob") self.assertTrue(deleted)
def test_json_policies_api_get1(self, mock_get): ''' Tests the when requests gets a successful response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(test_name=test_name) mock_get.return_value = mock_resp jsonPolices = self._api.get("bill") self.assertTrue(isinstance(jsonPolices, JsonPolicies)) self.assertEqual(jsonPolices.name, "bill")
def test_documents_api_get1(self, mock_get): ''' Tests the when requests gets a successful response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(test_name=test_name) mock_get.return_value = mock_resp document = self._api.get(test_name) self.assertIsInstance(document, Document) self.assertEqual(document.name, test_name)
def test__request_file_download2(self, mock_get): ''' Tests _request_file where the form data isnt a dictionary ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(test_name=test_name) mock_get.return_value = mock_resp with self.assertRaises(InvalidTypeError) as e: downloaded = self._api._request_file("/test","test",form_data="astring",download=True) self.assertIn('object type does not match', e.exception.message)
def test_json_policies_api_get3(self, mock_get): ''' Tests when requests gets a 500 response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(status=500,raise_for_status="internal error") mock_get.return_value = mock_resp with self.assertRaises(ForumHTTPError) as e: jsonPolices = self._api.get("bill") #print e.exception.message self.assertEqual(500, e.exception.cause.response.status_code) self.assertIn('internal error', e.exception.message)
def test_task_list_groups_api_delete3(self, mock_delete): ''' Tests requests gets a 500 response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(status=500, raise_for_status="internal error") mock_delete.return_value = mock_resp with self.assertRaises(ForumHTTPError) as e: deleted = self._api.delete("bill") #print e.exception.message self.assertEqual(500, e.exception.cause.response.status_code) self.assertIn('internal error', e.exception.message)
def test_task_list_groups_api_deploy1(self, mock_post): ''' Tests when requests gets a successful response from forum ''' test_name = sys._getframe().f_code.co_name #mock_get.return_value = self.loadMock(test_name) mock_resp = helper._mock_response(test_name=test_name) mock_post.return_value = mock_resp whereami = os.path.dirname(__file__) filename = '{0}/../mocks/{1}'.format(whereami, test_name) created = self._api.deploy(filename, "password") self.assertTrue(created)
def test_http_remote_policy_api_set2(self, mock_put): ''' Tests when requests gets a 500 response from forum ''' test_name = sys._getframe().f_code.co_name model = HttpRemotePolicy() # noqa: E501 model.name = "bill" mock_resp = helper._mock_response(status=500,raise_for_status="internal error") mock_put.return_value = mock_resp with self.assertRaises(ForumHTTPError) as e: httpRemotePolicy = self._api.set("bill",model) #print e.exception.message self.assertEqual(500, e.exception.cause.response.status_code) self.assertIn('internal error', e.exception.message)
def test_task_list_groups_api_export3(self, mock_post): ''' Tests when requests gets a 500 response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(status=500, raise_for_status="internal error") mock_post.return_value = mock_resp filename = tempfile.mktemp() with self.assertRaises(ForumHTTPError) as e: exported = self._api.export("bill", filename, "bob") self.assertEqual(500, e.exception.cause.response.status_code) self.assertIn('internal error', e.exception.message)
def test_task_list_groups_api_export1(self, mock_post): ''' Tests the when requests gets a successful response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(test_name=test_name) mock_post.return_value = mock_resp filename = tempfile.mktemp() #Cant get this to work via a decorator mo = mock_open() with patch('forumsentry.api.open', mo): exported = self._api.export("bill", filename, "bob") self.assertTrue(exported)
def test__request_file_download1(self, mock_get): ''' Tests _request_file successful response from forum ''' test_name = sys._getframe().f_code.co_name mock_resp = helper._mock_response(test_name=test_name) mock_get.return_value = mock_resp filename = tempfile.mktemp() mo = mock_open() with patch('forumsentry.api.open', mo): downloaded = self._api._request_file("/test",filename,download=True) self.assertTrue(downloaded)
def test_json_policies_api_set_virtual_directory2(self, mock_put): ''' Tests when requests gets a 500 response from forum ''' test_name = sys._getframe().f_code.co_name model = VirtualDirectory() # noqa: E501 model.name = "bill" mock_resp = helper._mock_response(status=500,raise_for_status="internal error") mock_put.return_value = mock_resp with self.assertRaises(ForumHTTPError) as e: created = self._api.set_virtual_directory('bill', 'bob',model) #print e.exception.message self.assertEqual(500, e.exception.cause.response.status_code) self.assertIn('internal error', e.exception.message)