diff --git a/pod_client/PodClient.py b/pod_client/pod_client.py similarity index 92% rename from pod_client/PodClient.py rename to pod_client/pod_client.py index 41dbe3191a887f54fefd436ee86ddfb93c0e06a2..4944c4dfc035db478dd5d892002e067383337aaa 100644 --- a/pod_client/PodClient.py +++ b/pod_client/pod_client.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from .Resource import API_URLS, Resource +from .resource import API_URLS, Resource class PodClient: diff --git a/pod_client/Resource.py b/pod_client/resource.py similarity index 96% rename from pod_client/Resource.py rename to pod_client/resource.py index dad425a63fec829b29c0549be1b5bc859da3efb6..986436715187ce69533a52f9352c4500333a2b71 100644 --- a/pod_client/Resource.py +++ b/pod_client/resource.py @@ -53,9 +53,9 @@ class Resource: raise Exception('Resource url not supported') def _request(self, method='GET', resource_id=None, headers={}, params={}, data={}, **request_params): - url = '%s/%s' % (self.host_url, API_URLS[self.name]) + url = '%s/%s/' % (self.host_url, API_URLS[self.name]) if resource_id: - url = '%s/%s' % (url, resource_id) + url = '%s%s/' % (url, resource_id) headers['Authorization'] = 'Token %s' % self.api_key try: response = requests.request(method, url, headers=headers, params=params, data=data, **request_params) diff --git a/tests/test_pod_client.py b/tests/test_pod_client.py index 3f5bb4ec7739d6b308c6d4d4c2ac0162689df88f..390fbd56958c128025c68e73852a156ed337fa9d 100644 --- a/tests/test_pod_client.py +++ b/tests/test_pod_client.py @@ -2,8 +2,8 @@ # -*- coding: utf-8 -*- import os from unittest import TestCase -from pod_client.PodClient import PodClient -from pod_client.Resource import Resource, API_URLS +from pod_client.pod_client import PodClient +from pod_client.resource import Resource, API_URLS HOST = 'http://pod.ubicast.net' diff --git a/tests/test_resource.py b/tests/test_resource.py index bcddae93b8253ba0c0dcc4f6783792bb7d8e521f..3d285f4054a116df4305328a9a417e1c2d03a421 100644 --- a/tests/test_resource.py +++ b/tests/test_resource.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- import os from unittest import TestCase -from pod_client.Resource import Resource, API_URLS +from pod_client.resource import Resource, API_URLS HOST = 'http://pod.ubicast.net' API_KEY = os.environ.get('POD_UNIT_TEST_API_KEY') @@ -63,10 +63,35 @@ class ResourceTest(TestCase): self.assertEqual(response.status_code, 204, response.text) def test_put(self): - pass + resource = Resource(HOST, API_KEY, 'channels') + response = resource.post(data={'title': 'unittest'}) + self.assertEqual(response.status_code, 201, response.text) + data = response.json() + data['title'] = 'New title unittest' + response = resource.put(resource_id=data['id'], data=data) + self.assertEqual(response.status_code, 200, response.text) + data_put = response.json() + self.assertEqual(data_put['title'], 'New title unittest') + response = resource.delete(resource_id=data['id']) + self.assertEqual(response.status_code, 204, response.text) def test_patch(self): - pass + resource = Resource(HOST, API_KEY, 'channels') + response = resource.post(data={'title': 'unittest'}) + self.assertEqual(response.status_code, 201, response.text) + data = response.json() + response = resource.patch(resource_id=data['id'], data={'title': 'New title unittest'}) + self.assertEqual(response.status_code, 200, response.text) + data_patch = response.json() + self.assertEqual(data_patch['title'], 'New title unittest') + response = resource.delete(resource_id=data['id']) + self.assertEqual(response.status_code, 204, response.text) def test_delete(self): - pass + resource = Resource(HOST, API_KEY, 'channels') + response = resource.post(data={'title': 'unittest'}) + self.assertEqual(response.status_code, 201, response.text) + data = response.json() + self.assertTrue(data['id']) + response = resource.delete(resource_id=data['id']) + self.assertEqual(response.status_code, 204, response.text) diff --git a/tox.ini b/tox.ini index 411dd1143abb1ff45424ea8ac84631a72ebea4f5..b9b70b0f37406c8bcf28bcf9c11846a9a7e43d06 100644 --- a/tox.ini +++ b/tox.ini @@ -20,7 +20,7 @@ exclude = .tox/,.git/,.virtualenv/,__pycache__/,build/,dist/ parameters = --exclude tests/ --min-confidence 90 [pytest] -addopts = --verbose --tb=long --showlocals --color=yes --cov=pod_client +addopts = --verbose --tb=long --showlocals --color=yes --cov=pod_client --cov-report term-missing testpaths = tests [testenv:lint]