本文整理汇总了Python中mock.Mock.execute方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.execute方法的具体用法?Python Mock.execute怎么用?Python Mock.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_tables_info_when_no_table_list_is_provided
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def test_get_tables_info_when_no_table_list_is_provided(self):
mocked_table_list_query_cursor = Mock()
mocked_table_list_query_cursor.execute = Mock(return_value=True)
mocked_table_list_query_cursor.fetchall = Mock(return_value=[{'table_name': 'unit'}, {'table_name': 'test'}])
mocked_table_count_query_cursor = Mock()
mocked_table_count_query_cursor.execute = Mock(return_value=True)
mocked_table_count_query_cursor.fetchone = Mock(return_value=[10])
columns = {
'table_name': '',
'column_name': 'column',
'data_type': 'string',
'character_maximum_length': '1',
'is_nullable': 'NO',
'column_default': ''
}
tables_columns = []
columns.update(table_name='unit')
tables_columns.append(columns.copy())
columns.update(table_name='test')
tables_columns.append(columns.copy())
mocked_table_columns_query_cursor = Mock()
mocked_table_columns_query_cursor.execute = Mock(return_value=True)
mocked_table_columns_query_cursor.fetchall = Mock(return_value=tables_columns)
mocked_table_top_query_cursor = Mock()
mocked_table_top_query_cursor.execute = Mock(return_value=True)
mocked_table_top_query_cursor.fetchall = Mock(return_value=[])
mocked_mssql = Mock()
mocked_mssql.cursor = Mock(side_effect=[mocked_table_list_query_cursor, mocked_table_count_query_cursor,
mocked_table_columns_query_cursor, mocked_table_top_query_cursor])
mocked_builder = Mock()
mocked_builder.build = Mock(return_value=mocked_mssql)
expected = {'tables': {'test': {'columns': [{'character_maximum_length': '1',
'column_default': '',
'column_name': 'column',
'data_type': 'string',
'is_nullable': 'NO'}],
'count': 10,
'rows': []},
'unit': {'columns': [{'character_maximum_length': '1',
'column_default': '',
'column_name': 'column',
'data_type': 'string',
'is_nullable': 'NO'}],
'count': 10,
'rows': []}},
'db_connection_string': 'jdbc:sqlserver://test'
}
assert expected == Sqlserver(mocked_builder, self.logger, db_host = 'test').get_all_tables_info(None, None, None)
示例2: make_mock_service
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def make_mock_service(self, project_quota, region_quota):
mock_project_method = Mock()
mock_project_method.execute = Mock(return_value={'quotas': project_quota})
mock_projects = Mock()
mock_projects.get = Mock(return_value=mock_project_method)
mock_region_method = Mock()
mock_region_method.execute = Mock(return_value={'quotas': region_quota})
mock_regions = Mock()
mock_regions.get = Mock(return_value=mock_region_method)
mock_service = Mock()
mock_service.projects = Mock(return_value=mock_projects)
mock_service.regions = Mock(return_value=mock_regions)
return mock_service
示例3: test_grab_new_jobs_with_jobs
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def test_grab_new_jobs_with_jobs(self, job_patch):
mock_row = [Mock(ID=1), Mock(ID=2), None]
cursor = Mock()
cursor.fetchone.side_effect = mock_row
cursor.execute = Mock()
connection = Mock()
connection.cursor.return_value = cursor
job_1 = Mock(id=1, status=1)
job_1.set_status_in_db.return_value = None
job_2 = Mock(id=2, status=1)
job_2.set_status_in_db.return_value = None
job_patch.side_effect = [job_1, job_2]
maker = CDMaker("/audio/", "/ptburn/", "/label/", "conn_string")
return_value = maker.grab_new_jobs(connection)
self.assertEquals(len(return_value), 2)
self.assertEquals(return_value[0].id, 1)
self.assertEquals(job_1.status, 2)
job_1.set_status_in_db.called_once_with(connection)
self.assertEquals(return_value[1].id, 2)
self.assertEquals(job_2.status, 2)
job_2.set_status_in_db.called_once_with(connection)
cursor.execute.called_once_with(CDMaker.GRAB_NEW_JOBS_SQL)
示例4: test_no_logged_user
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def test_no_logged_user(self, cookie_facade):
cmd_mock = Mock()
cmd_mock.execute = Mock(return_value=cmd_mock)
cmd_mock.result = None
cookie_facade.retrive_cookie_data = Mock(return_value=cmd_mock)
result = facade.logged_user(None).execute().result
self.assertIsNone(result)
示例5: test_prepare_conn_execute_the_subnet_actions
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def test_prepare_conn_execute_the_subnet_actions(self):
# Arrage
actions = []
prepare_subnet_sub_a = PrepareSubnet();
prepare_subnet_sub_a.actionId = "SubA"
prepare_subnet_sub_a.actionParams = PrepareSubnetParams()
actions.append(prepare_subnet_sub_a)
prepare_cloud_infra = PrepareCloudInfra()
prepare_cloud_infra.actionId = "Net"
prepare_cloud_infra.actionParams = PrepareCloudInfraParams()
actions.append(prepare_cloud_infra)
prepare_subnet_sub_b = PrepareSubnet();
prepare_subnet_sub_b.actionId = "SubB"
prepare_subnet_sub_b.actionParams = PrepareSubnetParams()
actions.append(prepare_subnet_sub_b)
prepare_create_key = CreateKeys();
prepare_create_key.actionId = "CreateKeys"
actions.append(prepare_create_key)
# Act
with patch('cloudshell.cp.aws.domain.conncetivity.operations.prepare.PrepareSubnetExecutor') as ctor:
obj = Mock()
obj.execute = Mock(return_value=["ResA", "ResB"])
ctor.return_value = obj
results = self.prepare_conn.prepare_connectivity(ec2_client=self.ec2_client,
ec2_session=self.ec2_session,
s3_session=self.s3_session,
reservation=self.reservation,
aws_ec2_datamodel=self.aws_dm,
actions=actions,
cancellation_context=self.cancellation_context,
logger=Mock())
# Assert
self.assertEqual(len(results), 4)
self.assertEqual(results[2], "ResA")
self.assertEqual(results[3], "ResB")
示例6: test_convert
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def test_convert(self, connect, popen, pipe, exists, copy):
sqlite = self.path + "/files/test_thematic_shp_thematic.sqlite"
shapefile = self.path + "/files/shp"
cmd = "ogr2ogr -f 'ESRI Shapefile' {0} {1} -lco ENCODING=UTF-8".format(shapefile, sqlite)
proc = Mock()
exists.return_value = True
conn = Mock()
conn.enable_load_extention = Mock()
connect.return_value = conn
cur = Mock()
conn.cursor = cur
cur.execute = Mock()
popen.return_value = proc
proc.communicate.return_value = (Mock(), Mock())
proc.wait.return_value = 0
# set zipped to False for testing
tags = self.job.categorised_tags
t2s = ThematicSQliteToShp(
sqlite=sqlite, shapefile=shapefile, tags=tags, job_name="test_thematic_shp", zipped=False, debug=True
)
exists.assert_called_twice()
copy.assert_called_once()
out = t2s.convert()
popen.assert_called_once_with(cmd, shell=True, executable="/bin/bash", stdout=pipe, stderr=pipe)
self.assertEquals(out, shapefile)
示例7: _build_mock
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def _build_mock():
fetch_mock = Mock()
fetch_mock.execute = Mock(return_value=fetch_mock)
fetch_mock.result.content = _SUCCESS_PAGSEGURO_XML.encode('ISO-8859-1')
fetch_mock.result.status_code = 200
fetch_mock.errors = {}
fetch_mock.commit = Mock(return_value=[])
return fetch_mock
示例8: setup_base_mock
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def setup_base_mock(self, fetch_command_cls):
app = _setup_app_data()
fetch_cmd_obj = Mock()
fetch_cmd_obj.errors = {}
fetch_cmd_obj.execute = Mock(return_value=fetch_cmd_obj)
fetch_cmd_obj.result.content = json.dumps({'id': "654321", 'email': "[email protected]"})
fetch_command_cls.return_value = fetch_cmd_obj
return app, fetch_cmd_obj, Mock()
示例9: make_fake_conn
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def make_fake_conn(receive_returns=None):
receive_returns = receive_returns or (["{}"], "", 0)
conn = Mock()
conn.return_value = conn
conn.execute = conn
conn.receive = Mock(return_value=receive_returns)
conn.result = Mock(return_value=conn)
return conn
示例10: test_logged_user
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def test_logged_user(self, cookie_facade):
user = mommy.save_one(MainUser)
cmd_mock = Mock()
cmd_mock.execute = Mock(return_value=cmd_mock)
cmd_mock.result = {'id': user.key.id()}
cookie_facade.retrive_cookie_data = Mock(return_value=cmd_mock)
result = facade.logged_user(None).execute().result
self.assertEqual(user, result)
示例11: test_google_user_logged
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def test_google_user_logged(self, facade_mock):
self.set_current_user()
cmd_mock = Mock()
cmd_mock.pending_link = False
execute_mock = Mock()
execute_mock.execute = Mock(return_value=cmd_mock)
facade_mock.login_google = Mock(return_value=execute_mock)
response = google.index(Mock())
self.assertIsInstance(response, RedirectResponse)
示例12: make_fake_conn
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def make_fake_conn(receive_returns=None):
receive_returns = receive_returns or (['{}'], '', 0)
conn = Mock()
conn.return_value = conn
conn.execute = conn
conn.receive = Mock(return_value=receive_returns)
conn.gateway.remote_exec = conn.receive
conn.result = Mock(return_value=conn)
return conn
示例13: make_fake_conn
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def make_fake_conn(receive_returns=None):
receive_returns = receive_returns or ([b'{}'], [], 0)
conn = Mock()
conn.return_value = conn
conn.execute = conn
conn.receive = Mock(return_value=receive_returns)
conn.gateway.remote_exec = conn.receive
conn.result = Mock(return_value=conn)
conn.cmd = lambda x: x
return conn
示例14: create_command
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def create_command(self, name, execute_method=None):
command = Mock()
command.aliases = name
command.matches = Mock()
command.matches.return_value = True
if execute_method:
command.execute = execute_method
return command
示例15: assertions_test
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import execute [as 别名]
def assertions_test(self):
# assert_exception_test
mock_session = Mock(**{'execute.side_effect': AlreadyExists("Dummy exception message.")})
assert_exception(mock_session, "DUMMY QUERY", expected=AlreadyExists)
# assert_unavailable_test
mock_session = Mock(**{'execute.side_effect': Unavailable("Dummy Unavailabile message.")})
assert_unavailable(mock_session.execute)
# assert_invalid_test
mock_session = Mock(**{'execute.side_effect': InvalidRequest("Dummy InvalidRequest message.")})
assert_invalid(mock_session, "DUMMY QUERY")
# assert_unauthorized_test
mock_session = Mock(**{'execute.side_effect': Unauthorized("Dummy Unauthorized message.")})
assert_unauthorized(mock_session, "DUMMY QUERY", None)
# assert_one_test
mock_session = Mock()
mock_session.execute = Mock(return_value=[[1, 1]])
assert_one(mock_session, "SELECT * FROM test", [1, 1])
# assert_none_test
mock_session = Mock()
mock_session.execute = Mock(return_value=[])
assert_none(mock_session, "SELECT * FROM test")
# assert_all_test
mock_session = Mock()
mock_session.execute = Mock(return_value=[[i, i] for i in range(0, 10)])
assert_all(mock_session, "SELECT k, v FROM test", [[i, i] for i in range(0, 10)], ignore_order=True)
# assert_almost_equal_test
assert_almost_equal(1, 1.1, 1.2, 1.9, error=1.0)
# assert_row_count_test
mock_session = Mock()
mock_session.execute = Mock(return_value=[[1]])
assert_row_count(mock_session, 'test', 1)
# assert_length_equal_test
check = [1, 2, 3, 4]
assert_length_equal(check, 4)