Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions castle/api/get_device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from castle.api_request import APIRequest
from castle.commands.get_device import CommandsGetDevice


class APIGetDevice(object):
@staticmethod
def retrieve(device_token):
return APIRequest().call(CommandsGetDevice.build(device_token))
15 changes: 15 additions & 0 deletions castle/commands/get_device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from castle.command import Command
from castle.validators.present import ValidatorsPresent


class CommandsGetDevice(object):

@staticmethod
def build(device_token):
ValidatorsPresent.call({'device_token': device_token}, 'device_token')

return Command(
method='get',
path="devices/{device_token}".format(device_token=device_token),
data=None
)
2 changes: 2 additions & 0 deletions castle/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


TEST_MODULES = [
'castle.test.api.get_device_test',
'castle.test.api.get_devices_test',
'castle.test.api.review_test',
'castle.test.api_request_test',
Expand All @@ -14,6 +15,7 @@
'castle.test.commands.authenticate_test',
'castle.test.commands.identify_test',
'castle.test.commands.impersonate_test',
'castle.test.commands.get_device_test',
'castle.test.commands.get_devices_test',
'castle.test.commands.review_test',
'castle.test.commands.track_test',
Expand Down
27 changes: 27 additions & 0 deletions castle/test/api/get_device_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import json
import responses

from castle.test import unittest
from castle.api.get_device import APIGetDevice
from castle.configuration import configuration


class APIGetDeviceTestCase(unittest.TestCase):
def setUp(self):
configuration.api_secret = 'test'

def tearDown(self):
configuration.api_secret = None

@responses.activate
def test_retrieve(self):
# pylint: disable=line-too-long
response_text = "{\"id\":\"d_id\",\"manufacturer\":\"d_manufacturer\",\"model\":\"d_model\",\"name\":\"d_name\",\"type\":\"d_type\"}"
responses.add(
responses.GET,
'https://api.castle.io/v1/devices/1234',
body=response_text,
status=200
)
device_token = '1234'
self.assertEqual(APIGetDevice.retrieve(device_token), json.loads(response_text))
21 changes: 21 additions & 0 deletions castle/test/commands/get_device_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from castle.test import unittest
from castle.command import Command
from castle.commands.get_device import CommandsGetDevice
from castle.errors import InvalidParametersError


def device_token():
return '1234'


class CommandsGetDeviceTestCase(unittest.TestCase):
def test_build_no_device_token(self):
with self.assertRaises(InvalidParametersError):
CommandsGetDevice.build('')

def test_build(self):
command = CommandsGetDevice.build(device_token())
self.assertIsInstance(command, Command)
self.assertEqual(command.method, 'get')
self.assertEqual(command.path, 'devices/1234')
self.assertEqual(command.data, None)