2020-06-22 20:21:22 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import unittest
|
2020-06-23 14:47:40 +01:00
|
|
|
from tmdb.tmdb_api import Movie
|
|
|
|
from tmdb.tmdb import TmdbBot
|
2020-06-23 16:34:34 +01:00
|
|
|
from tmdb.database import Database
|
|
|
|
from sqlalchemy import create_engine
|
|
|
|
|
2020-06-22 20:21:22 +01:00
|
|
|
|
|
|
|
class TestTmdbMethods(unittest.TestCase):
|
|
|
|
### TMDB API
|
|
|
|
def test_search_item(self):
|
|
|
|
movie = Movie()
|
|
|
|
id = movie.search_title('Breakfast Club')
|
|
|
|
self.assertEqual(id, 2108)
|
|
|
|
|
|
|
|
def test_cast(self):
|
|
|
|
movie = Movie()
|
|
|
|
movie.search_title('Breakfast Club')
|
|
|
|
self.assertEqual('Anthony Michael Hall', movie.cast[0])
|
|
|
|
|
|
|
|
def test_title(self):
|
|
|
|
movie = Movie()
|
|
|
|
movie.search_title('Breakfast Club')
|
|
|
|
self.assertEqual('The Breakfast Club', movie.title)
|
|
|
|
|
|
|
|
def test_overview(self):
|
|
|
|
movie = Movie()
|
|
|
|
movie.search_title('Breakfast Club')
|
|
|
|
description = 'Samstag morgen in einer amerikanischen High-School'
|
|
|
|
self.assertEqual(description, movie.overview[:len(description)])
|
|
|
|
|
|
|
|
def test_change_language(self):
|
|
|
|
movie = Movie()
|
|
|
|
movie.set_language('en')
|
|
|
|
movie.search_title('Breakfast Club')
|
|
|
|
description = 'Five high school students from different walks of life endure a Saturday detention'
|
|
|
|
self.assertEqual(description, movie.overview[:len(description)])
|
|
|
|
|
2020-06-23 14:47:40 +01:00
|
|
|
def test_html_construction(self):
|
|
|
|
movie = Movie()
|
|
|
|
tmdb = TmdbBot("","" ,"" ,"" ,"" ,"" ,"" ,"" ,"" )
|
|
|
|
movie.query_details('550')
|
|
|
|
message = tmdb.construct_html_message(movie, overview_length = 10)
|
|
|
|
self.assertEqual(message, """<p><b>Fight Club</b></p>
|
|
|
|
<p>Ein Yuppie [...]</p>
|
|
|
|
<p>Acting: Edward Norton, Brad Pitt, Helena Bonham Carter</p>
|
|
|
|
<p>taken from www.themoviedb.org</p>""")
|
|
|
|
|
2020-06-23 16:34:34 +01:00
|
|
|
def test_database_language(self):
|
|
|
|
engine = create_engine('sqlite:///test.db', echo = True)
|
|
|
|
db = Database(engine)
|
|
|
|
db.set_language('@testuser:example.com', 'de')
|
|
|
|
self.assertEqual(str(db.get_language('@testuser:example.com')), 'de')
|
|
|
|
db.set_language('@testuser:example.com', 'en')
|
|
|
|
self.assertEqual(str(db.get_language('@testuser:example.com')), 'en')
|
|
|
|
|
2020-06-22 20:21:22 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|