| @@ -77,6 +77,7 @@ class BoardImpl: | |||
| self.name = name | |||
| self.brdclass = brdclass | |||
| self.options = options | |||
| self.reserved = False | |||
| self.attrmap = {} | |||
| for i in options: | |||
| self.attrmap[i.defattrname] = i | |||
| @@ -94,6 +95,7 @@ class BoardImpl: | |||
| class Board(BaseModel): | |||
| name: str | |||
| brdclass: str | |||
| reserved: bool | |||
| attrs: Dict[str, Any] | |||
| class Config: | |||
| @@ -194,12 +196,20 @@ def board_priority(request: Request): | |||
| return scope['server'] | |||
| @router.get('/board/classes', response_model=Dict[str, BoardClassInfo]) | |||
| async def foo(user: str = Depends(lookup_user), | |||
| async def get_board_classes(user: str = Depends(lookup_user), | |||
| brdmgr: BoardManager = Depends(get_boardmanager)): | |||
| return brdmgr.classes() | |||
| @router.get('/board/{board_id}', response_model=Board) | |||
| async def get_board_info(board_id, user: str = Depends(lookup_user), | |||
| brdmgr: BoardManager = Depends(get_boardmanager)): | |||
| brd = brdmgr.boards[board_id] | |||
| await brd.update() | |||
| return brd | |||
| @router.get('/board/',response_model=Dict[str, Board]) | |||
| async def foo(user: str = Depends(lookup_user), | |||
| async def get_boards(user: str = Depends(lookup_user), | |||
| brdmgr: BoardManager = Depends(get_boardmanager)): | |||
| brds = brdmgr.boards | |||
| for i in brds: | |||
| @@ -208,7 +218,7 @@ async def foo(user: str = Depends(lookup_user), | |||
| return brds | |||
| @router.get('/') | |||
| async def foo(board_prio: dict = Depends(board_priority), | |||
| async def root_test(board_prio: dict = Depends(board_priority), | |||
| settings: config.Settings = Depends(get_settings)): | |||
| return { 'foo': 'bar', 'board': board_prio } | |||
| @@ -305,9 +315,14 @@ class TestBiteLab(unittest.IsolatedAsyncioTestCase): | |||
| self.assertEqual(res.status_code, HTTP_401_UNAUTHORIZED) | |||
| async def test_classes(self): | |||
| # that when requesting the board classes | |||
| res = await self.client.get('/board/classes', | |||
| auth=BiteAuth('thisisanapikey')) | |||
| # it is successful | |||
| self.assertEqual(res.status_code, HTTP_200_OK) | |||
| # and returns the correct data | |||
| self.assertEqual(res.json(), { 'cora-z7s': BoardClassInfo(**{ | |||
| 'arch': 'arm-armv7', 'clsname': 'cora-z7s', }) }) | |||
| @@ -350,12 +365,36 @@ class TestBiteLab(unittest.IsolatedAsyncioTestCase): | |||
| 'cora-1': { | |||
| 'name': 'cora-1', | |||
| 'brdclass': 'cora-z7s', | |||
| 'reserved': False, | |||
| 'attrs': { 'power': False }, | |||
| }, | |||
| } | |||
| self.assertEqual(res.json(), info) | |||
| class TestData(unittest.IsolatedAsyncioTestCase): | |||
| # that when snmpget returns True | |||
| sg.return_value = True | |||
| # that getting the board info | |||
| res = await self.client.get('/board/cora-1', | |||
| auth=BiteAuth('thisisanapikey')) | |||
| # calls snmpget w/ the correct args | |||
| sg.assert_called_with('poe', 'pethPsePortAdminEnable.1.2', | |||
| 'bool') | |||
| # that it is successful | |||
| self.assertEqual(res.status_code, HTTP_200_OK) | |||
| # and returns the correct data | |||
| info = { | |||
| 'name': 'cora-1', | |||
| 'brdclass': 'cora-z7s', | |||
| 'reserved': False, | |||
| 'attrs': { 'power': True }, | |||
| } | |||
| self.assertEqual(res.json(), info) | |||
| class TestDatabase(unittest.IsolatedAsyncioTestCase): | |||
| def setUp(self): | |||
| # setup temporary directory | |||
| self.dbtempfile = tempfile.NamedTemporaryFile() | |||
| @@ -371,8 +410,14 @@ class TestData(unittest.IsolatedAsyncioTestCase): | |||
| async def test_apikey(self): | |||
| data = self.data | |||
| # that the test database starts empty | |||
| self.assertEqual(await data.APIKey.objects.all(), []) | |||
| # that when it is populated with test data | |||
| await _setup_data(data) | |||
| # the data can be accessed | |||
| self.assertEqual((await data.APIKey.objects.get( | |||
| key='thisisanapikey')).user, 'foo') | |||
| self.assertEqual((await data.APIKey.objects.get( | |||