def __register_product_metadata_uri(self, mocker: Mocker, page_number: int): mocker.register_uri( "GET", f"{STARTING_PAGE}/{self.__eggs_and_dairy_category.name}?page={page_number}", text=load_meta_data_page(page_number), status_code=200)
def mock_requests_snapshot(request_mock: Mocker) -> (dict, Mocker): """ Mocks uploading to snapshot (get info and upload). GET to /desktop-app with snapshot data and return info. POST to /events/devices/snapshot to upload snapshot to DH """ # env file retuned to GET /desktop-app env_test = file('env_dh_test_id') uri_post = '{}/{}/events/devices/snapshot'.format(env_test['url'], env_test['db']) headers = { "Content-Type": "application/json", "Accept": "application/json" } headers_snapshot = headers.update({AUTH: BASIC.format(env_test['token'])}) request_mock.post(uri_post, json={'_id': 'new-snapshot-id'}, request_headers=headers_snapshot) # GET Request Matching request_mock.register_uri('GET', 'https://api.devicetag.io/desktop-app', request_headers=headers, json=env_test) return headers, request_mock
def test_error_get(self, *, rmock: requests_mock.Mocker) -> None: rmock.register_uri("GET", "mock://test/api", status_code=400, text='[{"error": "error", "meta": "meta"}]', reason="test") with self.assertRaises(AptlyAPIException): self.client.files.do_get("mock://test/api")
def test_request_router_uses_crl_validator(self, mocker: requests_mock.Mocker) -> None: # Given mocker.register_uri('POST', f'{self.sas_url}/registration') # When self.router.post_to_sas(request_dict={"registrationRequest": [{"foo": "bar"}]}) # Then self.crl_validator_mock.is_valid.assert_called_once_with(url=self.sas_url)
def init(self, requests_mock: Mocker, tmpdir_factory): Exchange._ngshare_url = "http://example.com" self.base_url = Exchange.ngshare_url.fget(Exchange) self.course_dir = self._init_course_dir(tmpdir_factory) self.cache_dir = self._init_cache_dir(tmpdir_factory) self.requests_mocker = requests_mock requests_mock.register_uri(rq_mock.ANY, rq_mock.ANY, text=self._mock_all)
def test_getAllSpellIndexess(self, requests_mock: RM.Mocker, spells: S.Spells, success: bool, code: int): requests_mock.register_uri(RM.GET, S.SPELLS_INDEX_URL, status_code=code, json=F.FAKE_SPELLS_INDEX) if (success): result = spells.getAllSpellIndexes() assert result == F.FAKE_SPELLS_INDEX_NAMES else: with PT.raises(Exception): result = spells.getAllSpellIndexes()
def test_getSpell(self, requests_mock: RM.Mocker, spells: S.Spells, success: bool, code: int): index = "fake-spell-1" requests_mock.register_uri(RM.GET, spells.getSpellURL(index), status_code=code, json=F.FAKE_SPELL) if (success): result = spells.getSpell(index) assert result == F.FAKE_SPELL else: with PT.raises(Exception): result = spells.getAllSpellIndexes()
def register(self, mocker: requests_mock.Mocker): services = self.pki_arch.service_registry for ocsp_info in services.list_ocsp_responders(): mocker.register_uri( 'POST', ocsp_info.url, content=partial(self.serve_ocsp_response, label=ocsp_info.label), headers={'Content-Type': 'application/ocsp-response'}) for tsa_info in services.list_time_stamping_services(): mocker.register_uri( 'POST', tsa_info.url, content=partial(self.serve_timestamp_response, label=tsa_info.label), headers={'Content-Type': 'application/timestamp-reply'}) for crl_repo in services.list_crl_repos(): mocker.register_uri( 'GET', crl_repo.latest_external_url, content=partial(self.serve_crl, label=crl_repo.label), headers={'Content-Type': 'application/pkix-crl'}) for plugin_info in services.list_plugin_services(): mocker.register_uri( 'POST', plugin_info.url, content=partial(self.serve_plugin, plugin_label=plugin_info.plugin_label, label=plugin_info.label), headers={'Content-Type': plugin_info.content_type})
def test_getAllSpells(self, requests_mock: RM.Mocker, spells: S.Spells): code = 200 indexes = F.FAKE_SPELLS_INDEX_NAMES allSpells = [] for index in indexes: requests_mock.register_uri(RM.GET, spells.getSpellURL(index), status_code=code, json=F.FAKE_SPELL) allSpells.append(F.FAKE_SPELL) requests_mock.register_uri(RM.GET, S.SPELLS_INDEX_URL, status_code=code, json=F.FAKE_SPELLS_INDEX) result = spells.getAllSpells() assert result == allSpells
def post_adjustment( self, mock: requests_mock.Mocker, defaults_resp_data: dict, adj_resp_data: dict, adj: dict, ) -> Response: mock.register_uri( "POST", f"{self.worker_url}{self.owner}/{self.title}/inputs", text=json.dumps(defaults_resp_data), ) mock.register_uri( "POST", f"{self.worker_url}{self.owner}/{self.title}/parse", text=json.dumps(adj_resp_data), ) init_resp = self.api_client.post( f"/{self.owner}/{self.title}/api/v1/", data=adj, format="json" ) assert_status(201, init_resp.status_code, "post_adjustment") return init_resp
def init_online_apifactory(self, m: requests_mock.Mocker): if not hasattr(self, 'factory'): m.register_uri( 'GET', 'https://sso.supermap.com/login', text= '{"lt":"LT-11506-wDwBEJsE2dWoVoKOfIDBZyRt0qk35k-sso.supermap.com","execution":"e1s1","_eventId":"submit"}', cookies={'JSESSIONID': '958322873908FF9CA99B5CB443ADDD5C'}) m.register_uri( 'POST', 'https://sso.supermap.com/login', headers={'location': 'https://www.supermapol.com/shiro-cas'}, status_code=302) m.register_uri( 'GET', 'https://www.supermapol.com/shiro-cas', cookies={'JSESSIONID': '958322873908FF9CA99B5CB443ADDD5C'}) self.factory = OnlineAPIFactory(self.baseuri, self.username, self.password)
def _set_mocker_CRL(mocker: requests_mock.Mocker, data: Dict[str, Union[bytes, Exception]]) -> None: for url, response in data.items(): if isinstance(response, Exception): mocker.register_uri('GET', url, exc=response) else: mocker.register_uri('GET', url, content=response)
def init(self, requests_mock: Mocker): self.requests_mocker = requests_mock requests_mock.register_uri(rq_mock.ANY, rq_mock.ANY, text=self._mock_all) cm._ngshare_url = NGSHARE_URL