Python httpretty.POST Examples
The following are 30
code examples of httpretty.POST().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
httpretty
, or try the search function
.
Example #1
Source File: test_backends.py From django-oidc-rp with MIT License | 6 votes |
def test_can_process_userinfo_included_in_the_id_token_instead_of_calling_the_userinfo_endpoint( self, rf): httpretty.register_uri( httpretty.POST, oidc_rp_settings.PROVIDER_TOKEN_ENDPOINT, body=json.dumps({ 'id_token': self.generate_jws(email='test1@example.com'), 'access_token': 'accesstoken', 'refresh_token': 'refreshtoken', }), content_type='text/json') request = rf.get('/oidc/cb/', {'state': 'state', 'code': 'authcode', }) SessionMiddleware().process_request(request) request.session.save() backend = OIDCAuthBackend() user = backend.authenticate(request, 'nonce') assert user.email == 'test1@example.com' assert user.oidc_user.sub == '1234'
Example #2
Source File: test_middleware.py From django-oidc-rp with MIT License | 6 votes |
def setup(self): httpretty.enable() self.key = RSAKey(kid='testkey').load(os.path.join(FIXTURE_ROOT, 'testkey.pem')) def jwks(_request, _uri, headers): # noqa: E306 ks = KEYS() ks.add(self.key.serialize()) return 200, headers, ks.dump_jwks() httpretty.register_uri( httpretty.GET, oidc_rp_settings.PROVIDER_JWKS_ENDPOINT, status=200, body=jwks) httpretty.register_uri( httpretty.POST, oidc_rp_settings.PROVIDER_TOKEN_ENDPOINT, body=json.dumps({ 'id_token': self.generate_jws(), 'access_token': 'accesstoken', 'refresh_token': 'refreshtoken', }), content_type='text/json') httpretty.register_uri( httpretty.GET, oidc_rp_settings.PROVIDER_USERINFO_ENDPOINT, body=json.dumps({'sub': '1234', 'email': 'test@example.com', }), content_type='text/json') yield httpretty.disable()
Example #3
Source File: test_middleware.py From django-oidc-rp with MIT License | 6 votes |
def test_log_out_the_user_if_the_id_token_is_not_valid(self, rf): request = rf.get('/oidc/cb/', {'state': 'state', 'code': 'authcode', }) SessionMiddleware().process_request(request) request.session.save() backend = OIDCAuthBackend() user = backend.authenticate(request, 'nonce') request.session['oidc_auth_id_token_exp_timestamp'] = \ (tz.now() - dt.timedelta(minutes=1)).timestamp() request.session['oidc_auth_refresh_token'] = 'this_is_a_refresh_token' auth.login(request, user) request.user = user httpretty.register_uri( httpretty.POST, oidc_rp_settings.PROVIDER_TOKEN_ENDPOINT, body=json.dumps({ 'id_token': 'badidtoken', 'access_token': 'accesstoken', 'refresh_token': 'refreshtoken', }), content_type='text/json') middleware = OIDCRefreshIDTokenMiddleware(lambda r: 'OK') middleware(request) assert not request.user.is_authenticated
Example #4
Source File: test_authentication.py From django-oidc-rp with MIT License | 6 votes |
def setup(self): httpretty.enable() self.key = RSAKey(kid='testkey').load(os.path.join(FIXTURE_ROOT, 'testkey.pem')) def jwks(_request, _uri, headers): # noqa: E306 ks = KEYS() ks.add(self.key.serialize()) return 200, headers, ks.dump_jwks() httpretty.register_uri( httpretty.GET, oidc_rp_settings.PROVIDER_JWKS_ENDPOINT, status=200, body=jwks) httpretty.register_uri( httpretty.POST, oidc_rp_settings.PROVIDER_TOKEN_ENDPOINT, body=json.dumps({ 'id_token': self.generate_jws(), 'access_token': 'accesstoken', 'refresh_token': 'refreshtoken', }), content_type='text/json') httpretty.register_uri( httpretty.GET, oidc_rp_settings.PROVIDER_USERINFO_ENDPOINT, body=json.dumps({'sub': '1234', 'email': 'test@example.com', }), content_type='text/json') yield httpretty.disable()
Example #5
Source File: android_test.py From python-client with Apache License 2.0 | 6 votes |
def test_find_element_by_android_data_matcher(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/element'), body='{"value": {"element-6066-11e4-a52e-4f735466cecf": "element-id"}}' ) el = driver.find_element_by_android_data_matcher( name='title', args=['title', 'Animation'], className='class name') d = get_httpretty_request_body(httpretty.last_request()) assert d['using'] == '-android datamatcher' value_dict = json.loads(d['value']) assert value_dict['args'] == ['title', 'Animation'] assert value_dict['name'] == 'title' assert value_dict['class'] == 'class name' assert el.id == 'element-id'
Example #6
Source File: site.py From anime-downloader with The Unlicense | 6 votes |
def configure_httpretty(sitedir): httpretty.enable() dir = Path(f"tests/test_sites/data/test_{sitedir}/") data_file = dir / 'data.json' data = None with open(data_file) as f: data = json.load(f) for obj in data: method = httpretty.POST if obj['method'] == 'GET': method = httpretty.GET with open(dir / obj['file']) as f: httpretty.register_uri( method, obj['url'], f.read(), )
Example #7
Source File: test_posting.py From atomicpuppy with MIT License | 6 votes |
def because_an_event_is_published_on_a_stream(self): httpretty.register_uri( httpretty.POST, "http://{}:{}/streams/{}".format(self._host, self._port, self.stream), body='{}') data = {'foo': 'bar'} evt = Event( id=self.event_id, type='my-event-type', data=data, stream=self.stream, sequence=None, metadata=None, ) self.publisher.post(evt, correlation_id=self.correlation_id) self.response_body = json.loads(httpretty.last_request().body.decode())[0]
Example #8
Source File: test_backends.py From django-oidc-rp with MIT License | 6 votes |
def setup(self): httpretty.enable() self.key = RSAKey(kid='testkey').load(os.path.join(FIXTURE_ROOT, 'testkey.pem')) def jwks(_request, _uri, headers): # noqa: E306 ks = KEYS() ks.add(self.key.serialize()) return 200, headers, ks.dump_jwks() httpretty.register_uri( httpretty.GET, oidc_rp_settings.PROVIDER_JWKS_ENDPOINT, status=200, body=jwks) httpretty.register_uri( httpretty.POST, oidc_rp_settings.PROVIDER_TOKEN_ENDPOINT, body=json.dumps({ 'id_token': self.generate_jws(), 'access_token': 'accesstoken', 'refresh_token': 'refreshtoken', }), content_type='text/json') httpretty.register_uri( httpretty.GET, oidc_rp_settings.PROVIDER_USERINFO_ENDPOINT, body=json.dumps({'sub': '1234', 'email': 'test@example.com', }), content_type='text/json') yield httpretty.disable()
Example #9
Source File: test_posting.py From atomicpuppy with MIT License | 6 votes |
def because_an_event_is_published_on_a_stream(self): httpretty.register_uri( httpretty.POST, "http://{}:{}/streams/{}".format(self._host, self._port, self.stream), body='{}') data = {'foo': 'bar'} metadata = {'lorem': 'ipsum'} evt = Event( id=self.event_id, type='my-event-type', data=data, stream=self.stream, sequence=None, metadata=metadata, ) self.publisher.post(evt, correlation_id=self.correlation_id) self.response_body = json.loads(httpretty.last_request().body.decode())[0]
Example #10
Source File: android_test.py From python-client with Apache License 2.0 | 6 votes |
def test_find_elements_by_android_data_matcher(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/elements'), body='{"value": [{"element-6066-11e4-a52e-4f735466cecf": "element-id1"}, {"element-6066-11e4-a52e-4f735466cecf": "element-id2"}]}' ) els = driver.find_elements_by_android_data_matcher(name='title', args=['title', 'Animation']) d = get_httpretty_request_body(httpretty.last_request()) assert d['using'] == '-android datamatcher' value_dict = json.loads(d['value']) assert value_dict['args'] == ['title', 'Animation'] assert value_dict['name'] == 'title' assert els[0].id == 'element-id1' assert els[1].id == 'element-id2'
Example #11
Source File: webelement_test.py From python-client with Apache License 2.0 | 6 votes |
def test_send_key_with_file(self): driver = android_w3c_driver() # Should not send this file tmp_f = tempfile.NamedTemporaryFile() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/element/element_id/value') ) try: element = MobileWebElement(driver, 'element_id', w3c=True) element.send_keys(tmp_f.name) finally: tmp_f.close() d = get_httpretty_request_body(httpretty.last_request()) assert d['text'] == ''.join(d['value'])
Example #12
Source File: android_test.py From python-client with Apache License 2.0 | 6 votes |
def test_find_element_by_android_data_matcher(self): driver = android_w3c_driver() element = MobileWebElement(driver, 'element_id', w3c=True) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/element/element_id/element'), body='{"value": {"element-6066-11e4-a52e-4f735466cecf": "child-element-id"}}' ) el = element.find_element_by_android_data_matcher( name='title', args=['title', 'Animation'], className='class name') d = get_httpretty_request_body(httpretty.last_request()) assert d['using'] == '-android datamatcher' value_dict = json.loads(d['value']) assert value_dict['args'] == ['title', 'Animation'] assert value_dict['name'] == 'title' assert value_dict['class'] == 'class name' assert el.id == 'child-element-id'
Example #13
Source File: performance_test.py From python-client with Apache License 2.0 | 5 votes |
def test_get_performance_data_types(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/appium/performanceData/types'), body='{"value": ["cpuinfo", "memoryinfo", "batteryinfo", "networkinfo"]}' ) assert driver.get_performance_data_types() == ['cpuinfo', 'memoryinfo', 'batteryinfo', 'networkinfo']
Example #14
Source File: app_test.py From python-client with Apache License 2.0 | 5 votes |
def test_launch_app(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/appium/app/launch'), body='{"value": }' ) assert isinstance(driver.launch_app(), WebDriver)
Example #15
Source File: app_test.py From python-client with Apache License 2.0 | 5 votes |
def test_query_app_state(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/appium/device/app_state'), body='{"value": 3 }' ) result = driver.query_app_state('com.app.id') assert {'app': 3}, get_httpretty_request_body(httpretty.last_request()) assert result is ApplicationState.RUNNING_IN_BACKGROUND
Example #16
Source File: app_test.py From python-client with Apache License 2.0 | 5 votes |
def test_close_app(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/appium/app/close'), body='{"value": }' ) assert isinstance(driver.close_app(), WebDriver)
Example #17
Source File: android_test.py From python-client with Apache License 2.0 | 5 votes |
def test_find_elements_by_android_data_matcher_no_value(self): driver = android_w3c_driver() element = MobileWebElement(driver, 'element_id', w3c=True) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/element/element_id/elements'), body='{"value": []}' ) els = element.find_elements_by_android_data_matcher() d = get_httpretty_request_body(httpretty.last_request()) assert d['using'] == '-android datamatcher' assert d['value'] == '{}' assert len(els) == 0
Example #18
Source File: screen_record_test.py From python-client with Apache License 2.0 | 5 votes |
def test_start_recording_screen(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/appium/start_recording_screen'), ) assert driver.start_recording_screen(user='userA', password='12345') is None d = get_httpretty_request_body(httpretty.last_request()) assert d['options']['user'] == 'userA' assert d['options']['pass'] == '12345' assert 'password' not in d['options'].keys()
Example #19
Source File: test_posting.py From atomicpuppy with MIT License | 5 votes |
def because_an_event_is_published_on_a_stream(self): httpretty.register_uri( httpretty.POST, "http://{}:{}/streams/{}".format(self._host, self._port, self.stream), body='{}') data = {'foo': 'bar'} metadata = {'lorem': 'ipsum'} evt = Event(self.event_id, 'my-event-type', data, self.stream, None, metadata) self.publisher.post(evt) self.response_body = json.loads(httpretty.last_request().body.decode())[0]
Example #20
Source File: screen_record_test.py From python-client with Apache License 2.0 | 5 votes |
def test_stop_recording_screen(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/appium/stop_recording_screen'), body='{"value": "b64_video_data"}' ) assert driver.stop_recording_screen(user='userA', password='12345') == 'b64_video_data' d = get_httpretty_request_body(httpretty.last_request()) assert d['options']['user'] == 'userA' assert d['options']['pass'] == '12345' assert 'password' not in d['options'].keys()
Example #21
Source File: test_posting.py From atomicpuppy with MIT License | 5 votes |
def it_should_be_a_POST(self): assert(httpretty.last_request().method == "POST")
Example #22
Source File: app_test.py From python-client with Apache License 2.0 | 5 votes |
def test_background_app(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/appium/app/background'), body='{"value": ""}' ) result = driver.background_app(0) assert {'app': 0}, get_httpretty_request_body(httpretty.last_request()) assert isinstance(result, WebDriver)
Example #23
Source File: app_test.py From python-client with Apache License 2.0 | 5 votes |
def test_activate_app(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/appium/device/activate_app'), body='{"value": ""}' ) result = driver.activate_app("com.app.id") assert {'app': 'com.app.id'}, get_httpretty_request_body(httpretty.last_request()) assert isinstance(result, WebDriver)
Example #24
Source File: app_test.py From python-client with Apache License 2.0 | 5 votes |
def test_app_installed(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/appium/device/app_installed'), body='{"value": true}' ) result = driver.is_app_installed("com.app.id") assert {'app': "com.app.id"}, get_httpretty_request_body(httpretty.last_request()) assert result is True
Example #25
Source File: app_test.py From python-client with Apache License 2.0 | 5 votes |
def test_remove_app(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/appium/device/remove_app'), body='{"value": ""}' ) result = driver.remove_app('com.app.id') assert {'app': 'com.app.id'}, get_httpretty_request_body(httpretty.last_request()) assert isinstance(result, WebDriver)
Example #26
Source File: app_test.py From python-client with Apache License 2.0 | 5 votes |
def test_install_app(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/appium/device/install_app'), body='{"value": ""}' ) result = driver.install_app('path/to/app') assert {'app': 'path/to/app'}, get_httpretty_request_body(httpretty.last_request()) assert isinstance(result, WebDriver)
Example #27
Source File: app_test.py From python-client with Apache License 2.0 | 5 votes |
def test_reset(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/appium/app/reset'), body='{"value": ""}' ) result = driver.reset() assert {'sessionId': '1234567890'}, get_httpretty_request_body(httpretty.last_request()) assert isinstance(result, WebDriver)
Example #28
Source File: log_events_test.py From python-client with Apache License 2.0 | 5 votes |
def test_get_events_args(self): driver = ios_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/appium/events'), body=json.dumps({'value': {'appium:funEvent': [12347]}}) ) events_to_filter = ['appium:funEvent'] events = driver.get_events(events_to_filter) assert events['appium:funEvent'] == [12347] d = get_httpretty_request_body(httpretty.last_request()) assert d['type'] == events_to_filter
Example #29
Source File: android_test.py From python-client with Apache License 2.0 | 5 votes |
def test_find_elements_by_android_data_matcher_no_value(self): driver = android_w3c_driver() httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/elements'), body='{"value": []}' ) els = driver.find_elements_by_android_data_matcher() d = get_httpretty_request_body(httpretty.last_request()) assert d['using'] == '-android datamatcher' assert d['value'] == '{}' assert len(els) == 0
Example #30
Source File: windows_test.py From python-client with Apache License 2.0 | 5 votes |
def test_find_element_by_windows_uiautomation(self): driver = android_w3c_driver() element = MobileWebElement(driver, 'element_id', w3c=True) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/element/element_id/element'), body='{"value": {"element-6066-11e4-a52e-4f735466cecf": "win-element-id"}}' ) el = element.find_element_by_windows_uiautomation('win_element') d = get_httpretty_request_body(httpretty.last_request()) assert d['using'] == '-windows uiautomation' assert el.id == 'win-element-id'