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


Python Mock.status方法代码示例

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


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

示例1: testGetSuggestedInstancesTwoDifferentSize

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
  def testGetSuggestedInstancesTwoDifferentSize(self, getRDSInstancesMock):
    region = "us-west-2"
    # Instance 1
    instanceMock1 = Mock(spec="boto.rds.dbinstance.DBInstance")
    instanceMock1.status = "available"
    instanceMock1.allocated_storage = 64.0
    instanceMock1.id = "testId1"
    # Instance 2
    instanceMock2 = Mock(spec="boto.rds.dbinstance.DBInstance")
    instanceMock2.status = "available"
    instanceMock2.allocated_storage = 65.0
    instanceMock2.id = "testId2"

    getRDSInstancesMock.return_value = [
        instanceMock1,
        instanceMock2,
    ]

    suggestions = rds_utils.getSuggestedInstances(region)
    self.assertIsInstance(suggestions, types.GeneratorType)
    suggestions = list(suggestions)

    self.assertSequenceEqual(suggestions, [
        {"id": "testId2", "name": "testId2", "namespace": "AWS/RDS",
         "region": region},
        {"id": "testId1", "name": "testId1", "namespace": "AWS/RDS",
         "region": region},
    ])
    getRDSInstancesMock.assert_call_once_with(region)
开发者ID:darreldonnelly,项目名称:numenta-apps,代码行数:31,代码来源:rds_utils_test.py

示例2: test_catter

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
def test_catter():
    fs = Filesystem(DB(':memory:'))
    fs.root().add_file('zeroes', [test_asset_ids], 130)

    asset = Mock()
    asset.__enter__ = Mock(return_value=asset)
    asset.__exit__ = Mock(return_value=False)
    asset.status = Mock(return_value=proto.AssetStatus(size=1024 * 1024, status=proto.SUCCESS))
    asset.__iter__ = Mock(return_value=('\x00' * (128 * 1024) for _ in range(8)))

    bithorde = Mock()
    bithorde.open = Mock(return_value=asset)
    cat = Cat(fs, bithorde)

    sha = sha1()
    for chunk in cat(P('zeroes')):
        sha.update(chunk)
    assert_equals(sha.hexdigest(), '3b71f43ff30f4b15b5cd85dd9e95ebc7e84eb5a3')

    with assert_raises(FNotFound):
        for chunk in cat(P('NON-EXISTING')):
            pass

    asset.status = Mock(return_value=proto.AssetStatus(status=proto.NOTFOUND))
    with assert_raises(NotFoundError):
        for chunk in cat(P('zeroes')):
            pass
开发者ID:rawler,项目名称:bhindex,代码行数:29,代码来源:cat_test.py

示例3: test_request

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
    def test_request(self):
        self.hc.USER_AGENT = "user-agent"
        resp = Mock()
        body = Mock()
        resp.status = 200
        httplib2.Http.request = Mock(return_value=(resp, body))
        self.hc.morph_response_body = Mock(return_value=body)
        r, b = self.hc.request()
        self.assertEqual(resp, r)
        self.assertEqual(body, b)
        self.assertEqual((resp, body), self.hc.last_response)

        httplib2.Http.request = Mock(return_value=(resp, None))
        r, b = self.hc.request()
        self.assertEqual(resp, r)
        self.assertEqual(None, b)

        status_list = [400, 401, 403, 404, 408, 409, 413, 500, 501]
        for status in status_list:
            resp.status = status
            self.assertRaises(ValueError, self.hc.request)

        exception = exceptions.ResponseFormatError
        self.hc.morph_response_body = Mock(side_effect=exception)
        self.assertRaises(Exception, self.hc.request)
开发者ID:DJohnstone,项目名称:python-troveclient,代码行数:27,代码来源:test_client.py

示例4: create_mock_scheduled_tasks

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
 def create_mock_scheduled_tasks(cls):
     jobs = []
     for name in ["foo", "bar", "baz"]:
         job = Mock()
         job.key = JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name)
         job.failure_count = 0
         job.assignedTask = Mock(spec=AssignedTask)
         job.assignedTask.slaveHost = "slavehost"
         job.assignedTask.task = Mock(spec=TaskConfig)
         job.assignedTask.task.maxTaskFailures = 1
         job.assignedTask.task.executorConfig = Mock(spec=ExecutorConfig)
         job.assignedTask.task.executorConfig.data = Mock()
         job.assignedTask.task.metadata = []
         job.assignedTask.task.owner = Identity(role="mchucarroll")
         job.assignedTask.task.environment = "test"
         job.assignedTask.task.jobName = "woops"
         job.assignedTask.task.numCpus = 2
         job.assignedTask.task.ramMb = 2
         job.assignedTask.task.diskMb = 2
         job.assignedTask.instanceId = 4237894
         job.assignedTask.assignedPorts = None
         job.status = ScheduleStatus.RUNNING
         mockEvent = Mock(spec=TaskEvent)
         mockEvent.timestamp = 28234726395
         mockEvent.status = ScheduleStatus.RUNNING
         mockEvent.message = "Hi there"
         job.taskEvents = [mockEvent]
         jobs.append(job)
     return jobs
