Exemplo n.º 1
0
 def test_top_dvd(self):
     self.service = python_filmaffinity.FilmAffinity()
     movies = self.service.top_dvd(top=10)
     time.sleep(4)
     self.check_list(movies)
     movies = self.service.top_dvd(top=20)
     time.sleep(4)
     self.assertEqual(len(movies), 20)
     movies = self.service.top_dvd(top=80)
     time.sleep(4)
     self.assertEqual(len(movies), 40)
     self.check_list(movies)
Exemplo n.º 2
0
 def test_top_series(self):
     self.service = python_filmaffinity.FilmAffinity()
     movies = self.service.top_tv_series()
     self.check_list(movies)
     time.sleep(4)
     movies = self.service.top_tv_series(top=5)
     self.assertEqual(len(movies), 5)
     time.sleep(4)
     movies = self.service.top_tv_series(top=80)
     self.assertEqual(len(movies), 30)
     time.sleep(4)
     movies = self.service.top_tv_series(from_year='2010', to_year='2011')
     self.check_list(movies)
Exemplo n.º 3
0
 def __init__(self):
     self.service = python_filmaffinity.FilmAffinity()
Exemplo n.º 4
0
 def test_top_movistar(self):
     self.service = python_filmaffinity.FilmAffinity()
     movies = self.service.top_movistar(top=10)
     self.check_list(movies)
Exemplo n.º 5
0
class TestApi(TestCase):
    service = python_filmaffinity.FilmAffinity()

    def tearDown(self):
        time.sleep(4)

    def check_list(self, movies):
        self.assertNotEqual(0, len(movies))
        movie = random.choice(movies)
        for field in FIELDS_PAGE_MOVIES:
            self.assertNotEqual(movie[field],
                                None,
                                msg='Error on getting movie list '
                                ',field is: {}'.format(field))
        self.assertNotEqual(len(movie['directors']), 0)

    def check_element(self, movie):
        for field in FIELDS_PAGE_DETAIL:
            self.assertNotEqual(movie[field],
                                None,
                                msg='Error on checking movie '
                                'field: {}'.format(field))

    def test_search(self):
        movies = self.service.search(title='Batman')
        self.check_list(movies)

    def test_get_movie(self):
        movie = self.service.get_movie(id='197671', images=True)
        self.check_element(movie)
        self.assertNotEqual(movie['images'], [],
                            msg='Error on getting movie images')

    def test_top_filmaffinity(self):
        movies = self.service.top_filmaffinity()
        self.check_list(movies)

    def test_top_series(self):
        self.service = python_filmaffinity.FilmAffinity()
        movies = self.service.top_tv_series()
        self.check_list(movies)
        time.sleep(4)
        movies = self.service.top_tv_series(top=5)
        self.assertEqual(len(movies), 5)
        time.sleep(4)
        movies = self.service.top_tv_series(top=80)
        self.assertEqual(len(movies), 30)
        time.sleep(4)
        movies = self.service.top_tv_series(from_year='2010', to_year='2011')
        self.check_list(movies)

    def test_top_premieres(self):
        movies = self.service.top_premieres()
        self.check_list(movies)

    def test_top_filmaffinity_years(self):
        movies = self.service.top_filmaffinity(from_year='2010',
                                               to_year='2011')
        self.check_list(movies)

    def test_search_years(self):
        movies = self.service.search(title='Batman',
                                     from_year='2000',
                                     to_year='2011')
        self.check_list(movies)

    def test_top_netflix(self):
        movies = self.service.top_netflix(top=10)
        self.check_list(movies)

    def test_top_movistar(self):
        self.service = python_filmaffinity.FilmAffinity()
        movies = self.service.top_movistar(top=10)
        self.check_list(movies)

    def test_top_rakuten(self):
        movies = self.service.top_rakuten(top=10)
        self.check_list(movies)

    def test_top_hbo(self):
        movies = self.service.top_hbo(top=10)
        self.check_list(movies)

    def test_top_filmin(self):
        movies = self.service.top_filmin(top=10)
        self.check_list(movies)

    def test_recommend_netflix(self):
        movie = self.service.recommend_netflix()
        self.check_element(movie)

    def test_recommend_hbo(self):
        movie = self.service.recommend_hbo()
        self.check_element(movie)

    def test_recommend_filmin(self):
        movie = self.service.recommend_filmin()
        self.check_element(movie)

    def test_recommend_movistar(self):
        movie = self.service.recommend_movistar()
        self.check_element(movie)

    def test_recommend_rakuten(self):
        self.service = python_filmaffinity.FilmAffinity()
        movie = self.service.recommend_rakuten()
        self.check_element(movie)

    def test_top_dvd(self):
        self.service = python_filmaffinity.FilmAffinity()
        movies = self.service.top_dvd(top=10)
        time.sleep(4)
        self.check_list(movies)
        movies = self.service.top_dvd(top=20)
        time.sleep(4)
        self.assertEqual(len(movies), 20)
        movies = self.service.top_dvd(top=80)
        time.sleep(4)
        self.assertEqual(len(movies), 40)
        self.check_list(movies)

    def test_invalid_language(self):
        self.assertRaises(FilmAffinityInvalidLanguage,
                          python_filmaffinity.FilmAffinity,
                          lang="abc")

    def test_invalid_backend(self):
        self.assertRaises(FilmAffinityInvalidBackend,
                          python_filmaffinity.FilmAffinity,
                          cache_backend='mysqlite')

    def test_invalid_connection(self):
        self.assertRaises(FilmAffinityConnectionError,
                          self.service._load_url,
                          "http://notworking.tz",
                          headers={'User-Agent': 'Mozilla/5.0'},
                          verify=True,
                          timeout=1,
                          force_server_response=True)

    def test_meta_variables(self):
        for v in meta_test.__dict__:
            if v in ['__builtins__', '__package__', '__doc__']:
                continue
            self.assertIsNotNone(
                meta_test.__dict__[v],
                msg='Error on getting meta value: {}'.format(v))
