Here are the examples of the python api scrape.Session taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
7 Examples
3
Example 1
def __init__(self, conf):
super(CreateRecordsLoadTest, self).__init__('create_record', conf)
repo_exists = self.conf['repo'] in model.Repo.list()
if not self.conf['test_mode'] and repo_exists:
raise Exception(
'"create" task must be done against a new repository, but a '
'repository "%s" already exists. If you really want to do '
'this, set "test_mode" to true in the config JSON.'
% self.conf['repo'])
if not repo_exists:
self.create_repo(self.conf['repo'])
scraper = scrape.Session(verbose=1)
self.create_page = scraper.go(
'%s/%s/create?role=provide'
% (self.conf['base_url'], self.conf['repo']))
3
Example 2
def __init__(self, conf):
super(SearchRecordsLoadTest, self).__init__('search_record', conf)
assert self.conf['repo'] in model.Repo.list(), (
'Repository "%s" doesn\'t exist.' % self.conf['repo'])
scraper = scrape.Session(verbose=1)
self.search_page = scraper.go(
'%s/%s/query?role=seek'
% (self.conf['base_url'], self.conf['repo']))
3
Example 3
def execute_one(self, query):
status = None
try:
logging.info('Search record: %s', query)
scraper = scrape.Session(verbose=1)
scraper.go(self.search_page)
scraper.submit(
scraper.doc.cssselect_one('form'),
query=query)
status = scraper.status
finally:
self.data['http_statuses'].append(status)
2
Example 4
def execute_one(self, name):
status = None
try:
logging.info('Create record: %s', name)
# Creates a new scrape.Session instance here because scrape.Session
# is not thread-safe. Note that this scraper.go() doesn't cause
# extra HTTP request.
scraper = scrape.Session(verbose=1)
scraper.go(self.create_page)
(given_name, family_name) = name.split(' ')
scraper.submit(
scraper.doc.cssselect_one('form'),
given_name=given_name,
family_name=family_name,
author_name='load_test.py',
text='This is a record created by load_test.py.')
status = scraper.status
finally:
self.data['http_statuses'].append(status)
0
Example 5
def setUp(self):
"""Sets up a scrape Session for each test."""
# See http://zesty.ca/scrape for docuementation on scrape.
self.s = scrape.Session(verbose=1)
self.set_utcnow_for_test(ServerTestsBase.TEST_TIMESTAMP, flush='*')
0
Example 6
def setUp(self):
"""Sets up a scrape Session for each test."""
self.s = scrape.Session(verbose=1)
0
Example 7
Project: personfinder Source File: read_only_tests.py
def test_language_cookie_caching(self):
"""Regression test for caching the wrong language."""
# Run a session where the default language is English
en_session = self.s = scrape.Session(verbose=1)
doc = self.go('/haiti?lang=en') # sets cookie
assert 'I\'m looking for someone' in doc.text
doc = self.go('/haiti')
assert 'I\'m looking for someone' in doc.text
# Run a separate session where the default language is French
fr_session = self.s = scrape.Session(verbose=1)
doc = self.go('/haiti?lang=fr') # sets cookie
assert 'Je recherche une personne' in doc.text
doc = self.go('/haiti')
assert 'Je recherche une personne' in doc.text
# Check that this didn't screw up the language for the other session
self.s = en_session
doc = self.go('/haiti')
assert 'I\'m looking for someone' in doc.text