Verified Commit 8a701ef8 authored by Jan Koppe's avatar Jan Koppe
Browse files

read,create series, read events

parent c723dcf2
Pipeline #1282 failed with stages
in 1 minute and 38 seconds
0.0.1.dev3
\ No newline at end of file
0.0.1.dev4
......@@ -13,10 +13,12 @@
# limitations under the License.
from .base import Base
from .events import Events
from .series import Series
from .groups import Groups
class ExternalApi(Base, Groups):
class ExternalApi(Base, Events, Series, Groups):
"""
Collection class
"""
......
......@@ -23,16 +23,14 @@ class Events(ApiClient):
with_publications=False,
filter=None,
**kwargs) -> dict():
parameters = {
'sign': sign,
'withacl': with_acl,
'withmetadata': with_metadata,
'withpublications': with_publications,
}
# TODO: validate filter
if filter:
parameters['filter'] = filter
return self.get_json('/events', parameters, **kwargs)
return self.get_json('/events', parameters=parameters, **kwargs)
......@@ -17,11 +17,11 @@ from .apiclient import ApiClient
class Groups(ApiClient):
def get_group(self, group_id, **kwargs) -> dict():
return self.get_json('/groups/%s' % group_id, **kwargs)
def get_groups(self, **kwargs) -> dict():
return self.get_json('/groups', **kwargs)
def get_group(self, group_id=None, **kwargs) -> dict():
if group_id:
return self.get_json('/groups/%s' % group_id, **kwargs)
else:
return self.get_json('/groups', **kwargs)
def create_group(self, name, desc="", roles=[], members=[],
**kwargs) -> bool():
......
# Copyright 2017 The WWU eLectures Team All rights reserved.
#
# Licensed under the Educational Community License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://opensource.org/licenses/ECL-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import uuid
from .apiclient import ApiClient
class Series(ApiClient):
def get_series(self, filter=None, **kwargs) -> dict():
parameters = {}
# TODO: validate filter
if filter:
parameters['filter'] = filter
return self.get_json('/series', parameters=parameters, **kwargs)
def create_series(self, metadata, acl, theme=None, **kwargs) -> str():
data = {
'metadata': metadata,
'acl': acl,
}
if theme:
data['theme'] = theme
r = self.req('/series', method='POST', data=data, **kwargs)
identifier = r.json().get('identifier')
return uuid.UUID(identifier)
# Copyright 2017 The WWU eLectures Team All rights reserved.
#
# Licensed under the Educational Community License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://opensource.org/licenses/ECL-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
from opencast_externalapi import ExternalApi
class TestEvents(unittest.TestCase):
API_VERSION = 'v1.0.0'
def setUp(self):
self.api = ExternalApi(host='http://localhost:8080') # TODO: CHANGE
def test_get_events(self):
events = self.api.get_events()
self.assertIsInstance(events, list)
......@@ -26,21 +26,21 @@ class TestGroups(unittest.TestCase):
def setUp(self):
self.api = ExternalApi(host='http://localhost:8080') # TODO: CHANGE
def test_get_groups(self):
groups = self.api.get_groups()
def test_get_group(self):
groups = self.api.get_group()
self.assertIsInstance(groups, list)
for group in groups:
self.assertIsNotNone(group.get('identifier'))
def test_get_groups_limit(self):
one_group = self.api.get_groups(limit=1)
one_group = self.api.get_group(limit=1)
self.assertEqual(len(one_group), 1)
self.assertIsInstance(one_group, list)
def test_get_group(self):
groups = self.api.get_groups()
groups = self.api.get_group()
group_id = groups[0].get('identifier')
group = self.api.get_group(group_id)
......
# Copyright 2017 The WWU eLectures Team All rights reserved.
#
# Licensed under the Educational Community License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://opensource.org/licenses/ECL-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
import uuid
from opencast_externalapi import ExternalApi
TEST_METADATA = '''
[
{
"label": "Opencast Series DublinCore",
"flavor": "dublincore/series",
"fields": [
{
"id": "title",
"value": "Captivating title"
},
{
"id": "subjects",
"value": ["John Clark", "Thiago Melo Costa"]
},
{
"id": "description",
"value": "A great description"
}
]
}
]
'''
TEST_ACL = '''
[
{
"allow": true,
"action": "write",
"role": "ROLE_ADMIN"
},
{
"allow": true,
"action": "read",
"role": "ROLE_USER"
}
]
'''
class TestSeries(unittest.TestCase):
API_VERSION = 'v1.0.0'
def setUp(self):
self.api = ExternalApi(host='http://localhost:8080') # TODO: CHANGE
def test_get_series(self):
series = self.api.get_series()
self.assertIsInstance(series, list)
def test_create_series(self):
id = self.api.create_series(metadata=TEST_METADATA, acl=TEST_ACL)
self.assertIsInstance(id, uuid.UUID)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment