コード例 #1
0
 def test_one_uri(self):
   http = infra_libs.HttpMock([('https://www.google.com',
                                {'status': '403'},
                                'bar')])
   response, body = http.request('https://www.google.com', 'GET')
   self.assertIsInstance(response, httplib2.Response)
   self.assertEqual(response.status, 403)
   self.assertEqual(body, 'bar')
コード例 #2
0
ファイル: router_test.py プロジェクト: xinghun61/infra
    def test_logs_success(self, logdebug):
        r = router._HttpRouter({}, 'https://bla.bla')
        r._http = infra_libs.HttpMock([('https://bla.bla', {
            'status': 200
        }, '')])

        event = LogRequestLite.LogEventLite()
        event.event_time_ms = router.time_ms()
        event.event_code = 1
        event.event_flow_id = 2
        self.assertTrue(r.push_event(event))
        self.assertIn(mock.call('Succeeded POSTing data after %d attempts', 1),
                      logdebug.call_args_list)
コード例 #3
0
  def test_two_uris(self):
    http = infra_libs.HttpMock([('https://www.google.com',
                                 {'status': 200}, 'foo'),
                                ('.*', {'status': 404}, '')])
    response, body = http.request('https://mywebserver.woo.hoo', 'GET')
    self.assertIsInstance(response, httplib2.Response)
    self.assertEqual(response.status, 404)
    self.assertEqual(body, '')

    self.assertEqual(http.requests_made[0].uri, 'https://mywebserver.woo.hoo')
    self.assertEqual(http.requests_made[0].method, 'GET')
    self.assertEqual(http.requests_made[0].body, None)
    self.assertEqual(http.requests_made[0].headers, None)
コード例 #4
0
ファイル: router_test.py プロジェクト: xinghun61/infra
    def test_push_fail(self):
        # Fail to push events even after all retries
        sleep = mock.create_autospec(time.sleep, auto_set=True)
        r = router._HttpRouter({}, 'https://bla.bla', _sleep_fn=sleep)
        r._http = infra_libs.HttpMock([('https://bla.bla', {
            'status': 403
        }, '')])

        event = LogRequestLite.LogEventLite()
        event.event_time_ms = router.time_ms()
        event.event_code = 1
        event.event_flow_id = 2
        self.assertFalse(r.push_event(event))
        self.assertEquals(len(sleep.call_args_list), r.try_num)
コード例 #5
0
ファイル: router_test.py プロジェクト: xinghun61/infra
    def test_push_ok(self):
        # Successfully push event the first time.
        sleep = mock.create_autospec(time.sleep, auto_set=True)
        r = router._HttpRouter({}, 'https://bla.bla', _sleep_fn=sleep)
        r._http = infra_libs.HttpMock([('https://bla.bla', {
            'status': 200
        }, '')])

        event = LogRequestLite.LogEventLite()
        event.event_time_ms = router.time_ms()
        event.event_code = 1
        event.event_flow_id = 2
        self.assertTrue(r.push_event(event))
        self.assertEquals(len(sleep.call_args_list), 0)
コード例 #6
0
 def test_invalid_body(self):
   with self.assertRaises(TypeError):
     infra_libs.HttpMock([('https://www.google.com', {'status': '200'}, 42)])
コード例 #7
0
 def test_invalid_headers(self):
   with self.assertRaises(TypeError):
     infra_libs.HttpMock([('https://www.google.com', None, None)])
コード例 #8
0
 def test_headers_without_status(self):
   with self.assertRaises(ValueError):
     infra_libs.HttpMock([('https://www.google.com', {'foo': 'bar'}, None)])
コード例 #9
0
 def test_invalid_uri(self):
   with self.assertRaises(TypeError):
     infra_libs.HttpMock([(1, {'status': '100'}, None)])
コード例 #10
0
 def test_uris_wrong_type(self):
   with self.assertRaises(ValueError):
     infra_libs.HttpMock([(None,)])
コード例 #11
0
 def test_uris_wrong_length(self):
   with self.assertRaises(ValueError):
     infra_libs.HttpMock([(1, 2)])
コード例 #12
0
 def test_invalid_parameter(self):
   with self.assertRaises(TypeError):
     infra_libs.HttpMock(None)
コード例 #13
0
 def test_empty(self):
   http = infra_libs.HttpMock([])
   with self.assertRaises(AssertionError):
     http.request('https://www.google.com', 'GET')