Verified Commit d766890b authored by Jan Koppe's avatar Jan Koppe
Browse files

more tests, test settings via env vars

parent 8a701ef8
Pipeline #1401 passed with stages
in 1 minute and 45 seconds
......@@ -23,7 +23,7 @@ DEFAULT_API_VERSION = "v1.0.0"
class ApiClient():
def __init__(self, host, user='admin', password='opencast',
def __init__(self, host, user, password,
api_version=DEFAULT_API_VERSION):
# Account credentials to authenticate with against the API. make sure
......
......@@ -16,7 +16,7 @@ from .apiclient import ApiClient
class Base(ApiClient):
def api_information(self, **kwargs) -> dict():
def info(self, **kwargs) -> dict():
"""
Returns key characteristics of the API such as the server name and the
default version.
......
from opencast_externalapi import ExternalApi
import os
import logging
logger = logging.getLogger()
def build_client():
host = os.getenv('OPENCAST_HOST', 'https://develop.opencast.org')
user = os.getenv('OPENCAST_USER', 'opencast_system_account')
password = os.getenv('OPENCAST_PASSWORD', 'CHANGE_ME')
logger.debug('user: %s, pass: %s, host: %s' % (user, password, host))
return ExternalApi(host=host, user=user, password=password)
......@@ -14,7 +14,7 @@
import unittest
from opencast_externalapi.apiclient import ApiClient
from tests.client_factory import build_client
class TestApiClient(unittest.TestCase):
......@@ -22,7 +22,7 @@ class TestApiClient(unittest.TestCase):
API_VERSION = 'v1.0.0'
def setUp(self):
self.api = ApiClient(host='http://localhost:8080') # TODO: CHANGE ME!
self.api = build_client()
def test_req(self):
r = self.api.req('/')
......
# 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 tests.client_factory import build_client
class TestBase(unittest.TestCase):
API_VERSION = 'v1.0.0'
def setUp(self):
self.api = build_client()
def test_api_version(self):
info = self.api.info()
self.assertIsInstance(info, dict)
self.assertEqual(info.get('version'), self.API_VERSION)
self.assertIsNotNone(info.get('url'))
def test_me(self):
me = self.api.me()
self.assertIsInstance(me, dict)
self.assertIsNotNone(me.get('email'))
self.assertIsNotNone(me.get('name'))
self.assertIsNotNone(me.get('provider'))
self.assertIsNotNone(me.get('userrole'))
self.assertIsNotNone(me.get('username'))
self.assertEqual(me.get('username'), self.api.auth_user)
def test_me_roles(self):
me = self.api.me()
roles = self.api.me_roles()
self.assertIsInstance(roles, list)
self.assertIn(me.get('userrole'), roles)
def test_organization(self):
org = self.api.organization()
self.assertIsInstance(org, dict)
self.assertIsNotNone(org.get('adminRole'))
self.assertIsNotNone(org.get('anonymousRole'))
self.assertIsNotNone(org.get('id'))
self.assertIsNotNone(org.get('name'))
def test_organization_properties(self):
props = self.api.organization_properties()
self.assertIsInstance(props, dict)
......@@ -14,7 +14,7 @@
import unittest
from opencast_externalapi import ExternalApi
from tests.client_factory import build_client
class TestEvents(unittest.TestCase):
......@@ -22,7 +22,7 @@ class TestEvents(unittest.TestCase):
API_VERSION = 'v1.0.0'
def setUp(self):
self.api = ExternalApi(host='http://localhost:8080') # TODO: CHANGE
self.api = build_client()
def test_get_events(self):
events = self.api.get_events()
......
......@@ -14,7 +14,7 @@
import unittest
from opencast_externalapi import ExternalApi
from tests.client_factory import build_client
class TestGroups(unittest.TestCase):
......@@ -24,22 +24,22 @@ class TestGroups(unittest.TestCase):
GROUP_NAME = 'test_group'
def setUp(self):
self.api = ExternalApi(host='http://localhost:8080') # TODO: CHANGE
self.api = build_client()
def test_get_group(self):
def test_get_all_groups(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):
def test_get_all_groups_limit(self):
one_group = self.api.get_group(limit=1)
self.assertEqual(len(one_group), 1)
self.assertIsInstance(one_group, list)
def test_get_group(self):
def test_get_one_group(self):
groups = self.api.get_group()
group_id = groups[0].get('identifier')
......@@ -47,7 +47,7 @@ class TestGroups(unittest.TestCase):
self.assertIsInstance(group, dict)
def test_create_group(self):
def test_create_and_delete_group(self):
success = self.api.create_group(self.GROUP_NAME)
......
......@@ -15,7 +15,7 @@
import unittest
import uuid
from opencast_externalapi import ExternalApi
from tests.client_factory import build_client
TEST_METADATA = '''
[
......@@ -61,7 +61,7 @@ class TestSeries(unittest.TestCase):
API_VERSION = 'v1.0.0'
def setUp(self):
self.api = ExternalApi(host='http://localhost:8080') # TODO: CHANGE
self.api = build_client()
def test_get_series(self):
series = self.api.get_series()
......
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