def test_requests(self): # Assume url = 'https://www.ole.com.ar/river-plate/' # Action request = Request() result = request.makeRequest(url) # Assert self.assertIsInstance(result, str)
def test_invalid_url(self): # Assume url = 'http:://badurl..com' # Action request = Request() # Assert with self.assertRaises(urllib2.URLError): request.makeRequest(url)
def test_fetch_text_fail() -> None: url = "http://github.com/mocking/fail" responses.add( responses.GET, url, status=503, ) with pytest.raises(Exception): Request.fetch_text(url)
def collect(user: str, date_range: DateRange) -> Extractor: data = [] for year in date_range.iter_year(): url = f"https://github.com/{user}" params = { "from": f"{year}-01-01", } text = Request.fetch_text(url, params) rects = BeautifulSoup(text, "html.parser").findAll("rect") for rect in rects: data_date = rect["data-date"] data_count = rect["data-count"] if date.fromisoformat(data_date) in date_range: data.append( [ pd.Timestamp(data_date), pd.to_numeric(data_count), ] ) return Extractor( user=user, df=pd.DataFrame( data=data, columns=["date", "count"], ), )
def test_reponse_created(self): print('running') request = Request(environ, start_response) response = Response(request, '200 OK', 'text/html') self.assertEqual(response.headers, []) self.assertEqual(response.status_code, '200 OK') self.assertEqual(response.content_type, 'text/html') self.assertEqual(response.response_content, [])
def produce(self): request_id = self.__current_request creation_time = self.next_creation_time new_request = Request(self.id, request_id, creation_time) self.__current_request += 1 self.next_creation_time += self.__generate_delay_before_request() return new_request
async def parse_request(self, client): data = await self.loop.sock_recv(client, self.SOCK_BUFFER_SIZE) message = data.decode() lines = message.split('\r\n') try: method, target, ver = lines[0].split() except ValueError: raise HTTPError(400, 'Bad Request') return Request(method, target, ver, [], None)
def test_fetch_text_success() -> None: url = "http://github.com/mocking/success" key = "key" value = "value" responses.add( responses.GET, f"{url}?{key}={value}", body=b"text", ) text = Request.fetch_text(url, {key: value}) assert text == "text"
def test_create_request(self): request = Request(environ, start_response) self.assertEqual(request.http_host , environ['HTTP_HOST']) self.assertEqual(request.http_user_agent , environ['HTTP_USER_AGENT']) self.assertEqual(request.lang , environ.get('LANG')) self.assertEqual(request.method , environ.get('REQUEST_METHOD')) self.assertEqual(request.path , environ.get('PATH_INFO')) self.assertEqual(request.host_address , environ.get('HTTP_HOST')) self.assertEqual(request.gateway_interface , environ.get('GATEWAY_INTERFACE')) self.assertEqual(request.server_port , environ.get('SERVER_PORT')) self.assertEqual(request.remote_host , environ.get('REMOTE_HOST')) self.assertEqual(request.content_length , environ.get('CONTENT_LENGTH')) self.assertEqual(request.server_protocol , environ.get('SEVER_PROTOCOL')) self.assertEqual(request.server_software , environ.get('SERVER_SOFTWARE')) self.assertEqual(request.start_response , start_response) self.assertEqual(request.environ , environ)
def ReqPusher(self, info): deployment = self.GetDepByLabel(info[1]) with deployment.lock: deployment.pendingReqs.append(Request(info)) deployment.waiting.set()
def ReqPusher(self, info): self.etcd.pendingReqs.append(Request(info)) self.requestWaiting.set()
def test_ok(): return Request().run()
def subscribe(self, streams): request = Request(self, "subscribe") if streams is not None: request.message.streams = streams if isinstance(streams, list) else [streams] return request
customers = [] windows = [] for i in range(0, Globals.window_number): # 创建窗口 windows.append(Window(id=i)) time = 0 for i in range(0, Globals.max_cus): # 创建所有顾客 start_time = time + float( np.random.poisson(Globals.mean_arrive_time * 10)) / 10 time = start_time # start_time = float(np.random.exponential(Globals.mean_arrive_time)) # duration = -Globals.mean_serve_time * np.log(float(np.random.randint(1, 11) / 10)) duration = float(np.random.exponential(Globals.mean_serve_time)) customers.append(Request(arrive_time=start_time, duration=duration)) if Globals.debug: print("准备工作完毕") print("已经创建%d个窗口" % len(windows)) print("已经创建%d个顾客" % len(customers)) for i in customers: print(" %d-客户:到达时间%f:服务时间%f" % (i.get_id(), i.get_arrive_time(), i.get_duration())) # 创建控制器 controller = Controller(outdoors=customers, windows=windows) controller.run() a = Statistics.wait_time / Globals.max_cus b = Statistics.wait_area / Globals.window_number / Globals.cur_time c = Statistics.usage_time * 100 / Globals.cur_time / Globals.window_number
import socket from src.request import Request from src.utils import log from src.routes import route_dict from src.UserManage import Error request = Request() #url解析 def path_parise(path): log(path) query={} index = path.find('?') log('-----------------') log(index) if index != -1: path, query_string = path.split('?', 1) args = query_string.split('&') query = {} for arg in args: k, v = arg.split('=') query[k] = v if 'static' in path: query['filename'] =path path='static' return path, query #响应 def response_for_path(path): log("the path is {}".format(path)) response=route_dict.get(path,Error) return response(request)
from src.request import Request Request().run()