def setUp(self): #Create NGINXServer class instance to control server start and stop self.nginx = NginxServer( **{ 'http_options': 'limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;', 'server_options': 'limit_req zone=one burst=6 nodelay;' }) self.nginx.start() self.app = TestApp(self.nginx.root_url)
def start_server(self, locations=None, pages=None): if locations is None: locations = [] if pages is None: pages = ('dashboard', 'action', 'search', 'welp/1234') locations.append({'path': '/', 'definition': LOCATION}) self.serv_dir = tempfile.mkdtemp() target = os.path.join(self.serv_dir, 'api-specs') shutil.copy(SPEC_FILE, target) # and lets add some pages for page in pages: path = os.path.join(self.serv_dir, page) if not os.path.isdir(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) with open(path, 'w') as f: f.write('yeah') if PY3: server = 'http.server' else: server = 'SimpleHTTPServer' self._p = subprocess.Popen([sys.executable, '-m', server, '8282'], cwd=self.serv_dir, stderr=subprocess.PIPE, stdout=subprocess.PIPE) start = time.time() res = None while time.time() - start < 2: try: res = requests.get('http://127.0.0.1:8282/api-specs') break except requests.ConnectionError: time.sleep(.1) if res is None: self._kill_python_server() raise IOError("Could not start the Py server") try: self.nginx = NginxServer(locations=locations, http_options=HTTP_OPTIONS, server_options=SERVER_OPTIONS) self.nginx.start() except Exception: self._kill_python_server() raise
def setUp(self): self.nginx = NginxServer() self.nginx.start() self.app = TestApp(self.nginx.root_url)