From 90c375b45efcd65bcb7859badde193557b741752 Mon Sep 17 00:00:00 2001
From: sschoorens <stephane.schoorens@ubicast.eu>
Date: Mon, 20 Jan 2020 14:36:33 +0100
Subject: [PATCH] rename and add put,patch,delete tests refs #29848

---
 pod_client/{PodClient.py => pod_client.py} |  2 +-
 pod_client/{Resource.py => resource.py}    |  4 +--
 tests/test_pod_client.py                   |  4 +--
 tests/test_resource.py                     | 33 +++++++++++++++++++---
 tox.ini                                    |  2 +-
 5 files changed, 35 insertions(+), 10 deletions(-)
 rename pod_client/{PodClient.py => pod_client.py} (92%)
 rename pod_client/{Resource.py => resource.py} (96%)

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 41dbe31..4944c4d 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 dad425a..9864367 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 3f5bb4e..390fbd5 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 bcddae9..3d285f4 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 411dd11..b9b70b0 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]
-- 
GitLab