Skip to content
Snippets Groups Projects
Commit 318c8e5d authored by Stéphane Schoorens's avatar Stéphane Schoorens
Browse files

ad podclient and resource object + tests refs #29848

parent e5db458d
No related branches found
No related tags found
No related merge requests found
......@@ -7,5 +7,8 @@ RUN apt update
RUN apt -qy install --no-install-recommends python3 python3-pip make
RUN pip3 install -U pip
COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt
COPY pip-requirements-docker.txt /tmp/pip-requirements-docker.txt
RUN pip install --no-cache-dir -r /tmp/pip-requirements-docker.txt tox
\ No newline at end of file
# POD client
python3 implementation of a pod client
pod is a video cms for educational https://github.com/EsupPortail/Esup-Pod
# build
`make build`
# lint
`make lint`
# deadcode
`make deadcode`
# test
`make test`
# Project dependencies
`python3 python3-pip python3-requests make`
\ No newline at end of file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from unittest import TestCase
def setUpModule():
pass
def tearDownModule():
pass
class BaseTest(TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_init(self):
pass
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from .Resource import API_URLS, Resource
class PodClient:
host_url = ''
def __init__(self, host_url):
self.host_url = host_url
if not self.host_url:
raise Exception('Pod host url required')
for key in API_URLS.keys():
self.__dict__[key] = Resource(host_url, key)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests
import logging
API_URLS = {
"users": "/rest/users/",
"groups": "/rest/groups/",
"owners": "/rest/owners/",
"channels": "/rest/channels/",
"themes": "/rest/themes/",
"types": "/rest/types/",
"discipline": "/rest/discipline/",
"videos": "/rest/videos/",
"renditions": "/rest/renditions/",
"encodings_video": "/rest/encodings_video/",
"encodings_audio": "/rest/encodings_audio/",
"playlist_videos": "/rest/playlist_videos/",
"contributors": "/rest/contributors/",
"documents": "/rest/documents/",
"tracks": "/rest/tracks/",
"overlays": "/rest/overlays/",
"chapters": "/rest/chapters/",
"recording": "/rest/recording/",
"recordingfile": "/rest/recordingfile/",
"folders": "/rest/folders/",
"files": "/rest/files/",
"images": "/rest/images/",
"enrichments": "/rest/enrichments/",
"buildings": "/rest/buildings/",
"broadcasters": "/rest/broadcasters/"
}
class Resource:
host_url = ''
name = ''
def __init__(self, host_url, resource_name):
self.host_url = host_url
if not self.host_url:
raise Exception('Pod host url required')
self.name = resource_name
if not API_URLS.get(self.name):
raise Exception('Resource url not supported')
def _do(self, method='GET', params={}, data={}, **request_params):
url = API_URLS[self.name]
try:
response = requests.request(method, url, params, data, request_params)
except (requests.RequestException,
requests.ConnectionError,
requests.HTTPError,
requests.URLRequired,
requests.TooManyRedirectsas) as e:
logging.error(e)
return
return response
def get(self, data=None, **request_params):
return self._do('GET', params=data, request_params=request_params)
def post(self, data=None, **request_params):
return self._do('GET', data=data, request_params=request_params)
def put(self, data=None, **request_params):
return self._do('GET', data=data, request_params=request_params)
def patch(self, data=None, **request_params):
return self._do('GET', data=data, request_params=request_params)
def delete(self, data=None, **request_params):
return self._do('GET', data=data, request_params=request_params)
File moved
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from unittest import TestCase
from pod_client.PodClient import PodClient
from pod_client.Resource import Resource, API_URLS
HOST = 'http://pod.ubicast.net'
def setUpModule():
pass
def tearDownModule():
pass
class PodClientTest(TestCase):
def test_init(self):
pod_client = PodClient(HOST)
for key in API_URLS.keys():
self.assertTrue(hasattr(pod_client, key))
self.assertTrue(isinstance(getattr(pod_client, key), Resource))
success = True
try:
pod_client = PodClient('')
except Exception:
success = False
self.assertFalse(success)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from unittest import TestCase
from pod_client.Resource import Resource, API_URLS
HOST = 'http://pod.ubicast.net'
def setUpModule():
pass
def tearDownModule():
pass
class ResourceTest(TestCase):
def test_init(self):
resource_name = 'files'
resource_file = Resource(HOST, resource_name)
self.assertEqual(HOST, resource_file.host_url)
self.assertEqual(resource_name, resource_file.name)
success = True
try:
resource_file = Resource('', resource_name)
except Exception:
success = False
self.assertFalse(success)
success = True
try:
resource_file = Resource(HOST, 'fake')
except Exception:
success = False
self.assertFalse(success)
def test_get(self):
pass
def test_post(self):
pass
def test_put(self):
pass
def test_patch(self):
pass
def test_delete(self):
pass
requests~=2.21
\ No newline at end of file
......@@ -3,14 +3,25 @@ envlist = lint, deadcode, test
toxworkdir = /tmp/tox_workdir
temp_dir = /tmp/tox_tmp
skipsdist = true
[flake8]
# https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
# Ignored errors:
# - E501: line too long
# - E265: block comment should start with '# ' (makes it easier to enable/disable code)
# - W503: line break before binary operator (deprecated rule)
# - W505: doc line too long
ignore = E501,E265,W503,W505
exclude = .tox/,.git/,.virtualenv/,__pycache__/,build/,dist/
[vulture]
parameters = --exclude *settings.py,*config.py --min-confidence 90
parameters = --exclude tests/ --min-confidence 90
[pytest]
addopts = --verbose --tb=long --showlocals --color=yes --cov=pod-client
testpaths = pod-client/
addopts = --verbose --tb=long --showlocals --color=yes --cov=pod_client
testpaths = pod_client
[testenv:lint]
deps = flake8
......@@ -24,5 +35,5 @@ commands = vulture . {[vulture]parameters}
deps =
pytest >= 4.5.0
pytest-cov >= 2.7.1
requests
commands = pytest
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment