当前位置: 首页>>代码示例>>Python>>正文


Python Mock.value方法代码示例

本文整理汇总了Python中mock.Mock.value方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.value方法的具体用法?Python Mock.value怎么用?Python Mock.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mock.Mock的用法示例。


在下文中一共展示了Mock.value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_restructure_layout_preferences_forwards

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
    def test_restructure_layout_preferences_forwards(self):

        empty_workspace = Mock()
        empty_workspace_layout_pref = Mock()
        empty_workspace_layout_preferences = TestQueryResult([])
        empty_workspace.workspacepreference_set.filter.side_effect = (
            lambda **kwargs: empty_workspace_layout_pref
            if kwargs.get("name") == "layout"
            else empty_workspace_layout_preferences
        )
        empty_workspace.tab_set.all.return_value = TestQueryResult([])

        workspace = Mock()
        workspace_layout_pref = Mock()
        workspace_columns_pref = Mock()
        workspace_columns_pref.name = "columns"
        workspace_columns_pref.value = 15
        workspace_layout_preferences = TestQueryResult([workspace_columns_pref])
        workspace.workspacepreference_set.filter.side_effect = (
            lambda **kwargs: workspace_layout_pref
            if kwargs.get("name", "") == "layout"
            else workspace_layout_preferences
        )

        workspace_tab = Mock()
        workspace_tab_layout_pref = Mock()
        workspace_tab_columns_pref = Mock()
        workspace_tab_columns_pref.name = "columns"
        workspace_tab_columns_pref.value = 15
        workspace_tab_layout_preferences = TestQueryResult([workspace_tab_columns_pref])
        workspace_tab.tabpreference_set.filter.side_effect = (
            lambda **kwargs: workspace_tab_layout_pref
            if kwargs.get("name", "") == "layout"
            else workspace_tab_layout_preferences
        )

        workspace_empty_tab = Mock()
        workspace_empty_tab_layout_pref = Mock()
        workspace_empty_tab_layout_preferences = TestQueryResult([])
        workspace_empty_tab.tabpreference_set.filter.side_effect = (
            lambda **kwargs: workspace_empty_tab_layout_pref
            if kwargs.get("name", "") == "layout"
            else workspace_empty_tab_layout_preferences
        )
        workspace.tab_set.all.return_value = TestQueryResult([workspace_empty_tab, workspace_tab])

        migration = self._pick_migration("0016_restructure_layout_preferences")
        orm = Mock(autospec=migration.orm())
        orm.Workspace.objects.all.return_value = TestQueryResult([empty_workspace, workspace])
        migration.migration_instance().forwards(orm)

        self.assertTrue(empty_workspace_layout_pref.update.called)
        self.assertEqual(empty_workspace_layout_preferences.delete.call_count, 0)
        self.assertFalse(empty_workspace.workspacepreference_set.create.called)

        self.assertTrue(workspace_layout_pref.update.called)
        self.assertTrue(workspace_layout_preferences.delete.called)
        self.assertTrue(workspace_tab_layout_preferences.delete.called)
        self.assertFalse(workspace_empty_tab_layout_preferences.delete.called)
        self.assertTrue(workspace.workspacepreference_set.create.called)
开发者ID:ciniguez,项目名称:FIREWA,代码行数:62,代码来源:south_migrations.py

示例2: test_resource_offers_creates_nodes

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
    def test_resource_offers_creates_nodes(self, mock_get_slave):
        mock_get_slave.return_value = SlaveInfo(u'localhost', 5151)
        mock_cpu = Mock()
        mock_cpu.name = u'cpus'
        mock_cpu.value = 10
        
        mock_disk = Mock()
        mock_disk.name = u'disk'
        mock_disk.value = 4000
 
        mock_mem = Mock()
        mock_mem.name = u'mem'
        mock_mem.value = 100000
        
        mock_offer = Mock()
        mock_offer.id.value = 1
        mock_offer.slave_id.value = 1
        mock_offer.hostname.value = u'localhost'
        mock_offer.resources = [mock_cpu, mock_disk, mock_mem]
        offers = [mock_offer]

        my_scheduler, driver, master_info = self._get_mocked_scheduler_driver_master()

        localhost_exists = Node.objects.filter(hostname=u'localhost').exists()
        self.assertFalse(localhost_exists, 'there should not be a node before the first offer')
        my_scheduler.resourceOffers(driver, offers)
        localhost_exists = Node.objects.all().exists()
        self.assertTrue(localhost_exists, 'there should be a node after the first offer')
开发者ID:Carl4,项目名称:scale,代码行数:30,代码来源:test_scheduler.py

示例3: test_hash_function

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
 def test_hash_function(self):
     mock_item_1 = Mock()
     mock_item_1.value = 1
     mock_item_2 = Mock()
     mock_item_2.value = 2
     input_list = [mock_item_1, mock_item_1, mock_item_2, mock_item_2]
     expected = [mock_item_1, mock_item_2]
     self.assertEqual(expected, unique_list_items(input_list, lambda x: x.value))
