Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: appengine/swarming/handlers_endpoints_test.py

Issue 2198063002: Add bots.count endpoint (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: Address nits Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « appengine/swarming/handlers_endpoints.py ('k') | appengine/swarming/swarming_rpcs.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding=utf-8 2 # coding=utf-8
3 # Copyright 2015 The LUCI Authors. All rights reserved. 3 # Copyright 2015 The LUCI Authors. All rights reserved.
4 # Use of this source code is governed under the Apache License, Version 2.0 4 # Use of this source code is governed under the Apache License, Version 2.0
5 # that can be found in the LICENSE file. 5 # that can be found in the LICENSE file.
6 6
7 import base64 7 import base64
8 import datetime 8 import datetime
9 import json 9 import json
10 import logging 10 import logging
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 self.assertEqual(expected, response.json) 1415 self.assertEqual(expected, response.json)
1416 1416
1417 request = swarming_rpcs.BotsRequest(dimensions=['not:existing']) 1417 request = swarming_rpcs.BotsRequest(dimensions=['not:existing'])
1418 response = self.call_api('list', body=message_to_dict(request)) 1418 response = self.call_api('list', body=message_to_dict(request))
1419 del expected[u'items'] 1419 del expected[u'items']
1420 self.assertEqual(expected, response.json) 1420 self.assertEqual(expected, response.json)
1421 1421
1422 request = swarming_rpcs.BotsRequest(dimensions=['bad']) 1422 request = swarming_rpcs.BotsRequest(dimensions=['bad'])
1423 self.call_api('list', body=message_to_dict(request), status=400) 1423 self.call_api('list', body=message_to_dict(request), status=400)
1424 1424
1425 def test_count_ok(self):
1426 """Asserts that BotsCount is returned for the appropriate set of bots."""
1427 self.set_as_privileged_user()
1428 self.mock_now(datetime.datetime(2009, 1, 2, 3, 4, 5, 6))
1429 bot_management.bot_event(
1430 event_type='bot_connected', bot_id='id3',
1431 external_ip='8.8.4.4', authenticated_as='bot:whitelisted-ip',
1432 dimensions={'foo': ['bar'], 'id': ['id3']}, state={'ram': 65},
1433 version='123456789', quarantined=True, task_id=None, task_name=None)
1434 now = datetime.datetime(2010, 1, 2, 3, 4, 5, 6)
1435 self.mock_now(now)
1436 bot_management.bot_event(
1437 event_type='bot_connected', bot_id='id1',
1438 external_ip='8.8.4.4', authenticated_as='bot:whitelisted-ip',
1439 dimensions={'foo': ['bar'], 'id': ['id1']}, state={'ram': 65},
1440 version='123456789', quarantined=False, task_id=None, task_name=None)
1441 bot_management.bot_event(
1442 event_type='bot_connected', bot_id='id2',
1443 external_ip='8.8.4.4', authenticated_as='bot:whitelisted-ip',
1444 dimensions={'foo': ['bar'], 'id': ['id2']}, state={'ram': 65},
1445 version='123456789', quarantined=True, task_id='987', task_name=None)
1446 expected = {
1447 u'count': u'3',
1448 u'quarantined': u'2',
1449 u'dead': u'1',
1450 u'busy': u'1',
1451 u'now': unicode(now.strftime(self.DATETIME_FORMAT)),
1452 }
1453 request = swarming_rpcs.BotsRequest()
1454 response = self.call_api('count', body=message_to_dict(request))
1455 self.assertEqual(expected, response.json)
1456
1457 expected = {
1458 u'count': u'1',
1459 u'quarantined': u'0',
1460 u'dead': u'0',
1461 u'busy': u'0',
1462 u'now': unicode(now.strftime(self.DATETIME_FORMAT)),
1463 }
1464 request = swarming_rpcs.BotsRequest(dimensions=['foo:bar', 'id:id1'])
1465 response = self.call_api('count', body=message_to_dict(request))
1466 self.assertEqual(expected, response.json)
1467
1468 expected[u'quarantined'] = u'1'
1469 expected[u'busy'] = u'1'
1470 request = swarming_rpcs.BotsRequest(dimensions=['foo:bar', 'id:id2'])
1471 response = self.call_api('count', body=message_to_dict(request))
1472 self.assertEqual(expected, response.json)
1473
1474 expected[u'dead'] = u'1'
1475 expected[u'busy'] = u'0'
1476 request = swarming_rpcs.BotsRequest(dimensions=['foo:bar', 'id:id3'])
1477 response = self.call_api('count', body=message_to_dict(request))
1478 self.assertEqual(expected, response.json)
1479
1480 request = swarming_rpcs.BotsRequest(dimensions=['not:existing'])
1481 response = self.call_api('count', body=message_to_dict(request))
1482 expected = {
1483 u'count': u'0',
1484 u'quarantined': u'0',
1485 u'dead': u'0',
1486 u'busy': u'0',
1487 u'now': unicode(now.strftime(self.DATETIME_FORMAT)),
1488 }
1489 self.assertEqual(expected, response.json)
1490
1491 request = swarming_rpcs.BotsRequest(dimensions=['bad'])
1492 self.call_api('count', body=message_to_dict(request), status=400)
1425 1493
1426 class BotApiTest(BaseTest): 1494 class BotApiTest(BaseTest):
1427 api_service_cls = handlers_endpoints.SwarmingBotService 1495 api_service_cls = handlers_endpoints.SwarmingBotService
1428 1496
1429 def test_get_ok(self): 1497 def test_get_ok(self):
1430 """Asserts that get shows the tasks a specific bot has executed.""" 1498 """Asserts that get shows the tasks a specific bot has executed."""
1431 self.set_as_privileged_user() 1499 self.set_as_privileged_user()
1432 now = datetime.datetime(2010, 1, 2, 3, 4, 5, 6) 1500 now = datetime.datetime(2010, 1, 2, 3, 4, 5, 6)
1433 self.mock_now(now) 1501 self.mock_now(now)
1434 now_str = unicode(now.strftime(self.DATETIME_FORMAT)) 1502 now_str = unicode(now.strftime(self.DATETIME_FORMAT))
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 self.assertEqual(expected, response.json) 1740 self.assertEqual(expected, response.json)
1673 1741
1674 1742
1675 if __name__ == '__main__': 1743 if __name__ == '__main__':
1676 if '-v' in sys.argv: 1744 if '-v' in sys.argv:
1677 unittest.TestCase.maxDiff = None 1745 unittest.TestCase.maxDiff = None
1678 logging.basicConfig(level=logging.DEBUG) 1746 logging.basicConfig(level=logging.DEBUG)
1679 else: 1747 else:
1680 logging.basicConfig(level=logging.CRITICAL) 1748 logging.basicConfig(level=logging.CRITICAL)
1681 unittest.main() 1749 unittest.main()
OLDNEW
« no previous file with comments | « appengine/swarming/handlers_endpoints.py ('k') | appengine/swarming/swarming_rpcs.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698