开发者ID:mkacik,项目名称:incubator-aurora,代码行数:31,代码来源:test_diff.py

示例5: create_mock_scheduled_tasks

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
 def create_mock_scheduled_tasks(cls):
   jobs = []
   for name in ['foo', 'bar', 'baz']:
     job = Mock()
     job.key = JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name)
     job.failure_count = 0
     job.assignedTask = Mock(spec=AssignedTask)
     job.assignedTask.slaveHost = 'slavehost'
     job.assignedTask.task = Mock(spec=TaskConfig)
     job.assignedTask.task.maxTaskFailures = 1
     job.assignedTask.task.packagesDEPRECATED = []
     job.assignedTask.task.owner = Identity(role='mchucarroll')
     job.assignedTask.task.environment = 'test'
     job.assignedTask.task.jobName = 'woops'
     job.assignedTask.task.numCpus = 2
     job.assignedTask.task.ramMb = 2
     job.assignedTask.task.diskMb = 2
     job.assignedTask.instanceId = 4237894
     job.assignedTask.assignedPorts = None
     job.status = ScheduleStatus.RUNNING
     mockEvent = Mock(spec=TaskEvent)
     mockEvent.timestamp = 28234726395
     mockEvent.status = ScheduleStatus.RUNNING
     mockEvent.message = "Hi there"
     job.taskEvents = [mockEvent]
     jobs.append(job)
   return jobs
开发者ID:MustafaOrkunAcar,项目名称:incubator-aurora,代码行数:29,代码来源:test_status.py

示例6: test_retry_412_successfull

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
    def test_retry_412_successfull(self, mock_get_connection):
        # this tests the read function when first HTTP request returns a
        # 412 but the second one
        # is successful and returns a 200

        # mock the 412 response
        mockHttpResponse412 = Mock(name="HttpResponse412")
        mockHttpResponse412.getheader.return_value = 1
        mockHttpResponse412.status = 412
        mockHttpResponse412.read.return_value = "Fail"

        # mock the 200 response
        mockHttpResponse200 = Mock(name="HttpResponse200")
        mockHttpResponse200.getheader.return_value = 1
        mockHttpResponse200.status = 200
        mockHttpResponse200.read.return_value = "Testing"
        conn = Connection()
        mockHttpRequest = Mock(name="HttpRequest")

        # set a 412 response first followed by a 200 response
        mockHttpRequest.getresponse = MagicMock(
            side_effect=[mockHttpResponse412, mockHttpResponse200])
        conn.get_connection.return_value = mockHttpRequest
        vofile = vos.VOFile(["Some URL"], conn, "GET")
        vofile.currentRetryDelay = 2
开发者ID:canfar,项目名称:vos,代码行数:27,代码来源:test_vofile.py

示例7: test_step_status_is_collected_and_reported

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
    def test_step_status_is_collected_and_reported(self, format_summary):
        feature = Mock()
        scenario = Mock()
        steps = [Mock(), Mock(), Mock(), Mock(), Mock()]
        steps[0].status = 'failed'
        steps[0].__iter__ = Mock(return_value=iter([]))
        steps[1].status = 'undefined'
        steps[1].__iter__ = Mock(return_value=iter([]))
        steps[2].status = 'passed'
        steps[2].__iter__ = Mock(return_value=iter([]))
        steps[3].status = 'passed'
        steps[3].__iter__ = Mock(return_value=iter([]))
        steps[4].status = None
        steps[4].__iter__ = Mock(return_value=iter([]))
        feature.status = 'failed'
        feature.duration = 12.3
        feature.__iter__ = Mock(return_value=iter([scenario]))
        scenario.status = 'failed'
        scenario.__iter__ = Mock(return_value=iter(steps))

        config = Mock()
        reporter = SummaryReporter(config)

        reporter.feature(feature)
        reporter.end()

        expected = {
            'passed': 2,
            'failed': 1,
            'skipped': 1,
            'untested': 0,
            'undefined': 1,
        }

        eq_(format_summary.call_args_list[2][0], ('step', expected))
开发者ID:eykd,项目名称:behave,代码行数:37,代码来源:test_summary.py

示例8: create_mock_scheduled_tasks

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
 def create_mock_scheduled_tasks(cls):
   jobs = []
   for name in ['foo', 'bar', 'baz']:
     job_key = JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name)
     job = Mock()
     job.key = job_key
     job.failure_count = 0
     job.assignedTask = Mock(spec=AssignedTask)
     job.assignedTask.taskId = 1287391823
     job.assignedTask.slaveHost = 'slavehost'
     job.assignedTask.task = Mock(spec=TaskConfig)
     job.assignedTask.task.executorConfig = Mock()
     job.assignedTask.task.maxTaskFailures = 1
     job.assignedTask.task.metadata = []
     job.assignedTask.task.job = job_key
     job.assignedTask.task.owner = Identity(role=cls.TEST_ROLE)
     job.assignedTask.task.environment = cls.TEST_ENV
     job.assignedTask.task.jobName = name
     job.assignedTask.task.numCpus = 2
     job.assignedTask.task.ramMb = 2
     job.assignedTask.task.diskMb = 2
     job.assignedTask.instanceId = 4237894
     job.assignedTask.assignedPorts = {}
     job.status = ScheduleStatus.RUNNING
     mockEvent = Mock(spec=TaskEvent)
     mockEvent.timestamp = 28234726395
     mockEvent.status = ScheduleStatus.RUNNING
     mockEvent.message = "Hi there"
     job.taskEvents = [mockEvent]
     jobs.append(job)
   return jobs
