Пример #1
0
 def test_post_error_task(self):
     self.mock(time, "time", lambda: 126.0)
     self.mock(logging, "error", lambda *_, **_kw: None)
     self.mock(bot_main, "get_remote", lambda: self.server)
     # get_state() return value changes over time. Hardcode its value for the
     # duration of this test.
     self.mock(os_utilities, "get_state", lambda: {"foo": "bar"})
     expected_attribs = bot_main.get_attributes(None)
     self.expected_requests(
         [
             (
                 "https://localhost:1/auth/api/v1/accounts/self/xsrf_token",
                 {"data": expected_attribs, "headers": {"X-XSRF-Token-Request": "1"}},
                 {"xsrf_token": "token"},
             ),
             (
                 "https://localhost:1/swarming/api/v1/bot/task_error/23",
                 {
                     "data": {"id": expected_attribs["dimensions"]["id"][0], "message": "error", "task_id": 23},
                     "headers": {"X-XSRF-Token": "token"},
                 },
                 {},
             ),
         ]
     )
     botobj = bot_main.get_bot()
     bot_main.post_error_task(botobj, "error", 23)
Пример #2
0
 def test_post_error_task(self):
   self.mock(time, 'time', lambda: 126.0)
   self.mock(logging, 'error', lambda *_: None)
   self.mock(bot_main, 'get_remote', lambda: self.server)
   expected_attribs = bot_main.get_attributes()
   self.expected_requests(
       [
         (
           'https://localhost:1/auth/api/v1/accounts/self/xsrf_token',
           {
             'data': expected_attribs,
             'headers': {'X-XSRF-Token-Request': '1'},
           },
           {'xsrf_token': 'token'},
         ),
         (
           'https://localhost:1/swarming/api/v1/bot/task_error/23',
           {
             'data': {
               'id': expected_attribs['dimensions']['id'][0],
               'message': 'error',
               'task_id': 23,
             },
             'headers': {'X-XSRF-Token': 'token'},
           },
           {},
         ),
       ])
   botobj = bot_main.get_bot()
   bot_main.post_error_task(botobj, 'error', 23)
Пример #3
0
 def test_post_error_task(self):
   self.mock(time, 'time', lambda: 126.0)
   self.mock(logging, 'error', lambda *_, **_kw: None)
   self.mock(bot_main, 'get_remote', lambda: self.server)
   # get_state() return value changes over time. Hardcode its value for the
   # duration of this test.
   self.mock(os_utilities, 'get_state', lambda: {'foo': 'bar'})
   expected_attribs = bot_main.get_attributes()
   self.expected_requests(
       [
         (
           'https://localhost:1/auth/api/v1/accounts/self/xsrf_token',
           {
             'data': expected_attribs,
             'headers': {'X-XSRF-Token-Request': '1'},
           },
           {'xsrf_token': 'token'},
         ),
         (
           'https://localhost:1/swarming/api/v1/bot/task_error/23',
           {
             'data': {
               'id': expected_attribs['dimensions']['id'][0],
               'message': 'error',
               'task_id': 23,
             },
             'headers': {'X-XSRF-Token': 'token'},
           },
           {},
         ),
       ])
   botobj = bot_main.get_bot()
   bot_main.post_error_task(botobj, 'error', 23)
Пример #4
0
 def test_post_error_task(self):
     self.mock(time, 'time', lambda: 126.0)
     self.mock(logging, 'error', lambda *_: None)
     self.mock(bot_main, 'get_remote', lambda: self.server)
     expected_attribs = bot_main.get_attributes()
     self.expected_requests([
         (
             'https://localhost:1/auth/api/v1/accounts/self/xsrf_token',
             {
                 'data': expected_attribs,
                 'headers': {
                     'X-XSRF-Token-Request': '1'
                 },
             },
             {
                 'xsrf_token': 'token'
             },
         ),
         (
             'https://localhost:1/swarming/api/v1/bot/task_error/23',
             {
                 'data': {
                     'id': expected_attribs['dimensions']['id'][0],
                     'message': 'error',
                     'task_id': 23,
                 },
                 'headers': {
                     'X-XSRF-Token': 'token'
                 },
             },
             {},
         ),
     ])
     botobj = bot_main.get_bot()
     bot_main.post_error_task(botobj, 'error', 23)
