diff --git a/server-api/client-tests/__init__.py b/server-api/client-tests/__init__.py new file mode 100644 index 0000000..d6194da --- /dev/null +++ b/server-api/client-tests/__init__.py @@ -0,0 +1 @@ +from . import web diff --git a/server-api/client-tests/client.py b/server-api/client-tests/client.py index 038e070..2192009 100644 --- a/server-api/client-tests/client.py +++ b/server-api/client-tests/client.py @@ -1,55 +1,7 @@ import time import subprocess, os, sys import json, requests - -class RequestError(Exception): - pass - -class Response: - def __init__(self, body, code): - self.body = body - self.code = code - - def __str__(self): - return f'{self.code} => {self.body}' - -class Request: - def __init__(self, domain: str, params: dict): - assert(path[len(path) - 1] != '/') - - self.domain = domain - self.params = params - - def _make_request(self, method: str, path: str, hope: int): - # Lower driver for actuall making the request we are looking for - assert(path.startswith('/')) - method = method.lower() - - url = self.domain + path - if method == 'get': - resp = requests.get(url, data=self.params) - return Response(resp.body, resp.status_code, hope) - elif method == 'post': - resp = requests.post(url, data=self.params) - return Response(resp.body, resp.status_code, hope) - elif: method == 'delete': - resp = requests.delete(url, data=self.params) - return Response(resp.body, resp.status_code, hope) - - else: - raise RequestError('Invalid method passed') - - - - def get(self, path: str, hope: int): - return self._make_request('get', path, hope) - - def post(self, path: str, hope: int): - return self._make_request('post', path, hope) - - def delete(self, path: str, hope: int): - return self._make_request('delete', path, hope) - +from web import http class Test: diff --git a/server-api/client-tests/web/__init__.py b/server-api/client-tests/web/__init__.py new file mode 100644 index 0000000..33eaa2e --- /dev/null +++ b/server-api/client-tests/web/__init__.py @@ -0,0 +1 @@ +from . import http diff --git a/server-api/client-tests/web/http.py b/server-api/client-tests/web/http.py new file mode 100644 index 0000000..73e1309 --- /dev/null +++ b/server-api/client-tests/web/http.py @@ -0,0 +1,50 @@ +import requests + +class RequestError(Exception): + pass + +class Response: + def __init__(self, body, code): + self.body = body + self.code = code + + def __str__(self): + return f'{self.code} => {self.body}' + +class Request: + def __init__(self, domain: str, params: dict): + assert(domain[len(domain) - 1] != '/') + + self.domain = domain + self.params = params + + def _make_request(self, method: str, path: str, hope: int): + # Lower driver for actuall making the request we are looking for + assert(path.startswith('/')) + method = method.lower() + + url = self.domain + path + if method == 'get': + resp = requests.get(url, data=self.params) + return Response(resp.body, resp.status_code, hope) + elif method == 'post': + resp = requests.post(url, data=self.params) + return Response(resp.body, resp.status_code, hope) + elif method == 'delete': + resp = requests.delete(url, data=self.params) + return Response(resp.body, resp.status_code, hope) + + else: + raise RequestError('Invalid method passed') + + + + def get(self, path: str, hope: int): + return self._make_request('get', path, hope) + + def post(self, path: str, hope: int): + return self._make_request('post', path, hope) + + def delete(self, path: str, hope: int): + return self._make_request('delete', path, hope) +