예제 #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 *_, **_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)
예제 #3
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)
예제 #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': {
                     'Cookie': 'GOOGAPPUID=42'
                 },
                 'timeout': remote_client.NET_CONNECTION_TIMEOUT_SEC,
             },
             {
                 'resp': 1
             },
         ),
     ])
     botobj = bot_main.get_bot(bot_main.get_config())
     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
파일: __main__.py 프로젝트: nodirt/luci-py
def CMDattributes(_args):
  """Prints out the bot's attributes."""
  import bot_main
  json.dump(
      bot_main.get_attributes(), sys.stdout, indent=2, sort_keys=True,
      separators=(',', ': '))
  print('')
  return 0
예제 #8
0
def CMDattributes(_args):
    """Prints out the bot's attributes."""
    import bot_main
    json.dump(bot_main.get_attributes(),
              sys.stdout,
              indent=2,
              sort_keys=True,
              separators=(',', ': '))
    print('')
    return 0
예제 #9
0
파일: main_test.py 프로젝트: nodirt/luci-py
 def test_attributes(self):
   self.maxDiff = None
   actual = json.loads(subprocess.check_output(
       [sys.executable, self.zip_file, 'attributes']))
   expected = bot_main.get_attributes()
   for key in ('cwd', 'disks', 'running_time', 'started_ts'):
     del actual['state'][key]
     del expected['state'][key]
   del actual['version']
   del expected['version']
   self.assertEqual(expected, actual)
예제 #10
0
 def test_attributes(self):
     self.maxDiff = None
     actual = json.loads(
         subprocess.check_output(
             [sys.executable, self.zip_file, 'attributes']))
     expected = bot_main.get_attributes()
     for key in (u'cwd', u'disks', u'running_time', u'started_ts'):
         del actual[u'state'][key]
         del expected[u'state'][key]
     del actual[u'version']
     del expected[u'version']
     self.assertAlmostEqual(actual[u'state'].pop(u'cost_usd_hour'),
                            expected[u'state'].pop(u'cost_usd_hour'),
                            places=6)
     self.assertEqual(expected, actual)
예제 #11
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)
예제 #12
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))