本文整理汇总了Python中unittest.mock.MagicMock.data方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.data方法的具体用法?Python MagicMock.data怎么用?Python MagicMock.data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mock_sign
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def mock_sign(success):
if success:
result = MagicMock(gnupg.Sign)
result.ok = True
result.data = b'ladida'
else:
result = MagicMock(gnupg.Sign)
result.ok = False
return MagicMock(return_value=result)
示例2: mock_encrypt
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def mock_encrypt(success):
if success:
result = MagicMock(gnupg.Crypt)
result.ok = True
result.data = b"blabla"
else:
result = MagicMock(gnupg.Crypt)
result.ok = False
return MagicMock(return_value=result)
示例3: test_activate_elements_no_list
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def test_activate_elements_no_list(self, mock_object):
mock_object.return_value.config = {
'3979c9fc3bee432fb25f354d6b4868b3': {
'name': 'test_projector_element_ahshaiTie8xie3eeThu9',
'test_key_ohwa7ooze2angoogieM9': 'test_value_raiL2ohsheij1seiqua5'}}
request = MagicMock()
request.data = {'name': 'new_test_projector_element_buuDohphahWeeR2eeQu0'}
self.viewset.request = request
with self.assertRaises(ValidationError):
self.viewset.activate_elements(request=request, pk=MagicMock())
示例4: test_activate_elements
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def test_activate_elements(self, mock_object):
mock_object.return_value.config = {
'6165b44cd0f34b44b1ed41565529d798': {
'name': 'test_projector_element_Du4tie7foosahnoofahg',
'test_key_Eek8eipeingulah3aech': 'test_value_quuupaephuY7eoLohbee'}}
request = MagicMock()
request.data = [{'name': 'new_test_projector_element_el9UbeeT9quucesoyusu'}]
self.viewset.request = request
self.viewset.activate_elements(request=request, pk=MagicMock())
self.assertEqual(len(mock_object.return_value.config), 2)
示例5: test_deactivate_elements_no_list
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def test_deactivate_elements_no_list(self, mock_object):
mock_object.return_value.config = [{
'name': 'test_projector_element_Au1ce9nevaeX7zo4ye2w',
'test_key_we9biiZ7bah4Sha2haS5': 'test_value_eehoipheik6aiNgeegor',
'uuid': '0f3b8f8df38b4bbc90f4beba9393d2db'}]
request = MagicMock()
request.data = 'bad_value_no_list_ohchohWee1fie0SieTha'
self.viewset.request = request
with self.assertRaises(ValidationError):
self.viewset.deactivate_elements(request=request, pk=MagicMock())
示例6: test_deactivate_elements
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def test_deactivate_elements(self, mock_object):
mock_object.return_value.config = {
'874aaf279be346ff85a9b456ce1d1128': {
'name': 'test_projector_element_c6oohooxugiphuuM6Wee',
'test_key_eehiloh7mibi7ur1UoB1': 'test_value_o8eig1AeSajieTh6aiwo'}}
request = MagicMock()
request.data = ['874aaf279be346ff85a9b456ce1d1128']
self.viewset.request = request
self.viewset.deactivate_elements(request=request, pk=MagicMock())
self.assertEqual(len(mock_object.return_value.config), 0)
示例7: test_activate_elements_bad_element
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def test_activate_elements_bad_element(self, mock_object):
mock_object.return_value.config = {
'374000ee236a41e09cce22ffad29b455': {
'name': 'test_projector_element_ieroa7eu3aechaip3eeD',
'test_key_mie3Eeroh9rooKeinga6': 'test_value_gee1Uitae6aithaiphoo'}}
request = MagicMock()
request.data = [{'bad_quangah1ahoo6oKaeBai': 'value_doh8ahwe0Zooc1eefu0o'}]
self.viewset.request = request
with self.assertRaises(ValidationError):
self.viewset.activate_elements(request=request, pk=MagicMock())
示例8: test_deactivate_elements_wrong_element
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def test_deactivate_elements_wrong_element(self, mock_object):
mock_object.return_value.config = {
'd867b2557ad041b8848e95981c5671b7': {
'name': 'test_projector_element_c6oohooxugiphuuM6Wee',
'test_key_eehiloh7mibi7ur1UoB1': 'test_value_o8eig1AeSajieTh6aiwo'}}
request = MagicMock()
request.data = ['1179ea09ba2b4559a41272efb1346c86'] # Wrong UUID.
self.viewset.request = request
with self.assertRaises(ValidationError):
self.viewset.deactivate_elements(request=request, pk=MagicMock())
示例9: test_deactivate_elements_bad_list
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def test_deactivate_elements_bad_list(self, mock_object):
mock_object.return_value.config = [{
'name': 'test_projector_element_teibaeRaim1heiCh6Ohv',
'test_key_uk7wai7eiZieQu0ief3': 'test_value_eeghisei3ieGh3ieb6ae',
'uuid': '8ae42a09f585480e8b4a53194d4d1fba'}]
request = MagicMock()
# Value 1 is not an dictionary so we expect ValidationError.
request.data = [1]
self.viewset.request = request
with self.assertRaises(ValidationError):
self.viewset.deactivate_elements(request=request, pk=MagicMock())
示例10: test_prune_elements
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def test_prune_elements(self, mock_object):
mock_object.return_value.config = {
'5460383449024dd99b04e8747d7764d5': {
'name': 'test_projector_element_Oc7OhXeeg0poThoh8boo',
'test_key_ahNei1ke4uCio6uareef': 'test_value_xieSh4yeemaen9oot6ki'}}
request = MagicMock()
request.data = [{
'name': 'test_projector_element_bohb1phiebah5TeCei1N',
'test_key_gahSh9otu6aeghaiquie': 'test_value_aeNgee2Yeeph4Ohru2Oo'}]
self.viewset.request = request
self.viewset.prune_elements(request=request, pk=MagicMock())
self.assertEqual(len(mock_object.return_value.config), 1)
示例11: receive
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def receive():
nonlocal call
call += 1
if call == 1:
response = MagicMock()
response.data = '{"action": "ping", "event": {"cpu_usage_percent": 35.7, "memory_usage_percent": 80.7}}'
response.tp = aiohttp.WSMsgType.text
return response
else:
response = MagicMock()
response.tp = aiohttp.WSMsgType.closed
return response
示例12: test_update_elements_wrong_element
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def test_update_elements_wrong_element(self, mock_object):
mock_object.return_value.config = {
'5b5e5d3b35de4fff873925296c3093fc': {
'name': 'test_projector_element_njb657djcsjdmgfnffkm',
'test_key_uhilo7mir1Uoee7ibhB1': 'test_value_hjrnsmbhfn5zwakbig88'}}
request = MagicMock()
request.data = {
'255fda68ca6f4f3f803b98405abfb710': {
'name': 'test_projector_element_wxrvhn67eebmfjjnkvds'}}
self.viewset.request = request
with self.assertRaises(ValidationError):
self.viewset.update_elements(request=request, pk=MagicMock())
示例13: mock_decrypt
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def mock_decrypt(encryption_status, signature_status, data=b"blabla"):
if encryption_status == Encryption.correct:
if signature_status == Signature.correct:
result = MagicMock(gnupg.Crypt)
result.status = 'decryption ok'
result.trust_text = 'much trusted'
result.data = data
if signature_status == Signature.incorrect:
result = MagicMock(gnupg.Crypt)
result.status = 'decryption ok'
result.trust_text = None
result.data = b'-----BEGIN PGP SIGNATURE-----'
if signature_status == Signature.missing:
result = MagicMock(gnupg.Crypt)
result.status = 'decryption ok'
result.trust_text = None
result.data = data
if encryption_status == Encryption.incorrect:
result = MagicMock(gnupg.Crypt)
result.status = 'decryption failed'
if encryption_status == Encryption.missing:
if signature_status == Signature.correct:
result = MagicMock(gnupg.Verify)
result.status = 'signature valid'
if signature_status == Signature.incorrect:
result = MagicMock(gnupg.Verify)
result.status = 'no public key'
if signature_status == Signature.missing:
result = MagicMock(gnupg.Verify)
result.status = 'no data was provided'
result.trust_text = None
return MagicMock(return_value=result)
示例14: test_prune_elements_with_stable
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def test_prune_elements_with_stable(self, mock_object):
mock_object.return_value.config = {
'e7f91680cd9343dba1416f14871b8e3b': {
'name': 'test_projector_element_aegh2aichee9nooWohRu',
'test_key_wahlaelahwaeNg6fooH7': 'test_value_taePie9Ohxohja4ugisa',
'stable': True}}
request = MagicMock()
request.data = [{
'name': 'test_projector_element_yei1Aim6Aed1po8eegh2',
'test_key_mud1shoo8moh6eiXoong': 'test_value_shugieJier6agh1Ehie3'}]
self.viewset.request = request
self.viewset.prune_elements(request=request, pk=MagicMock())
self.assertEqual(len(mock_object.return_value.config), 2)
示例15: test_update_elements
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import data [as 别名]
def test_update_elements(self, mock_object):
mock_object.return_value.config = {
'aacbb64acafc4ccc957240c871d4e77d': {
'name': 'test_projector_element_jbmgfnf657djcnsjdfkm',
'test_key_7mibir1Uoee7uhilohB1': 'test_value_mbhfn5zwhakbigjrns88'}}
request = MagicMock()
request.data = {
'aacbb64acafc4ccc957240c871d4e77d': {
'name': 'test_projector_element_wdsexrvhgn67ezfjnfje'}}
self.viewset.request = request
self.viewset.update_elements(request=request, pk=MagicMock())
self.assertEqual(len(mock_object.return_value.config), 1)
self.assertEqual(mock_object.return_value.config[
'aacbb64acafc4ccc957240c871d4e77d']['name'], 'test_projector_element_wdsexrvhgn67ezfjnfje')