import pytest import json import os import sys import time from testsuite_utils import MockServer from response_templates import response_template_to_json try: # python 2 from BaseHTTPServer import BaseHTTPRequestHandler except ImportError: # python 3 from http.server import BaseHTTPRequestHandler from agavepy.agave import Agave # Sample successful responses from the agave api. sample_files_history_response = response_template_to_json("files-history.json") class MockServerListingsEndpoints(BaseHTTPRequestHandler): """ Mock the Agave API """ def do_GET(self): # Check that basic auth is used. authorization = self.headers.get("Authorization") if authorization == "" or authorization is None: self.send_response(400) self.end_headers() return self.send_response(200)
import sys import tempfile from response_templates import response_template_to_json try: from unittest.mock import patch except ImportError: from mock import patch sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from agavepy.agave import Agave # The agave API will provide a response with the following format upon a # successfull attempt at listing tenants. sample_tenants_list_response = response_template_to_json("tenants-list.json") # Sample configuration file using tenants irec and sd2e (sd2e is in current). sample_config = response_template_to_json("sample-config.json") class TestSaveConfigs: """ Test client-related agave api endpoints Tests client creation (HTTP POST request), removal (HTTP DELETE request), and listing (HTTP GET request). """ @patch("agavepy.tenants.tenants.get_tenants") def test_save_configs(self, mock_get_tenants): """ Test Agave initialization """
files-listings_tests.py """ import pytest import json import os import sys from testsuite_utils import MockServer from response_templates import response_template_to_json try: # python 2 from BaseHTTPServer import BaseHTTPRequestHandler except ImportError: # python 3 from http.server import BaseHTTPRequestHandler from tapispy.tapis import Tapis # Sample successful responses from the agave api. sample_files_list_response = response_template_to_json("files-list.json") class MockServerListingsEndpoints(BaseHTTPRequestHandler): """ Mock the Agave API """ def do_GET(self): """ Mock oauth client listing. """ self.send_response(200) self.end_headers() self.wfile.write(json.dumps(sample_files_list_response).encode()) class TestMockServer(MockServer): """ Test file listing-related agave api endpoints
import pytest import json import os import sys import time from testsuite_utils import MockServer from response_templates import response_template_to_json try: # python 2 from BaseHTTPServer import BaseHTTPRequestHandler except ImportError: # python 3 from http.server import BaseHTTPRequestHandler from agavepy.agave import Agave # Sample successful responses from the agave api. sample_files_pems_list_response = response_template_to_json("files-pems-list.json") class MockServerListingsEndpoints(BaseHTTPRequestHandler): """ Mock the Agave API """ def do_GET(self): # Check that basic auth is used. authorization = self.headers.get("Authorization") if authorization == "" or authorization is None: self.send_response(400) self.end_headers() return self.send_response(200)
import os import shutil import tempfile import time from testsuite_utils import MockServer from response_templates import response_template_to_json try: # python 2 from BaseHTTPServer import BaseHTTPRequestHandler except ImportError: # python 3 from http.server import BaseHTTPRequestHandler from agavepy.agave import Agave # Sample successful responses from the agave api. sample_files_upload_response = response_template_to_json("files-upload.json") class MockServerFilesEndpoints(BaseHTTPRequestHandler): def send_headers(self): # The path corresponds to the service being queried. For example, # querying "http://localhost:80/f/file.txt" will set the path as # "/f/file.txt". npath = os.path.normpath(self.path) npath = npath[1:] path_elements = npath.split("/") # Check access token. try: # Python 2 valid_access_token = self.headers.getheader("Authorization") except AttributeError: # Python 3
import sys from http.server import BaseHTTPRequestHandler from testsuite_utils import MockServer from response_templates import response_template_to_json try: from unittest.mock import patch except ImportError: from mock import patch sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from agavepy.agave import Agave # Sample successful responses from the agave api. sample_client_create_response = response_template_to_json( "clients-create.json") sample_client_list_response = response_template_to_json("clients-list.json") sample_client_subscription = response_template_to_json( "clients-subscriptions.json") class MockServerClientEndpoints(BaseHTTPRequestHandler): """ Mock the Agave API Mock client managament endpoints from the agave api. """ def do_GET(self): """ Mock oauth client listing. """ # Check that basic auth is used. authorization = self.headers.get("Authorization")
import os import sys from response_templates import response_template_to_json try: from unittest.mock import patch except ImportError: from mock import patch sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from tapispy.tapis import Tapis # The agave API will provide a response with the following format upon a # successfull attempt at listing tenants. sample_tenants_list_response = response_template_to_json("tenants-list.json") class TestAgaveInitialization: """ Test client-related agave api endpoints Tests client creation (HTTP POST request), removal (HTTP DELETE request), and listing (HTTP GET request). """ @patch("tapispy.tenants.tenants.get_tenants") @patch("tapispy.agave.input") def test_Agave_init(self, mock_get_tenants, mock_input): """ Test Agave initialization """ # Patch list_tenants function and input. mock_input.return_value = sample_tenants_list_response
from testsuite_utils import MockServer from response_templates import response_template_to_json try: from unittest.mock import patch except ImportError: from mock import patch sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from tapispy.tapis import Tapis # Agave will provide a response with the following format upon a # successfull attempt at creating an access token. Refreshing a token results # in a response with the same format. sample_token_create_response = response_template_to_json("auth-tokens-create.json") class MockServerTokenEndpoints(BaseHTTPRequestHandler): """ Mock token managament endpoints. """ def do_POST(self): """ Test token creation and refreshing """ # Get request data (curl's -d). form = cgi.FieldStorage( fp = self.rfile, headers = self.headers, environ={'REQUEST_METHOD': 'POST'})
from testsuite_utils import MockServer from response_templates import response_template_to_json try: from unittest.mock import patch except ImportError: from mock import patch sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from agavepy.agave import Agave # Agave will provide a response with the following format upon a # successfull attempt at creating an access token. Refreshing a token results # in a response with the same format. sample_token_create_response = response_template_to_json("auth-tokens-create.json") class MockServerTokenEndpoints(BaseHTTPRequestHandler): """ Mock token managament endpoints. """ def do_POST(self): """ Test token creation and refreshing """ # Get request data (curl's -d). form = cgi.FieldStorage( fp = self.rfile, headers = self.headers, environ={'REQUEST_METHOD': 'POST'})
import sys import tempfile from response_templates import response_template_to_json try: from unittest.mock import patch except ImportError: from mock import patch sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from agavepy.agave import Agave # The agave API will provide a response with the following format upon a # successfull attempt at listing tenants. sample_tenants_list_response = response_template_to_json("tenants-list.json") # Sample configuration file using tenants irec and sd2e (sd2e is in current). sample_config = response_template_to_json("sample-config.json") class TestSaveConfigs: """ Test client-related agave api endpoints Tests client creation (HTTP POST request), removal (HTTP DELETE request), and listing (HTTP GET request). """ @patch("agavepy.tenants.tenants.get_tenants") def test_save_configs(self, mock_get_tenants): """ Test Agave initialization
import shutil import tempfile import time from testsuite_utils import MockServer from response_templates import response_template_to_json try: # python 2 from BaseHTTPServer import BaseHTTPRequestHandler except ImportError: # python 3 from http.server import BaseHTTPRequestHandler from agavepy.agave import Agave # Sample successful responses from the agave api. sample_files_upload_response = response_template_to_json("files-upload.json") class MockServerFilesEndpoints(BaseHTTPRequestHandler): def send_headers(self): # The path corresponds to the service being queried. For example, # querying "http://localhost:80/f/file.txt" will set the path as # "/f/file.txt". npath = os.path.normpath(self.path) npath = npath[1:] path_elements = npath.split("/") # Check access token. try: # Python 2 valid_access_token = self.headers.getheader("Authorization") except AttributeError: # Python 3
import os import sys from response_templates import response_template_to_json try: from unittest.mock import patch except ImportError: from mock import patch sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from agavepy.agave import Agave # The agave API will provide a response with the following format upon a # successfull attempt at listing tenants. sample_tenants_list_response = response_template_to_json("tenants-list.json") class TestAgaveInitialization: """ Test client-related agave api endpoints Tests client creation (HTTP POST request), removal (HTTP DELETE request), and listing (HTTP GET request). """ @patch("agavepy.tenants.tenants.get_tenants") @patch("agavepy.agave.input") def test_Agave_init(self, mock_get_tenants, mock_input): """ Test Agave initialization """ # Patch list_tenants function and input.