Skip to content

Commit

Permalink
Sorta implement dep devices fetch
Browse files Browse the repository at this point in the history
Separate simulator config and test suite for testing DEP failures only, as this
will not be testable on live config.
  • Loading branch information
mosen committed Jul 18, 2017
1 parent 11bf0a7 commit 96029c0
Show file tree
Hide file tree
Showing 5 changed files with 361 additions and 53 deletions.
40 changes: 31 additions & 9 deletions commandment/dep/dep.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Iterator
from typing import Union, List
import requests
from requests.auth import AuthBase
Expand All @@ -6,8 +7,18 @@
from datetime import timedelta
from .errors import DEPError

class DEPCursor:
pass

class DEPCursor(Iterator):

def __init__(self, owner: DEP):
self.owner = owner

def __iter__(self):
pass

def __next__(self):
pass



class DEPAuth(AuthBase):
Expand Down Expand Up @@ -94,7 +105,7 @@ def send(self, req: requests.Request, **kwargs) -> requests.Response:
res.raise_for_status()
except requests.HTTPError as e:
raise DEPError(response=res, request=res.request) from e

return res

def fetch_token(self) -> Union[str, None]:
Expand All @@ -112,12 +123,22 @@ def fetch_token(self) -> Union[str, None]:
self._token = res.json().get("auth_session_token", None)
return self._token

def account(self, path: str = "/account") -> Union[None, dict]:
res = self.send(requests.Request("GET", self._url + path))
def account(self) -> Union[None, dict]:
"""Get Account Details
Returns:
Union[None, dict]: The account information, or None if it failed.
"""
res = self.send(requests.Request("GET", self._url + "/accounts"))
return res.json()

def devices(self) -> DEPCursor:
pass
def devices(self, limit: int = 100, cursor: Union[str, None] = None) -> dict:
"""Fetch a list of DEP devices
"""
req = requests.Request("POST", self._url + "/server/devices", json={'limit': limit, 'cursor': cursor})
res = self.send(req)
return res.json()


def device_detail(self, *serial_numbers: List[str]):
pass
Expand All @@ -128,8 +149,9 @@ def define_profile(self, profile: dict):
def assign_profile(self, profile_uuid: str, *serial_numbers: List[str]):
pass

def profile(self, uuid: str) -> dict:
def unassign_profile(self, *serial_numbers: List[str]):
pass

def remove_profile(self, *serial_numbers: List[str]):
def profile(self, uuid: str) -> dict:
pass

29 changes: 3 additions & 26 deletions simulators/depsim/config.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
{
"get_session_responses": [
{
"count": 1,
"response": "bad_request"
},
{
"count": 1,
"response": "forbidden_access_denied"
},
{
"count": 1,
"response": "forbidden_t_c_not_signed"
},
{
"count": 1,
"response": "invalid_method"
},
{
"count": 1,
"response": "unauthorized"
},
{
"count": 1,
"response": "too_many_requests"
}
]
"device_insertions": {
"devices_per_event": 500
}
}
Loading

0 comments on commit 96029c0

Please sign in to comment.