1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-12-05 01:23:44 +01:00
svtplay-dl/lib/svtplay_dl/tests/test_service.py

80 lines
2.9 KiB
Python
Raw Normal View History

import unittest
2019-08-25 00:40:39 +02:00
from svtplay_dl.service import Generic
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
2015-09-15 20:10:32 +02:00
class MockService(Service):
2019-08-25 00:27:31 +02:00
supported_domains = ["example.com", "example.net"]
2015-09-15 20:10:32 +02:00
class ServiceTest(unittest.TestCase):
def test_supports(self):
2019-09-15 23:41:39 +02:00
assert MockService.handles("http://example.com/video.swf?id=1")
assert MockService.handles("http://example.net/video.swf?id=1")
assert MockService.handles("http://www.example.com/video.swf?id=1")
assert 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()
2019-09-15 23:41:39 +02:00
assert not service_handler(sites, config, "localhost")
class service_handlerTest2(unittest.TestCase):
def test_service_handler(self):
config = setup_defaults()
2019-09-15 23:41:39 +02:00
assert isinstance(service_handler(sites, config, "https://www.svtplay.se"), Service)
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-15 23:41:39 +02:00
assert opengraph_get(self.text, "image") == "http://example.com/img3.jpg"
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):
2019-09-15 23:41:39 +02:00
assert not 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-15 23:41:39 +02:00
assert opengraph_get(self.text, "image") == "http://example.com/img3.jpg"
class test_generic(unittest.TestCase):
def test_nothing(self):
config = setup_defaults()
generic = Generic(config, "http://example.com")
data = "hejsan"
assert generic._match(data, sites) == ("http://example.com", None)
def test_hls(self):
config = setup_defaults()
generic = Generic(config, "http://example.com")
data = 'source src="http://example.com/hls.m3u8" type="application/x-mpegURL"'
assert isinstance(generic._match(data, sites)[1], Service)
def test_tv4(self):
config = setup_defaults()
generic = Generic(config, "http://example.com")
data = "rc=https://www.tv4play.se/iframe/video/12499319 "
assert isinstance(generic._match(data, sites)[1], Service)
def test_vimeo(self):
config = setup_defaults()
generic = Generic(config, "http://example.com")
data = 'src="https://player.vimeo.com/video/359281775" '
assert isinstance(generic._match(data, sites)[1], Service)