#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os from unittest import TestCase from pod_client.pod_client import PodClient from pod_client.resource import Resource, API_URLS HOST = 'http://pod.ubicast.net' API_KEY = os.environ.get('POD_UNIT_TEST_API_KEY') VIDEO_PATH = 'tests/media/test.mp4' def setUpModule(): pass def tearDownModule(): pass class PodClientTest(TestCase): def test_init(self): self.assertTrue(API_KEY) pod_client = PodClient(HOST, API_KEY) 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('', API_KEY) except Exception: success = False self.assertFalse(success) success = True try: pod_client = PodClient(HOST, '') except Exception: success = False self.assertFalse(success) self.assertTrue(pod_client.videos.get()) def test_post_video(self): pod_client = PodClient(HOST, API_KEY) data = { 'title': 'unittest video', 'type': pod_client.types.url(1), 'owner': pod_client.users.url(1) } files = {'video': open(VIDEO_PATH, 'rb')} response = pod_client.videos.post(data=data, files=files) self.assertTrue(response['success'], response.get('error')) self.assertEqual(data['title'], 'unittest video') response = pod_client.launch_encode_view.get(data={'slug': response['data']['slug']}) self.assertTrue(response['success'], response.get('error')) response = pod_client.videos.delete(resource_id=response['data']['id']) self.assertTrue(response['success'], response.get('error'))