开发者ID:Januson,项目名称:subscription-manager,代码行数:10,代码来源:test_utils.py

示例4: mock_read

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
 def mock_read(path):
     result = Mock(spec=EtcdResult)
     if path == TEST_HOST_PATH + "/bird_ip":
         result.value = "192.168.24.1"
         return result
     if path == TEST_HOST_PATH + "/bird6_ip":
         result.value = "fd30:4500::1"
         return result
     assert False
开发者ID:chuckbutler,项目名称:calico-docker,代码行数:11,代码来源:datastore_test.py

示例5: test_got_csrf

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
	def test_got_csrf(self):
		cookie1 = Mock()
		cookie1.name = 'csrftoken'
		cookie1.value = 'csrf value 1'
		cookie1.domain = 'other domain'
		cookie2 = Mock()
		cookie2.name = 'csrftoken'
		cookie2.value = 'csrf value 2'
		cookie2.domain = 'test.trigger.io'
		self.remote.cookies = [cookie1, cookie2]
		eq_(self.remote._csrf_token(), 'csrf value 2')
开发者ID:mobilipia,项目名称:build-tools,代码行数:13,代码来源:test_remote.py

示例6: test_wait_for_ready

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
 def test_wait_for_ready(self, m_sleep):
     m_resp_1 = Mock()
     m_resp_1.value = "false"
     m_resp_2 = Mock()
     m_resp_2.value = "true"
     responses = [
         etcd.EtcdException(),
         etcd.EtcdKeyNotFound(),
         m_resp_1,
         m_resp_2,
     ]
     self.m_client.read.side_effect = iter(responses)
     self.watcher.wait_for_ready(1)
     self.assertEqual(m_sleep.mock_calls, [call(1)] * 3)
开发者ID:ContainerSolutions,项目名称:calico,代码行数:16,代码来源:test_etcdutils.py

示例7: test_exec_config_with_set_workspaces

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
 def test_exec_config_with_set_workspaces(self):
     """Test exec config with set workspaces subcommand."""
     args = Mock()
     args.action = "set"
     args.key = "workspaces"
     args.value = False
     self.assertFalse(self.subcommand.execute(args))
开发者ID:Numergy,项目名称:yoda,代码行数:9,代码来源:config_test.py

示例8: test_server_sends_marshaled_exception_when_callback_raises_exception

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
    def test_server_sends_marshaled_exception_when_callback_raises_exception(self, mock_command_response):
        request = '{"name": "foobar", "arg": {"arg1": "value"}}'

        expected = '{"error": "raise me!", "value": null}'

        command_response = Mock(CommandResponse)
        command_response.error = "raise me!"
        command_response.value = None
        mock_command_response.return_value = command_response
        callback = Mock(side_effect=BusCtlServerError())

        marshaler = Mock(Marshaler)
        server = BusCtlServer()
        server._marshaler = marshaler

        command = Mock()
        command.name = "foobar"
        marshaler.unmarshal_command.return_value = command
        marshaler.marshal_response.return_value = expected

        command_class = Mock()
        command_class.name = "foobar"

        server.add_command(command_class, callback)

        response = server._process_next_command(request)

        self.assertEqual(response, expected)
        marshaler.marshal_response.assert_called_once_with(command_response)
开发者ID:jlebleu,项目名称:xivo-bus,代码行数:31,代码来源:test_server.py

示例9: test_nested_raw_field

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
 def test_nested_raw_field(self):
     foo = Mock()
     bar = Mock()
     bar.value = 3
     foo.bar = bar
     field = fields.Raw()
     self.assertEquals(field.output("bar.value", foo), 3)
开发者ID:EvaSDK,项目名称:flask-restful,代码行数:9,代码来源:test_fields.py

示例10: mock_read_4_endpoints

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
def mock_read_4_endpoints(path, recursive):
    assert path == ALL_ENDPOINTS_PATH
    assert recursive
    leaves = []

    specs = [
        (CALICO_V_PATH + "/host/TEST_HOST/bird_ip", "192.168.1.1"),
        (CALICO_V_PATH + "/host/TEST_HOST/bird6_ip", "fd80::4"),
        (CALICO_V_PATH + "/host/TEST_HOST/config/marker", "created"),
        (CALICO_V_PATH + "/host/TEST_HOST/workload/docker/1234/endpoint/567890abcdef",
         EP_56.to_json()),
        (CALICO_V_PATH + "/host/TEST_HOST/workload/docker/5678/endpoint/90abcdef1234",
         EP_90.to_json()),
        (CALICO_V_PATH + "/host/TEST_HOST2/bird_ip", "192.168.1.2"),
        (CALICO_V_PATH + "/host/TEST_HOST2/bird6_ip", "fd80::3"),
        (CALICO_V_PATH + "/host/TEST_HOST2/config/marker", "created"),
        (CALICO_V_PATH + "/host/TEST_HOST2/workload/docker/1234/endpoint/7890abcdef12",
         EP_78.to_json()),
        (CALICO_V_PATH + "/host/TEST_HOST2/workload/docker/5678/endpoint/1234567890ab",
         EP_12.to_json())]
    for spec in specs:
        leaf = Mock(spec=EtcdResult)
        leaf.key = spec[0]
        leaf.value = spec[1]
        leaves.append(leaf)

    result = Mock(spec=EtcdResult)
    result.leaves = iter(leaves)
    return result
开发者ID:chuckbutler,项目名称:calico-docker,代码行数:31,代码来源:datastore_test.py

示例11: test_process_event_nolabels

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
    def test_process_event_nolabels(self):
        with patch.object(FabricService.objects, "get_items") as fabric_service_objects, \
                patch.object(Service.objects, "get_items") as service_objects, \
                patch.object(Switch.objects, "get_items") as switch_objects, \
                patch.object(Switch, "save") as switch_save, \
                patch.object(SwitchPort, "save") as switchport_save:
            fabric_service_objects.return_value = [self.fabric_service]
            service_objects.return_value = [self.onos, self.fabric_service]
            switch_objects.return_value = [self.switch]

            event_dict = {"status": "created"}
            event = Mock()
            event.value = json.dumps(event_dict)

            step = self.event_step(model_accessor=self.model_accessor, log=self.log)
            step.process_event(event)

            self.assertEqual(self.switch.backend_code, 1)
            self.assertEqual(self.switch.backend_status, "succeeded")

            switch_save.assert_not_called()

            self.assertEqual(self.port1.backend_code, 1)
            self.assertEqual(self.port1.backend_status, "succeeded")

            self.assertEqual(self.port2.backend_code, 1)
            self.assertEqual(self.port2.backend_status, "succeeded")

            switchport_save.assert_not_called()
开发者ID:opencord,项目名称:fabric,代码行数:31,代码来源:test_kubernetes_event.py

示例12: test_to_json

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
    def test_to_json(self):
        host = "test_host"
        block = AllocationBlock(network, host)

        # Set up an allocation
        attr = {
            AllocationBlock.ATTR_HANDLE_ID: "test_key",
            AllocationBlock.ATTR_SECONDARY: {
                "key1": "value1",
                "key2": "value2"
            }
        }
        block.attributes.append(attr)
        block.allocations[5] = 0
        assert_equal(block.count_free_addresses(), BLOCK_SIZE - 1)

        # Read out the JSON
        json_str = block.to_json()
        json_dict = json.loads(json_str)
        assert_equal(json_dict[AllocationBlock.CIDR], str(network))
        assert_equal(json_dict[AllocationBlock.AFFINITY], "host:test_host")
        assert_dict_equal(json_dict[AllocationBlock.ATTRIBUTES][0],
                          attr)
        expected_allocations = [None] * BLOCK_SIZE
        expected_allocations[5] = 0
        assert_list_equal(json_dict[AllocationBlock.ALLOCATIONS],
                          expected_allocations)

        # Verify we can read the JSON back in.
        result = Mock(spec=EtcdResult)
        result.value = json_str
        block2 = AllocationBlock.from_etcd_result(result)
        assert_equal(block2.to_json(), json_str)
开发者ID:cheuschober,项目名称:libcalico,代码行数:35,代码来源:block_test.py

示例13: test_exec_config_with_set

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
 def test_exec_config_with_set(self):
     """Test exec config with set subcommand."""
     args = Mock()
     args.action = "set"
     args.key = "logfile"
     args.value = "/tmp/yoda.log"
     self.subcommand.execute(args)
     self.assertEqual("/tmp/yoda.log", self.config["logfile"])
开发者ID:Numergy,项目名称:yoda,代码行数:10,代码来源:config_test.py

示例14: test_get_stack_parameters_dict_returns_proper_dict

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
    def test_get_stack_parameters_dict_returns_proper_dict(self, _, get_stack_mock):
        cfn = CloudFormation()

        parameter_1 = Mock()
        parameter_1.key = "myKey1"
        parameter_1.value = "myValue1"
        parameter_2 = Mock()
        parameter_2.key = "myKey2"
        parameter_2.value = "myValue2"

        stack_mock = Mock()
        stack_mock.parameters = [parameter_1, parameter_2]
        get_stack_mock.return_value = stack_mock

        result = cfn.get_stack_parameters_dict('foo')

        self.assertDictEqual({'myKey1': 'myValue1', 'myKey2': 'myValue2'}, result)
开发者ID:oliver-schoenherr,项目名称:cfn-sphere,代码行数:19,代码来源:cfn_tests.py

示例15: test_get_cookie

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import value [as 别名]
 def test_get_cookie(self):
     morsel = Mock()
     morsel.value = "value"
     self.rh.request.cookies = {"testcookie": morsel}
     val = self.rh.get_cookie("testcookie")
     self.assertEqual(val, "value")
     val = self.rh.get_cookie("non_existent")
     self.assertEqual(val, None)
开发者ID:flaviogrossi,项目名称:cyclone,代码行数:10,代码来源:test_web.py


注:本文中的mock.Mock.value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。