Exemplo n.º 6
0
 def test_recommend_rakuten(self):
     self.service = python_filmaffinity.FilmAffinity()
     movie = self.service.recommend_rakuten()
     self.check_element(movie)
Exemplo n.º 7
0
    def datos_peli_film(self,
                        titulo=None,
                        idFicha=None,
                        anio=None,
                        sinopsis=None,
                        titulo_es=None):
        logger.debug(
            '-------------- BUSCAMOS EN FILMAFFINITY --------------------')
        service = python_filmaffinity.FilmAffinity(lang='es')
        service2 = python_filmaffinity.FilmAffinity(lang='en')
        pelicula = []
        if titulo_es == None and idFicha == None:
            print("No hay parámetros para la busqueda")
            pelicula = []
        elif idFicha <> None:
            pelicula = service.get_movie(id=idFicha, images=True)
            pelicula2 = service2.get_movie(id=idFicha, images=True)

        elif titulo_es <> None:
            continuar = 0
            if anio == None:
                try:
                    busqueda = service.search(title=titulo_es)
                    if len(busqueda) > 1:
                        print('Existen más de 1 resultado')
                        # return None
                    for peli in busqueda:
                        pelicula = service.get_movie(id=peli['id'],
                                                     images=True)
                        pelicula2 = service2.get_movie(id=pelicula['id'],
                                                       images=True)
                        continuar = 1
                        break
                except:
                    logger.error("Error en la búsqueda en español")

            else:
                try:
                    busqueda = service.search(title=titulo_es,
                                              from_year=anio,
                                              to_year=anio)
                    if len(busqueda) > 1:
                        print('Existen más de 1 resultado')
                        # return None
                    for x in busqueda:
                        pelicula = service.get_movie(id=x['id'], images=True)
                        pelicula2 = service2.get_movie(id=pelicula['id'],
                                                       images=True)
                        continuar = 1
                        break
                except:
                    logger.error("Error en la búsqueda en español")

        if titulo <> None and (continuar == 0 or titulo_es == None):
            if anio == None:
                try:
                    busqueda = service.search(title=titulo)
                    if len(busqueda) > 1:
                        print('Existen más de 1 resultado')
                        # return None
                    for peli in busqueda:
                        pelicula2 = service2.get_movie(title=peli['title'],
                                                       images=True)
                        pelicula = service.get_movie(id=pelicula2['id'],
                                                     images=True)

                        logger.debug('Pelicula Español')
                        log_datos(pelicula)
                        logger.debug('Pelicula Ingles')
                        log_datos(pelicula2)

                        break
                except:
                    logger.error("Error en la búsqueda en original")
            else:
                try:
                    resul = service2.search(title=titulo,
                                            from_year=anio,
                                            to_year=anio)

                    if len(resul) > 1:
                        print('Existen más de 1 resultado')
                        # return None
                    for x in resul:
                        pelicula2 = service2.get_movie(id=x['id'], images=True)
                        pelicula = service.get_movie(id=x['id'], images=True)

                        logger.debug('Pelicula Español')
                        log_datos(pelicula)
                        logger.debug('Pelicula Ingles')
                        log_datos(pelicula2)

                        break
                except:
                    logger.error("Error en la búsqueda en original")
        # xml_content = res.content
        # print (pelicula)

        if pelicula:
            item = {
                'titulo': pelicula['title'],
                'titulo_orig': pelicula2['title'],
                'anio': pelicula['year'],
                'generos': ', '.join(pelicula['genre']),
                'imagen': pelicula['poster'],
                'pais': pelicula['country'],
                'escritor': None,
                'director': ', '.join(pelicula['directors']),
                'actores': ', '.join(pelicula['actors']),
                'duracion': pelicula['duration'],
                'sinopsis': pelicula2['description'],
                'sinopsis_es': pelicula['description'],
                'idFicha': 'Film-' + pelicula['id'],
            }
            logger.debug('Finalmente nos queda ')
            log_datos(item)
        else:
            return None

        return item