本文整理汇总了Python中mock.MagicMock.url方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.url方法的具体用法?Python MagicMock.url怎么用?Python MagicMock.url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_schema
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def test_schema(self, mcharm):
wpmock = MagicMock()
mysqlmock = MagicMock()
wpmock.subordinate = False
wpmock.code_source = {'location':
'lp:~charmers/charms/precise/wordpress/trunk'}
wpmock.requires = {'db': {'interface': 'mysql'}}
wpmock.url = None
mysqlmock.subordinate = False
mysqlmock.code_source = {'location':
'lp:~charmers/charms/precise/mysql/trunk'}
mysqlmock.provides = {'db': {'interface': 'mysql'}}
mysqlmock.url = None
mcharm.side_effect = [mysqlmock, wpmock]
d = Deployment(juju_env='gojuju', sentries=False)
d.add('mysql')
d.configure('mysql', {'tuning': 'fastest'})
d.add('wordpress')
d.relate('mysql:db', 'wordpress:db')
schema = {'gojuju': {'services': {'mysql': {
'branch': 'lp:~charmers/charms/precise/mysql/trunk',
'options': {'tuning': 'fastest'}},
'wordpress': {'branch':
'lp:~charmers/charms/precise/wordpress/trunk'}},
'series': 'precise', 'relations': [['mysql:db', 'wordpress:db']]}}
self.assertEqual(schema, d.schema())
d.cleanup()
示例2: test_missing_keys
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def test_missing_keys(self):
http_session = MagicMock()
response = MagicMock()
http_session.get = MagicMock()
http_session.get.return_value = response
response.status_code = 200
response.content = "{}"
response.url = "http://example.com/?camli.mode=config"
conn = _connect(
'http://example.com/',
http_session=http_session,
)
self.assertEqual(
conn.blob_root,
None,
)
self.assertEqual(
conn.search_root,
None,
)
self.assertEqual(
conn.sign_root,
None,
)
示例3: test_init
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def test_init(self, release_mock):
repo_mock = MagicMock()
repo_mock.description = u'Takes a jinja2 template and some json and sends an email'
repo_mock.forks_count = 1
repo_mock.html_url = u'https://github.com/sanger-pathogens/json2email'
repo_mock.name = u'json2email'
repo_mock.stargazers_count = 1
repo_mock.updated_at = datetime.datetime(2015, 3, 28, 16, 58, 12)
repo_mock.url = u'https://api.github.com/repos/sanger-pathogens/json2email'
repo = RepoParser(repo_mock)
self.assertEqual(repo.name, u'json2email')
self.assertEqual(
repo.description,
u'Takes a jinja2 template and some json and sends an email'
)
self.assertEqual(
repo.html_url,
u'https://github.com/sanger-pathogens/json2email'
)
self.assertEqual(
repo.updated_at,
datetime.datetime(2015, 3, 28, 16, 58, 12)
)
self.assertEqual(repo.stargazers_count, 1)
self.assertEqual(repo.forks_count, 1)
release_mock.assert_called_once_with(
u'https://api.github.com/repos/sanger-pathogens/json2email',
None
)
示例4: test_getters_from_invalid_queue_item
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def test_getters_from_invalid_queue_item():
# First we mock an HTTP 404 error response, which is what the Jenkins
# REST API will return when the endpoint referenced by our queue item
# no longer exists
mock_response = MagicMock()
mock_response.status_code = 404
# Mock a Jenkins REST API object with the relevant structures used by
# our queue item
mock_api = MagicMock()
mock_api.get_api_data.side_effect = HTTPError(response=mock_response)
expected_id = 1234
mock_api.url = "https://jenkins.server/queue/item/" + str(expected_id)
# Flex our code
q1 = QueueItem(mock_api)
# confirm the results
assert q1.uid == expected_id
assert q1.stuck is None
assert q1.blocked is None
assert q1.buildable is None
assert q1.reason is None
assert q1.waiting is None
assert q1.cancelled is None
assert q1.job is None
assert q1.build is None
示例5: test_create_offering
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def test_create_offering(self, resource_exists, make_req_side_effect, exception_text=None, offering_created=False):
# Mock the plugin functions
offering = {'offering': 1}
resource = {'resource': 2}
resource = {
'href': 'href location',
'id': 'resource_id',
'name': 'resource name',
'version': 'resource version'
}
expected_result = BASE_STORE_URL + '/DSProductCatalog/api/catalogManagement/v2/productOffering/:' + resource.get('id')
self.instance._generate_product_info = MagicMock(return_value=resource)
self.instance._get_offering = MagicMock(return_value=offering)
self.instance._get_existing_product = MagicMock(return_value=resource if resource_exists else None)
self.instance._create_product = MagicMock(return_value=resource)
self.instance._rollback = MagicMock()
r = MagicMock(side_effect=make_req_side_effect)
self.instance._make_request = MagicMock(return_value=r)
# Call the function
try:
r.url = expected_result
result = self.instance.create_offering(DATASET, OFFERING_INFO_BASE)
# name = OFFERING_INFO_BASE['name'].replace(' ', '%20')
# Verify that exceptions were not expected
self.assertIsNone(exception_text)
self.assertEquals(expected_result, result)
self.instance._get_existing_product.assert_called_once_with(DATASET)
if not resource_exists:
self.instance._create_product.assert_called_once_with(
DATASET, OFFERING_INFO_BASE)
self.instance._get_offering.assert_called_once_with(OFFERING_INFO_BASE, resource)
def check_make_request_calls(call, method, url, headers, data):
self.assertEquals(method, call[0][0])
self.assertEquals(url, call[0][1])
self.assertEquals(headers, call[0][2])
self.assertEquals(data, call[0][3])
call_list = self.instance._make_request.call_args_list
base_url = BASE_STORE_URL
headers = {'Content-Type': 'application/json'}
check_make_request_calls(
call_list[0],
'post',
'%s/DSProductCatalog/api/catalogManagement/v2/catalog/%s/productOffering/' % (
base_url, OFFERING_INFO_BASE['catalog']),
headers,
offering)
except store_connector.StoreException as e:
self.instance._rollback.assert_called_once_with(OFFERING_INFO_BASE, offering_created)
self.assertEquals(e.message, exception_text)
示例6: test_mod_link_hide_event
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def test_mod_link_hide_event(self):
host = "reddit.com"
actor = FakeAccount(_id=123456, name="Hider")
link = MagicMock(name="link")
context = MagicMock(name="context")
request = MagicMock(name="request", host=host)
request.parsed_agent.app_name = None
base_url = '/base/url'
request.referrer = "https://www.reddit.com/"
link.url = 'https://www.reddit.com/r/testing/comments/13st/test'
parent_sr = link.subreddit_slow
parent_sr._id = link.sr_id
parent_sr.is_moderator = lambda u: MagicMock(name='sr_mod_rel')
link_author = link.author_slow
g.events.hide_link_event(actor, link, base_url,
request=request, context=context)
g.events.queue_production.assert_event_item(
{
'event_topic': 'flatlist_events',
'event_type': 'ss.post_flatlist',
'payload': {
'app_name': host,
'base_url': base_url,
'is_target_author': False,
'is_sr_moderator': True,
'process_notes': 'hide',
'sr_id': parent_sr._id,
'sr_name': parent_sr.name,
'target_created_ts': 1,
'target_author_name': link_author.name,
'target_fullname': link._fullname,
'target_id': link._id,
'target_url': link.url,
'target_url_domain': 'www.reddit.com',
'user_id': actor._id,
'user_name': actor.name,
'domain': request.host,
'oauth2_client_app_type': context.oauth2_client.app_type,
'obfuscated_data': {
'client_ip': request.ip,
},
'oauth2_client_id': context.oauth2_client._id,
'user_features': context.user.user_features,
'oauth2_client_name': context.oauth2_client.name,
'referrer_domain': self.domain_mock(),
'referrer_url': request.headers.get('Referer'),
'session_referrer_domain': self.domain_mock(),
'user_agent': request.user_agent,
'user_agent_parsed': request.parsed_agent.to_dict(),
'geoip_country': context.location,
},
}
)
示例7: test_list_file_info_http
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def test_list_file_info_http(self, requests_mock, re_mock):
retval = MagicMock(spec=requests.models.Response)
retval.url = 'http://marine.rutgers.edu/cool/maracoos/codar/ooi/radials/BELM/'
retval.content = '<http><body>' \
'<a href="RDLm_BELM_2012_08_14_1200.ruv">RDLm_BELM_2012_08_14_1200.ruv</a> ' \
'14-Aug-2012 08:42 88K \n<img src="/icons/unknown.gif" alt="[ ]"> ' \
'<a href="RDLm_BELM_2012_08_14_1300.ruv">RDLm_BELM_2012_08_14_1300.ruv</a> ' \
'14-Aug-2012 09:41 90K \n</body></html>'
requests_mock.return_value = retval
re_mock.return_value = ['RDLm_BELM_2012_08_14_1200.ruv', 'RDLm_BELM_2012_08_14_1300.ruv']
lst = [('http://marine.rutgers.edu/cool/maracoos/codar/ooi/radials/BELM/RDLm_BELM_2012_08_14_1200.ruv',),
('http://marine.rutgers.edu/cool/maracoos/codar/ooi/radials/BELM/RDLm_BELM_2012_08_14_1300.ruv',)]
self.assertEqual(list_file_info_http(base='http://marine.rutgers.edu/cool/maracoos/codar/ooi/radials/BELM/', pattern='*.ruv'), lst)
示例8: make_request
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def make_request(secure, host, path, params):
request = MagicMock()
# Generate the string of paramaters1
params_str = ''
for param in params:
params_str += '%s=%s&' % (param, params[param])
secure = 's' if secure else ''
request.url = 'http%s://%s/%s?%s' % (secure, host, path, params_str)
request.host = host
request.host_url = 'http%s://%s' % (secure, host)
request.params = params
return request
示例9: test_get_sbuffer_http
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def test_get_sbuffer_http(self, requests_mock, get_type_mock, StringIO_mock):
retval = MagicMock(spec=requests.models.Response)
retval.url = 'http://marine.rutgers.edu/cool/maracoos/codar/ooi/radials/BELM/'
retval.content = '<http><body>'\
'<a href="RDLm_BELM_2012_08_14_1200.ruv">RDLm_BELM_2012_08_14_1200.ruv</a> '\
'14-Aug-2012 08:42 88K \n<img src="/icons/unknown.gif" alt="[ ]"> '\
'<a href="RDLm_BELM_2012_08_14_1300.ruv">RDLm_BELM_2012_08_14_1300.ruv</a> '\
'14-Aug-2012 09:41 90K \n</body></html>'
requests_mock.return_value = retval
get_type_mock.return_value = 'http'
StringIO_mock.return_value = MagicMock(spec=StringIO)
self.assertTrue(isinstance(get_sbuffer(url=retval.url), StringIO))
示例10: test_team_add_ok_url
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def test_team_add_ok_url(self):
self.db.v1_channel_settings.find_one.return_value = None
team = MagicMock()
team.url = 'http://example.com/'
team.Rooms = []
self.v1.Team.where().first.return_value = team
d = self._test_command(
'teams add team name',
)
def check(res):
# call_args[0] ==> *args
self.assertEqual(self.db.v1_channel_settings.save.call_args[0][0]['teams']['team name'], team.url)
self.assertAck()
d.addCallback(check)
return d
示例11: test_last_author_for_topic
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def test_last_author_for_topic(self, m_cO):
ui = MagicMock()
ui.id = 'example'
ui.anonymous = False
ui.url = '/p/example'
ui.name = 'Example Profile'
m_cO.return_value = ui
context = MagicMock()
ts = TopicsSearch(context, MagicMock(), 6, 1)
topic = {'last_post_user_id': 'example', }
r = ts.last_author_for_topic(topic)
m_cO.assert_called_once_with('groupserver.UserFromId', context, 'example')
self.assertIn('id', r)
self.assertIn('name', r)
self.assertIn('exists', r)
self.assertTrue(r['exists'])
self.assertIn('url', r)
示例12: test_not_json
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def test_not_json(self):
http_session = MagicMock()
response = MagicMock()
http_session.get = MagicMock()
http_session.get.return_value = response
response.status_code = 200
response.content = "la la i am not json"
response.url = "http://example.com/?camli.mode=config"
self.assertRaises(
NotCamliServerError,
lambda: _connect(
'http://example.com/',
http_session=http_session,
),
)
示例13: test__get_updated_site_services
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def test__get_updated_site_services(self):
# get the site nodes
node = MagicMock()
node.name = 'mtclone-pyweb01'
node.site_name = 'mtclone'
node.url = 'http://127.0.0.1:6543'
node.ip = '127.0.0.1'
node.pull_services_as_dicts.return_value = {'services': [self.service_as_dict]}
nodes = {
'mtclone-pyweb01': node
}
# build a site without the services
site = Site('mtclone', status='unknown', nodes=nodes)
# get the services for the site
site.services = self.mf._get_updated_site_services(site)
self.assertEqual(len(site.services.keys()), 1)
self.assertEqual(site.services['anweb'].name, 'anweb')
示例14: test_success
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def test_success(self):
http_session = MagicMock()
response = MagicMock()
http_session.get = MagicMock()
http_session.get.return_value = response
response.status_code = 200
response.content = """
{
"blobRoot": "/mock-blobs/",
"searchRoot": "/mock-search/",
"jsonSignRoot": "/mock-sign/"
}
"""
# Act as if we were redirected to example.net
response.url = "http://example.net/?camli.mode=config"
conn = _connect(
'http://example.com/',
http_session=http_session,
)
http_session.get.assert_called_with(
'http://example.com/?camli.mode=config'
)
self.assertEqual(
conn.blob_root,
"http://example.net/mock-blobs/",
)
self.assertEqual(
conn.search_root,
"http://example.net/mock-search/",
)
self.assertEqual(
conn.sign_root,
"http://example.net/mock-sign/",
)
示例15: test_sauthc1signer
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import url [as 别名]
def test_sauthc1signer(self):
r = MagicMock()
r.headers = {}
r.url = 'https://api.stormpath.com/v1/'
r.method = 'GET'
r.body = None
mock_dt = MagicMock()
mock_dt.utcnow.return_value = datetime.datetime(2013, 7, 1,
0, 0, 0, 0)
mock_uuid4 = MagicMock(
return_value='a43a9d25-ab06-421e-8605-33fd1e760825')
s = Sauthc1Signer(id='MyId', secret='Shush!')
with patch('stormpath.auth.datetime', mock_dt):
with patch('stormpath.auth.uuid4', mock_uuid4):
r2 = s(r)
self.assertEqual(r, r2)
self.assertEqual(r.headers['Authorization'],
'SAuthc1 sauthc1Id=MyId/20130701/a43a9d25-ab06-421e-8605-33fd1e760825/sauthc1_request, ' + # noqa
'sauthc1SignedHeaders=host;x-stormpath-date, ' +
'sauthc1Signature=990a95aabbcbeb53e48fb721f73b75bd3ae025a2e86ad359d08558e1bbb9411c') # noqa