2014-01-01 14:57:17 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
# ex:ts=4:sw=4:sts=4:et
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
# The unittest framwork doesn't play nice with pylint:
|
|
|
|
# pylint: disable-msg=C0103
|
|
|
|
from __future__ import absolute_import
|
2019-08-25 00:40:39 +02:00
|
|
|
|
2014-01-01 14:57:17 +01:00
|
|
|
import unittest
|
2019-08-25 00:40:39 +02:00
|
|
|
|
|
|
|
from svtplay_dl.service import opengraph_get
|
|
|
|
from svtplay_dl.service import Service
|
|
|
|
from svtplay_dl.service import service_handler
|
2018-10-05 23:24:53 +02:00
|
|
|
from svtplay_dl.service.services import sites
|
|
|
|
from svtplay_dl.utils.parser import setup_defaults
|
2014-01-01 14:57:17 +01:00
|
|
|
|
2015-09-15 20:10:32 +02:00
|
|
|
|
2014-01-01 14:57:17 +01:00
|
|
|
class MockService(Service):
|
2019-08-25 00:27:31 +02:00
|
|
|
supported_domains = ["example.com", "example.net"]
|
2014-01-01 14:57:17 +01:00
|
|
|
|
2015-09-15 20:10:32 +02:00
|
|
|
|
2014-01-01 14:57:17 +01:00
|
|
|
class ServiceTest(unittest.TestCase):
|
|
|
|
def test_supports(self):
|
2019-08-25 00:27:31 +02:00
|
|
|
self.assertTrue(MockService.handles("http://example.com/video.swf?id=1"))
|
|
|
|
self.assertTrue(MockService.handles("http://example.net/video.swf?id=1"))
|
|
|
|
self.assertTrue(MockService.handles("http://www.example.com/video.swf?id=1"))
|
|
|
|
self.assertTrue(MockService.handles("http://www.example.net/video.swf?id=1"))
|
2018-10-05 23:24:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
class service_handlerTest(unittest.TestCase):
|
|
|
|
def test_service_handler(self):
|
|
|
|
config = setup_defaults()
|
|
|
|
self.assertIsNone(service_handler(sites, config, "localhost"))
|
2018-10-05 23:45:09 +02:00
|
|
|
|
2018-10-05 23:46:52 +02:00
|
|
|
|
2018-10-05 23:45:09 +02:00
|
|
|
class service_handlerTest2(unittest.TestCase):
|
|
|
|
def test_service_handler(self):
|
|
|
|
config = setup_defaults()
|
2019-09-06 22:49:49 +02:00
|
|
|
self.assertIsInstance(service_handler(sites, config, "https://www.svtplay.se"), Service)
|
2018-10-05 23:46:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
class service_opengraphGet(unittest.TestCase):
|
|
|
|
text = '<html><head><meta name="og:image" property="og:image" content="http://example.com/img3.jpg"><meta'
|
|
|
|
|
|
|
|
def test_og_get(self):
|
2019-09-06 22:49:49 +02:00
|
|
|
self.assertEqual(opengraph_get(self.text, "image"), "http://example.com/img3.jpg")
|
2018-10-05 23:46:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
class service_opengraphGet_none(unittest.TestCase):
|
|
|
|
text = '<html><head><meta name="og:image" property="og:image" content="http://example.com/img3.jpg"><meta'
|
|
|
|
|
|
|
|
def test_og_get(self):
|
|
|
|
self.assertIsNone(opengraph_get(self.text, "kalle"))
|
|
|
|
|
|
|
|
|
|
|
|
class service_opengraphGet2(unittest.TestCase):
|
|
|
|
text = '<html><head><meta name="og:image" property="og:image" content="http://example.com/img3.jpg">'
|
|
|
|
|
|
|
|
def test_og_get(self):
|
2019-09-06 22:49:49 +02:00
|
|
|
self.assertEqual(opengraph_get(self.text, "image"), "http://example.com/img3.jpg")
|