Пример #5
0
 def test_post_error_task(self):
   self.mock(time, 'time', lambda: 126.0)
   self.mock(logging, 'error', lambda *_, **_kw: None)
   self.mock(
       bot_main, 'get_config',
       lambda: {'server': self.url, 'server_version': '1'})
   expected_attribs = bot_main.get_attributes(None)
   self.expected_requests(
       [
         (
           'https://localhost:1/swarming/api/v1/bot/task_error/23',
           {
             'data': {
               'id': expected_attribs['dimensions']['id'][0],
               'message': 'error',
               'task_id': 23,
             },
             'follow_redirects': False,
             'headers': {},
             'timeout': remote_client.NET_CONNECTION_TIMEOUT_SEC,
           },
           {'resp': 1},
         ),
       ])
   botobj = bot_main.get_bot()
   self.assertEqual(True, bot_main.post_error_task(botobj, 'error', 23))
Пример #6
0
 def test_post_error_task(self):
     self.mock(time, 'time', lambda: 126.0)
     self.mock(logging, 'error', lambda *_, **_kw: None)
     self.mock(bot_main, 'get_config', lambda: {
         'server': self.url,
         'server_version': '1'
     })
     expected_attribs = bot_main.get_attributes(None)
     self.expected_requests([
         (
             'https://localhost:1/swarming/api/v1/bot/task_error/23',
             {
                 'data': {
                     'id': expected_attribs['dimensions']['id'][0],
                     'message': 'error',
                     'task_id': 23,
                 },
             },
             {
                 'resp': 1
             },
         ),
     ])
     botobj = bot_main.get_bot()
     self.assertEqual({'resp': 1},
                      bot_main.post_error_task(botobj, 'error', 23))
Пример #7
0
 def test_post_error_task(self):
     self.mock(time, 'time', lambda: 126.0)
     self.mock(logging, 'error', lambda *_, **_kw: None)
     self.mock(bot_main, 'get_remote', lambda: self.server)
     # get_state() return value changes over time. Hardcode its value for the
     # duration of this test.
     self.mock(os_utilities, 'get_state', lambda: {'foo': 'bar'})
     expected_attribs = bot_main.get_attributes()
     self.expected_requests([
         (
             'https://localhost:1/auth/api/v1/accounts/self/xsrf_token',
             {
                 'data': expected_attribs,
                 'headers': {
                     'X-XSRF-Token-Request': '1'
                 },
             },
             {
                 'xsrf_token': 'token'
             },
         ),
         (
             'https://localhost:1/swarming/api/v1/bot/task_error/23',
             {
                 'data': {
                     'id': expected_attribs['dimensions']['id'][0],
                     'message': 'error',
                     'task_id': 23,
                 },
                 'headers': {
                     'X-XSRF-Token': 'token'
                 },
             },
             {},
         ),
     ])
     botobj = bot_main.get_bot()
     bot_main.post_error_task(botobj, 'error', 23)
Пример #8
0
 def test_post_error_task(self):
   self.mock(time, 'time', lambda: 126.0)
   self.mock(logging, 'error', lambda *_, **_kw: None)
   self.mock(
       bot_main, 'get_config',
       lambda: {'server': self.url, 'server_version': '1'})
   expected_attribs = bot_main.get_attributes(None)
   self.expected_requests(
       [
         (
           'https://localhost:1/swarming/api/v1/bot/task_error/23',
           {
             'data': {
               'id': expected_attribs['dimensions']['id'][0],
               'message': 'error',
               'task_id': 23,
             },
           },
           {'resp': 1},
         ),
       ])
   botobj = bot_main.get_bot()
   self.assertEqual({'resp': 1}, bot_main.post_error_task(botobj, 'error', 23))