Skip to content

Commit

Permalink
subsequence limit and trunc512 flag added in mockserver
Browse files Browse the repository at this point in the history
  • Loading branch information
someshc8i committed Jul 5, 2018
1 parent 83bc9e1 commit 21a601e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
7 changes: 6 additions & 1 deletion tests/conftest.py
Expand Up @@ -32,6 +32,10 @@ def pytest_addoption(parser):
"--redir",
action="store_true",
default="False", help="success queries redirection")
parser.addoption(
"--trunc512",
action="store_true",
default="False", help="trunc512 support")


@pytest.fixture(scope='session')
Expand All @@ -47,7 +51,8 @@ def server(request):
return 'http://' + option.server
circular_support = request.config.getoption("--cir")
redirection = request.config.getoption("--redir")
trunc512 = request.config.getoption("--trunc512")
port = get_free_port()
start_mock_server(port, circular_support, redirection)
start_mock_server(port, circular_support, redirection, trunc512=trunc512)
server_base_url = 'http://localhost:' + str(port)
return server_base_url
14 changes: 11 additions & 3 deletions tests/mockserver.py
Expand Up @@ -13,6 +13,8 @@
DATA = []
CIRCULAR_CHROMOSOME_SUPPORT = True
REDIRECTION = False
SUBSEQUENCE_LIMIT = 400000
TRUNC512 = True


class MockServerRequestHandler(BaseHTTPRequestHandler):
Expand Down Expand Up @@ -150,7 +152,9 @@ def get_seq_obj(self):

seq_id = self.get_seq_id()
for seq in DATA:
if seq.md5 == seq_id or seq.sha512 == seq_id:
if seq.md5 == seq_id:
return seq
if TRUNC512 is True and seq.sha512 == seq_id:
return seq
return None

Expand All @@ -173,6 +177,9 @@ def send(self, status_code, content="".encode("ascii"), headers={}):
such as do_GET, handle_subsequence_query_range and
handle_subsequence_query_start_end
'''
if len(content) > SUBSEQUENCE_LIMIT:
self.send(416)
return

self.send_response(status_code)
for key in headers:
Expand Down Expand Up @@ -342,7 +349,7 @@ def get_free_port():
return port


def start_mock_server(port, circular_support, redirection, daemon=True):
def start_mock_server(port, circular_support, redirection, daemon=True, trunc512=True):
''' start_mock_server used by test suite's conftest.py file to run the server
on the fly. It gets circular_support (a boolean variable) from conftest.py
to set the global variable CIRCULAR_CHROMOSOME_SUPPORT in the server.
Expand All @@ -351,9 +358,10 @@ def start_mock_server(port, circular_support, redirection, daemon=True):
running all the tests.
'''

global CIRCULAR_CHROMOSOME_SUPPORT, REDIRECTION
global CIRCULAR_CHROMOSOME_SUPPORT, REDIRECTION, TRUNC512
CIRCULAR_CHROMOSOME_SUPPORT = circular_support
REDIRECTION = redirection
TRUNC512 = trunc512
set_data()
mock_server = HTTPServer(('localhost', port), MockServerRequestHandler)
mock_server_thread = Thread(target=mock_server.serve_forever)
Expand Down

0 comments on commit 21a601e

Please sign in to comment.