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