def fake_response(link, content, **response_data): """A fake response that can be added to the mirror. """ redirects = response_data.pop('redirects', []) # Use the fake internet system to generate a response object. # This is more reliable than putting on together manually. data = {'stream': content} data.update(response_data) with internet(**{link.original_url: data}): session = TestSession() session.mount('http://', TestAdapter()) session.mount('https://', TestAdapter()) response = session.request('GET', link.original_url) # Additional attributes are expected. This is what the spider # does before passing a link to mirror.add(). Possibly we should # have less code duplication here with the actual spider code. parser_class = get_parser_for_mimetype(get_content_type(response)) if parser_class: response.parsed = parser_class(response.content, response.url, encoding=response.encoding) else: response.parsed = None response.links_parsed = HeaderLinkParser(response) response.redirects = redirects return response
def setUp(self): post_save.disconnect(fire_metrics_if_new, sender=Schedule) self.session = TestSession() self.crontab_schedule = CrontabSchedule.objects.create( **{ "minute": '*', "hour": '*', "day_of_week": '*', "day_of_month": '*', "month_of_year": '*', }) self.periodic_crontab_task = PeriodicTask.objects.create( **{ "name": "noop crontab task", "task": "scheduler.tests.noop", "crontab": self.crontab_schedule, "enabled": True, "args": '["hello world"]', }) self.interval_schedule = IntervalSchedule.objects.create( **{ 'every': 5, 'period': 'minutes', }) self.periodic_interval_task = PeriodicTask.objects.create( **{ 'name': 'noop interval task', 'task': 'scheduler.tests.noop', 'interval': self.interval_schedule, 'enabled': True, 'args': '["hello world"]', })
def testSession(self): s = TestSession() self.assertEqual([], list(s.adapters)) s.mount('http://git', TestAdapter(b'git')) s.mount('http://github', TestAdapter(b'github')) s.mount('http://github.com', TestAdapter(b'github.com')) s.mount('http://github.com/about/', TestAdapter(b'github.com/about')) order = [ 'http://github.com/about/', 'http://github.com', 'http://github', 'http://git', ] self.assertEqual(order, list(s.adapters)) s.mount('http://gittip', TestAdapter(b'gittip')) s.mount('http://gittip.com', TestAdapter(b'gittip.com')) s.mount('http://gittip.com/about/', TestAdapter(b'gittip.com/about')) order = [ 'http://github.com/about/', 'http://gittip.com/about/', 'http://github.com', 'http://gittip.com', 'http://github', 'http://gittip', 'http://git', ] self.assertEqual(order, list(s.adapters)) s2 = requests.Session() s2.adapters = {'http://': TestAdapter(b'http')} s2.mount('https://', TestAdapter(b'https')) self.assertTrue('http://' in s2.adapters) self.assertTrue('https://' in s2.adapters)
def setUp(self): self.contacts_data = {} self.groups_data = {} self.contacts_backend = FakeContactsApi( "go/", self.AUTH_TOKEN, self.contacts_data, self.groups_data, contacts_limit=self.MAX_CONTACTS_PER_PAGE) self.session = TestSession() self.adapter = FakeContactsApiAdapter(self.contacts_backend) self.simulate_api_up()
def setUp(self): self.messageset_data = {} self.schedule_data = {} self.message_data = {} self.binary_content_data = {} self.contentstore_backend = FakeContentStoreApi( "contentstore/", self.AUTH_TOKEN, messageset_data=self.messageset_data, schedule_data=self.schedule_data, message_data=self.message_data, binary_content_data=self.binary_content_data) self.session = TestSession() adapter = FakeContentStoreApiAdapter(self.contentstore_backend) self.session.mount(self.API_URL, adapter) self.client = self.make_client()
def setUp(self): self.account_backend = FakeAccountApi("go/", self.AUTH_TOKEN) self.session = TestSession() self.adapter = FakeAccountApiAdapter(self.account_backend) self.simulate_api_up()
def __init__(self, test_case, api_url='http://example.com/api/v1'): self.test_case = test_case self.api_url = api_url self.session = TestSession() self._patches = []
def setUp(self): self.client = APIClient() self.adminclient = APIClient() self.session = TestSession()
def setUp(self): self.session = TestSession() self.client = MetricsApiClient(auth_token="auth-token", api_url="http://example.com/api/v1/go", session=self.session)
def make_session(pmr_info=None): session = TestSession() for url, adapter in endpoints: session.mount(url, adapter) return session