Python httpretty.register_uri() Examples
The following are 30
code examples of httpretty.register_uri().
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_sources_rss.py From ThreatIngestor with GNU General Public License v2.0 | 6 votes |
def test_run_supports_both_link_url(self): httpretty.register_uri(httpretty.GET, "http://rss.mock/rss.xml", body=self.RSS_CONTENT) saved_state, artifacts = self.rss.run(None) # link self.assertIn('http://example.com/bad/url/10', [str(x) for x in artifacts]) self.assertIn('https://www.rss.mock/some/url', [a.reference_link for a in artifacts]) afterioc = threatingestor.sources.rss.Plugin('test', 'http://rss.mock/rss.xml', 'afterioc') saved_state, artifacts = afterioc.run(None) # fallback to url self.assertIn('http://example.com/bad/url/00', [str(x) for x in artifacts]) self.assertEqual(artifacts[0].reference_link, 'http://rss.mock/rss.xml')
Example #2
Source File: test_registry.py From datapackage-py with MIT License | 6 votes |
def test_get_raises_if_remote_profile_file_doesnt_exist(): registry_url = 'http://example.com/registry.json' registry_body = """ [ { "id": "data-package", "title": "Data Package", "schema": "http://example.com/one.json", "schema_path": "data-package.json", "specification": "http://example.com" } ] """ httpretty.register_uri(httpretty.GET, registry_url, body=registry_body) profile_url = 'http://example.com/one.json' httpretty.register_uri(httpretty.GET, profile_url, status=404) registry = datapackage.registry.Registry(registry_url) with pytest.raises(RegistryError): registry.get('data-package')
Example #3
Source File: test_registry.py From datapackage-py with MIT License | 6 votes |
def test_get_raises_if_local_profile_file_doesnt_exist(): registry_body = """ [ { "id": "data-package", "title": "Data Package", "schema": "http://example.com/one.json", "schema_path": "inexistent.json", "specification": "http://example.com" } ] """ with tempfile.NamedTemporaryFile(suffix='.csv') as tmpfile: tmpfile.write(registry_body.encode('utf-8')) tmpfile.flush() registry = datapackage.registry.Registry(tmpfile.name) profile_url = 'http://example.com/one.json' httpretty.register_uri(httpretty.GET, profile_url, status=404) with pytest.raises(RegistryError): registry.get('data-package')
Example #4
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 #5
Source File: tests.py From python-opencage-geocoder with MIT License | 6 votes |
def testRateLimitExceeded(self): httpretty.register_uri( httpretty.GET, self.geocoder.url, body='{"status":{"code":402,"message":"OK"},"thanks":"For using an OpenCage Data API","total_results":0,"licenses":[{"url":"http://creativecommons.org/licenses/by-sa/3.0/","name":"CC-BY-SA"},{"url":"http://opendatacommons.org/licenses/odbl/summary/","name":"ODbL"}],"rate":{"reset":1402185600,"limit":"2500","remaining":0},"results":[],"timestamp":{"created_http":"Sat, 07 Jun 2014 10:38:45 GMT","created_unix":1402137525}}', status=402, adding_headers={'X-RateLimit-Limit': '2500', 'X-RateLimit-Remaining': '0', 'X-RateLimit-Reset': '1402185600'}, ) self.assertRaises(RateLimitExceededError, self.geocoder.geocode, "whatever") # check the exception try: self.geocoder.geocode("whatever") except RateLimitExceededError as ex: self.assertEqual(str(ex), 'Your rate limit has expired. It will reset to 2500 on 2014-06-08T00:00:00') self.assertEqual(ex.reset_to, 2500)
Example #6
Source File: tests.py From python-opencage-geocoder with MIT License | 6 votes |
def testDonostia(self): httpretty.register_uri( httpretty.GET, self.geocoder.url, body='{"thanks":"For using an OpenCage Data API","status":{"message":"OK","code":200},"rate":{"remaining":2482,"limit":"2500","reset":1402185600},"total_results":7,"results":[{"geometry":{"lat":"43.3213324","lng":"-1.9856227"},"annotations":{},"components":{"postcode":"20001;20002;20003;20004;20005;20006;20007;20008;20009;20010;20011;20012;20013;20014;20015;20016;20017;20018","county":"Donostialdea/Donostia-San Sebasti\u00e1n","state":"Basque Country","country":"Spain","city":"San Sebasti\u00e1n","country_code":"es"},"formatted":"San Sebasti\u00e1n, Donostialdea/Donostia-San Sebasti\u00e1n, 20001;20002;20003;20004;20005;20006;20007;20008;20009;20010;20011;20012;20013;20014;20015;20016;20017;20018, Basque Country, Spain, es","bounds":{"southwest":{"lat":"43.2178373","lng":"-2.086808"},"northeast":{"lng":"-1.8878838","lat":"43.3381344"}}},{"formatted":"Donostia, Irun, Bidasoa Beherea / Bajo Bidasoa, Basque Country, Spain, es","components":{"county":"Bidasoa Beherea / Bajo Bidasoa","state":"Basque Country","country":"Spain","city":"Irun","country_code":"es","road":"Donostia"},"bounds":{"southwest":{"lat":"43.3422299","lng":"-1.8022744"},"northeast":{"lng":"-1.8013452","lat":"43.3449598"}},"geometry":{"lng":"-1.8019153","lat":"43.3432784"},"annotations":{}},{"annotations":{},"geometry":{"lng":"-1.8022744","lat":"43.3422299"},"formatted":"Donostia, Anaka, Irun, Bidasoa Beherea / Bajo Bidasoa, Basque Country, Spain, es","components":{"county":"Bidasoa Beherea / Bajo Bidasoa","state":"Basque Country","country":"Spain","city":"Irun","suburb":"Anaka","country_code":"es","road":"Donostia"},"bounds":{"southwest":{"lng":"-1.8022971","lat":"43.3421635"},"northeast":{"lng":"-1.8022744","lat":"43.3422299"}}},{"geometry":{"lng":"-2.69312049872164","lat":"42.868297"},"annotations":{},"bounds":{"southwest":{"lng":"-2.6933154","lat":"42.8681484"},"northeast":{"lat":"42.8684357","lng":"-2.6929252"}},"formatted":"Donostia kalea, Ibaiondo, Vitoria-Gasteiz, Vitoria-Gasteizko Eskualdea / Cuadrilla de Vitoria, Basque Country, Spain, es","components":{"county":"Vitoria-Gasteizko Eskualdea / Cuadrilla de Vitoria","state":"Basque Country","country":"Spain","city":"Vitoria-Gasteiz","suburb":"Ibaiondo","country_code":"es","road":"Donostia kalea"}},{"bounds":{"southwest":{"lng":"-2.6889534","lat":"42.8620967"},"northeast":{"lat":"42.8623764","lng":"-2.6885774"}},"formatted":"Donostia kalea, Lakua, Vitoria-Gasteiz, Vitoria-Gasteizko Eskualdea / Cuadrilla de Vitoria, Basque Country, Spain, es","components":{"county":"Vitoria-Gasteizko Eskualdea / Cuadrilla de Vitoria","state":"Basque Country","country":"Spain","city":"Vitoria-Gasteiz","suburb":"Lakua","country_code":"es","road":"Donostia kalea"},"geometry":{"lat":"42.8622515","lng":"-2.68876582144679"},"annotations":{}},{"annotations":{},"geometry":{"lat":"51.5146888","lng":"-0.1609307"},"components":{"restaurant":"Donostia","country":"United Kingdom","state_district":"Greater London","country_code":"gb","county":"London","state":"England","suburb":"Marylebone","city":"City of Westminster","road":"Great Cumberland Mews"},"formatted":"Donostia, Great Cumberland Mews, Marylebone, City of Westminster, London, Greater London, England, United Kingdom, gb","bounds":{"northeast":{"lng":"-0.1608807","lat":"51.5147388"},"southwest":{"lat":"51.5146388","lng":"-0.1609807"}}},{"geometry":{"lat":43.31283,"lng":-1.97499},"annotations":{},"bounds":{"northeast":{"lng":"-1.92020404339","lat":"43.3401603699"},"southwest":{"lat":"43.2644081116","lng":"-2.04920697212"}},"formatted":"San Sebastian, Gipuzkoa, Basque Country, Spain, Donostia / San Sebasti\u00e1n","components":{"county":"Gipuzkoa","state":"Basque Country","country":"Spain","town":"San Sebastian","local administrative area":"Donostia / San Sebasti\u00e1n"}}],"timestamp":{"created_unix":1402136556,"created_http":"Sat, 07 Jun 2014 10:22:36 GMT"},"licenses":[{"name":"CC-BY-SA","url":"http://creativecommons.org/licenses/by-sa/3.0/"},{"name":"ODbL","url":"http://opendatacommons.org/licenses/odbl/summary/"}]}', ) results = self.geocoder.geocode("Donostia") self.assertTrue( any((abs(result['geometry']['lat'] - 43.300836) < 0.05 and abs(result['geometry']['lng'] - -1.9809529) < 0.05) for result in results), msg="Bad result" ) # test that the results are in unicode self.assertEqual(results[0]['formatted'], six.u('San Sebasti\xe1n, Donostialdea/Donostia-San Sebasti\xe1n, 20001;20002;20003;20004;20005;20006;20007;20008;20009;20010;20011;20012;20013;20014;20015;20016;20017;20018, Basque Country, Spain, es'))
Example #7
Source File: test_registry.py From datapackage-py with MIT License | 6 votes |
def test_init_accepts_urls(): url = 'http://some-place.com/registry.json' body = """ [ { "id": "data-package", "title": "Data Package", "schema": "https://specs.frictionlessdata.io/schemas/data-package.json", "schema_path": "data-package.json", "specification": "https://specs.frictionlessdata.io/data-package/" } ] """ httpretty.register_uri(httpretty.GET, url, body=body) registry = datapackage.registry.Registry(url) assert len(registry.available_profiles) == 1 assert registry.available_profiles.get('data-package') == { 'id': 'data-package', 'title': 'Data Package', 'schema': 'https://specs.frictionlessdata.io/schemas/data-package.json', 'schema_path': 'data-package.json', 'specification': 'https://specs.frictionlessdata.io/data-package/', }
Example #8
Source File: test_client.py From edx-analytics-data-api-client with Apache License 2.0 | 6 votes |
def test_request_format(self): httpretty.register_uri(httpretty.GET, self.test_url, body='{}') response = self.client.get(self.test_endpoint) self.assertEqual(httpretty.last_request().headers['Accept'], 'application/json') self.assertDictEqual(response, {}) httpretty.register_uri(httpretty.GET, self.test_url, body='not-json') response = self.client.get(self.test_endpoint, data_format=data_formats.CSV) self.assertEqual(httpretty.last_request().headers['Accept'], 'text/csv') self.assertEqual(response, 'not-json') httpretty.register_uri(httpretty.GET, self.test_url, body='{}') response = self.client.get(self.test_endpoint, data_format=data_formats.JSON) self.assertEqual(httpretty.last_request().headers['Accept'], 'application/json') self.assertDictEqual(response, {})
Example #9
Source File: test_registry.py From datapackage-py with MIT License | 6 votes |
def test_get_loads_remote_file_if_local_copy_doesnt_exist(): registry_body = """ [ { "id": "data-package", "title": "Data Package", "schema": "http://example.com/one.json", "schema_path": "data-package.json", "specification": "https://specs.frictionlessdata.io/data-package/" } ] """ profile_url = 'http://example.com/one.json' profile_body = '{ "profile": "data-package" }' httpretty.register_uri(httpretty.GET, profile_url, body=profile_body) with tempfile.NamedTemporaryFile(suffix='.csv') as tmpfile: tmpfile.write(registry_body.encode('utf-8')) tmpfile.flush() registry = datapackage.registry.Registry(tmpfile.name) base_profile = registry.get('data-package') assert base_profile is not None assert base_profile == {'profile': 'data-package'}
Example #10
Source File: test_package.py From datapackage-py with MIT License | 6 votes |
def test_descriptor_dereferencing_uri_remote(): # Mocks httpretty.register_uri(httpretty.GET, 'http://example.com/schema', body='{"fields": [{"name": "name"}]}') httpretty.register_uri(httpretty.GET, 'https://example.com/dialect', body='{"delimiter": ","}') # Tests descriptor = { 'resources': [ {'name': 'name1', 'data': 'data', 'schema': 'http://example.com/schema'}, {'name': 'name2', 'data': 'data', 'dialect': 'https://example.com/dialect'}, ], } package = Package(descriptor) assert package.descriptor['resources'] == list(map(helpers.expand_resource_descriptor, [ {'name': 'name1', 'data': 'data', 'schema': {'fields': [{'name': 'name'}]}}, {'name': 'name2', 'data': 'data', 'dialect': {'delimiter': ','}}, ]))
Example #11
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 #12
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 #13
Source File: test_course.py From edx-analytics-data-api-client with Apache License 2.0 | 6 votes |
def assertCorrectEnrollmentUrl(self, course, demographic=None): """ Verifies that the enrollment URL is correct. """ uri = self.get_api_url('courses/{0}/enrollment/'.format(course.course_id)) if demographic: uri += '%s/' % demographic httpretty.register_uri(httpretty.GET, uri, body='{}') course.enrollment(demographic) date = '2014-01-01' httpretty.reset() httpretty.register_uri(httpretty.GET, '{0}?start_date={1}'.format(uri, date), body='{}') course.enrollment(demographic, start_date=date) httpretty.reset() httpretty.register_uri(httpretty.GET, '{0}?end_date={1}'.format(uri, date), body='{}') course.enrollment(demographic, end_date=date) httpretty.reset() httpretty.register_uri(httpretty.GET, '{0}?start_date={1}&end_date={1}'.format(uri, date), body='{}') course.enrollment(demographic, start_date=date, end_date=date)
Example #14
Source File: test_sources_rss.py From ThreatIngestor with GNU General Public License v2.0 | 6 votes |
def test_run_respects_feed_type(self): httpretty.register_uri(httpretty.GET, "http://rss.mock/rss.xml", body=self.RSS_CONTENT) messy = threatingestor.sources.rss.Plugin('myrss', 'http://rss.mock/rss.xml', 'messy') clean = threatingestor.sources.rss.Plugin('testrss', 'http://rss.mock/rss.xml', 'clean') afterioc = threatingestor.sources.rss.Plugin('rsss', 'http://rss.mock/rss.xml', 'afterioc') saved_state, artifacts = messy.run(None) self.assertEqual(len(artifacts), 8) self.assertIn('http://example.com/bad/url/10', [str(x) for x in artifacts]) self.assertNotIn('http://example.com/good/url', [str(x) for x in artifacts]) self.assertNotIn('http://example.com/bad/url/00', [str(x) for x in artifacts]) saved_state, artifacts = clean.run(None) self.assertEqual(len(artifacts), 14) self.assertIn('http://example.com/bad/url/10', [str(x) for x in artifacts]) self.assertIn('http://example.com/good/url', [str(x) for x in artifacts]) self.assertIn('http://example.com/bad/url/00', [str(x) for x in artifacts]) saved_state, artifacts = afterioc.run(None) self.assertEqual(len(artifacts), 12) self.assertIn('http://example.com/bad/url/10', [str(x) for x in artifacts]) self.assertNotIn('http://example.com/good/url', [str(x) for x in artifacts]) self.assertIn('http://example.com/bad/url/00', [str(x) for x in artifacts])
Example #15
Source File: test_module.py From edx-analytics-data-api-client with Apache License 2.0 | 6 votes |
def test_grade_distribution_response(self): """ Verifies that the grade distribution responds with the expected values. """ body = [ { 'module_id': self.module_id, 'course_id': self.course_id, 'grade': 0, 'max_grade': 1, 'count': 1, 'created': '2014-01-01T00:01:00' } ] uri = self.get_api_url('problems/{0}/grade_distribution/'.format(self.module_id)) httpretty.register_uri(httpretty.GET, uri, body=json.dumps(body)) self.assertEqual(body, self.module.grade_distribution())
Example #16
Source File: test_module.py From edx-analytics-data-api-client with Apache License 2.0 | 6 votes |
def test_answer_distribution_response(self): """ Verifies that answer distribution responds with the expected values. """ body = [ { 'course_id': self.course_id, 'module_id': self.module_id, 'part_id': self.module_id.replace('/', '-') + '-part1', 'correct': True, 'first_response_count': 2, 'last_response_count': 2, 'value_id': 'choice_4', 'answer_value_text': 'User chose this answer.', 'answer_value_numeric': None, 'variant': 123, 'created': "2014-01-01T00:01:00" } ] uri = self.get_api_url('problems/{0}/answer_distribution/'.format(self.module_id)) httpretty.register_uri(httpretty.GET, uri, body=json.dumps(body)) self.assertEqual(body, self.module.answer_distribution())
Example #17
Source File: test_course.py From edx-analytics-data-api-client with Apache License 2.0 | 6 votes |
def test_videos(self): body = [ { 'pipeline_video_id': '0fac49ba', 'encoded_module_id': 'i4x-a-b-c', 'duration': 600, 'segment_length': 5, 'start_views': 50, 'end_views': 1, 'created': '2015-01-01T00:01:00' } ] uri = self.get_api_url('courses/{0}/videos/'.format(self.course_id)) httpretty.register_uri(httpretty.GET, uri, body=json.dumps(body)) self.assertEqual(body, self.course.videos())
Example #18
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 #19
Source File: test_middleware.py From django-oidc-rp with MIT License | 6 votes |
def test_log_out_the_user_if_the_refresh_token_is_expired(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({'error': 'yes'}), content_type='text/json', status=400) middleware = OIDCRefreshIDTokenMiddleware(lambda r: 'OK') middleware(request) assert not request.user.is_authenticated
Example #20
Source File: test_engagement_timeline.py From edx-analytics-data-api-client with Apache License 2.0 | 6 votes |
def test_engagement_timeline(self): body = { "days": [ { "date": "date", "problems_attempted": 0, "problems_completed": 0, "discussion_contributions": 0, "videos_viewed": 3 } ] } uri = self.get_api_url('engagement_timelines/{username}/?course_id={course_id}' .format(username=self.username, course_id=self.course_id)) httpretty.register_uri(httpretty.GET, uri, body=json.dumps(body)) self.assertEqual(body, self.engagement_timeline.get())
Example #21
Source File: test_module.py From edx-analytics-data-api-client with Apache License 2.0 | 5 votes |
def test_open_distribution_response(self): """ Verifies that open distribution responds with the expected values. """ body = [ { 'course_id': self.course_id, 'module_id': self.module_id, 'count': 123, 'created': '2014-01-01T00:00:00Z' } ] uri = self.get_api_url('problems/{0}/sequential_open_distribution/'.format(self.module_id)) httpretty.register_uri(httpretty.GET, uri, body=json.dumps(body)) self.assertEqual(body, self.module.sequential_open_distribution())
Example #22
Source File: test_registry.py From datapackage-py with MIT License | 5 votes |
def test_init_raises_if_registry_url_webserver_raises_error(): url = 'http://some-place.com/registry.csv' httpretty.register_uri(httpretty.GET, url, status=500) with pytest.raises(RegistryError): datapackage.registry.Registry(url)
Example #23
Source File: __init__.py From edx-analytics-data-api-client with Apache License 2.0 | 5 votes |
def verify_query_params_vs_expected(self, params, expected): """Construct URL with given query parameters and check if it is what we were told to expect.""" httpretty.reset() uri_template = '{uri}?' for key in params: uri_template += '%s={%s}' % (key, key) uri = uri_template.format(uri=self.base_uri, **params) httpretty.register_uri(httpretty.GET, uri, body='{}') getattr(self.client_class, self.endpoint)(**params) self.verify_last_querystring_equal(expected)
Example #24
Source File: test_module.py From edx-analytics-data-api-client with Apache License 2.0 | 5 votes |
def test_video_timeline_response(self): """ Verifies that the video timeline responds with the expected values. """ body = [ { 'segment': 0, 'num_users': 140, 'num_views': 64234, 'created': '2014-01-01T00:01:00' } ] uri = self.get_api_url('videos/{0}/timeline/'.format(self.module_id)) httpretty.register_uri(httpretty.GET, uri, body=json.dumps(body)) self.assertEqual(body, self.module.video_timeline())
Example #25
Source File: test_registry.py From datapackage-py with MIT License | 5 votes |
def test_base_path_is_none_if_registry_is_remote(): url = 'http://some-place.com/registry.json' httpretty.register_uri(httpretty.GET, url, body='[]') registry = datapackage.registry.Registry(url) assert registry.base_path is None
Example #26
Source File: test_module.py From edx-analytics-data-api-client with Apache License 2.0 | 5 votes |
def test_open_distribution_url(self): """ Verifies that the sequential open URL is correct. """ uri = self.get_api_url('problems/{0}/sequential_open_distribution/'.format(self.module_id)) httpretty.register_uri(httpretty.GET, uri, body='{}') self.module.sequential_open_distribution()
Example #27
Source File: __init__.py From edx-analytics-data-api-client with Apache License 2.0 | 5 votes |
def test_url_without_params(self): """Endpoint can be called without parameters.""" httpretty.register_uri(httpretty.GET, self.base_uri, body='{}') getattr(self.client_class, self.endpoint)()
Example #28
Source File: __init__.py From edx-analytics-data-api-client with Apache License 2.0 | 5 votes |
def verify_post_data(self, **kwargs): """Construct POST request with parameters and check if it is what we expect.""" httpretty.reset() httpretty.register_uri(httpretty.POST, self.base_uri, body='{}') getattr(self.client_class, self.endpoint)(**kwargs) expected_body = kwargs.copy() for key, val in expected_body.items(): if not isinstance(val, list): expected_body[key] = [val] actual_body = httpretty.last_request().parsed_body self.assertDictEqual(actual_body or {}, expected_body)
Example #29
Source File: test_course.py From edx-analytics-data-api-client with Apache License 2.0 | 5 votes |
def test_enrollment_data_format(self): uri = self.get_api_url('courses/{0}/enrollment/'.format(self.course.course_id)) httpretty.register_uri(httpretty.GET, uri, body='{}') self.course.enrollment() self.assertEqual(httpretty.last_request().headers['Accept'], 'application/json') httpretty.register_uri(httpretty.GET, uri, body='not-json') self.course.enrollment(data_format=data_formats.CSV) self.assertEqual(httpretty.last_request().headers['Accept'], 'text/csv')
Example #30
Source File: test_module.py From edx-analytics-data-api-client with Apache License 2.0 | 5 votes |
def test_answer_distribution_url(self): """ Verifies that the answer distribution URL is correct. """ uri = self.get_api_url('problems/{0}/answer_distribution/'.format(self.module_id)) httpretty.register_uri(httpretty.GET, uri, body='{}') self.module.answer_distribution()