开发者ID:kevints,项目名称:aurora,代码行数:33,代码来源:test_ssh.py

示例9: test_retry_successfull

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
    def test_retry_successfull(self):
        # this tests the read function when first HTTP request returns a 503 but the second one 
        # is successfull and returns a 200

        # mock the 503 response
        mockHttpResponse503 = Mock(name="HttpResponse503")
        mockHttpResponse503.getheader.return_value = 1
        mockHttpResponse503.status = 503
        mockHttpResponse503.read.return_value = "Fail"
        mockHttpResponse503.len.return_value = 10

        # mock the 200 response
        mockHttpResponse200 = Mock(name="HttpResponse200")
        mockHttpResponse200.getheader.return_value = 1
        mockHttpResponse200.status = 200
        mockHttpResponse200.read.return_value = "Testing"
        mockHttpResponse200.len.return_value = 10
        mockConn = Mock(name="Connection")
        mockHttpRequest = Mock(name="HttpRequest")

        # set a 503 response first followed by a 200 response
        mockHttpRequest.getresponse = MagicMock(name="getresponse mock")
        generator = mockHttpRequest.getresponse.iter.return_value
        iterator = iter([mockHttpResponse503, mockHttpResponse200])
        generator.__iter__.return_value = iterator
        mockConn.getConnection.return_value = mockHttpRequest
        vofile = vos.VOFile(["Some URL"], mockConn, "GET")
开发者ID:NormanHill,项目名称:cadcVOFS,代码行数:29,代码来源:test_vofile.py

示例10: test_delete

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
 def test_delete(self):
     resp = Mock()
     resp.status = 200
     body = None
     self.instances.api.client.delete = Mock(return_value=(resp, body))
     self.instances.delete('instance1')
     resp.status = 500
     self.assertRaises(Exception, self.instances.delete, 'instance1')
开发者ID:jcru,项目名称:python-troveclient,代码行数:10,代码来源:test_instances.py

示例11: mock_api_call

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
 def mock_api_call(self, github_api, url, method='GET', fields=None, headers={}):
     result = Mock()
     if method == 'GET':
         result.status = 200
     else:
         result.status = 201
     result.data = json.dumps(self.api_results.pop(0)).encode()
     result.headers.get.return_value = None
     return result
开发者ID:democraticd,项目名称:democraticd,代码行数:11,代码来源:test_pr_db.py

示例12: test__action

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
 def test__action(self):
     resp = Mock()
     self.management.api.client.post = Mock(return_value=(resp, 'body'))
     resp.status = 200
     self.management._action(1, 'body')
     self.assertEqual(1, self.management.api.client.post.call_count)
     resp.status = 400
     self.assertRaises(Exception, self.management._action, 1, 'body')
     self.assertEqual(2, self.management.api.client.post.call_count)
开发者ID:CiscoSystems,项目名称:python-troveclient,代码行数:11,代码来源:test_management.py

示例13: test_raise_error_from_status

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
    def test_raise_error_from_status(self):
        resp = Mock()
        resp.status = 200
        self.hc.raise_error_from_status(resp, Mock())

        status_list = [400, 401, 403, 404, 408, 409, 413, 500, 501]
        for status in status_list:
            resp.status = status
            self.assertRaises(ValueError,
                              self.hc.raise_error_from_status, resp, Mock())
开发者ID:DJohnstone,项目名称:python-troveclient,代码行数:12,代码来源:test_client.py

示例14: test_delete

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
 def test_delete(self):
     resp = Mock()
     resp.status = 200
     body = None
     self.security_group_rules.api = Mock()
     self.security_group_rules.api.client = Mock()
     self.security_group_rules.api.client.delete = Mock(return_value=(resp, body))
     self.security_group_rules.delete(self.id)
     resp.status = 500
     self.assertRaises(Exception, self.security_group_rules.delete, self.id)
开发者ID:neumerance,项目名称:cloudcapped,代码行数:12,代码来源:test_secgroups.py

示例15: test_index

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import status [as 别名]
 def test_index(self):
     resp = Mock()
     resp.status = 400
     body = {"Accounts": {}}
     self.accounts.api.client.get = Mock(return_value=(resp, body))
     self.assertRaises(Exception, self.accounts.index)
     resp.status = 200
     self.assertTrue(isinstance(self.accounts.index(), base.Resource))
     self.accounts.api.client.get = Mock(return_value=(resp, None))
     self.assertRaises(Exception, self.accounts.index)
开发者ID:riddhi89,项目名称:python-reddwarfclient,代码行数:12,代码来源:test_accounts.py


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