From 339998ab93e1cf4bea3629f4ffd7b15399959960 Mon Sep 17 00:00:00 2001 From: lomion Date: Thu, 23 Sep 2021 22:22:35 +0200 Subject: [PATCH] Fixed Flake --- test_tmdb.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/test_tmdb.py b/test_tmdb.py index 1f532ac..eab2605 100644 --- a/test_tmdb.py +++ b/test_tmdb.py @@ -2,25 +2,26 @@ import unittest from html import escape from tmdb.tmdb_api import Movie, TvShow, MoviePopular -from tmdb.tmdb import TmdbBot, MessageConstructor +from tmdb.tmdb import TmdbBot from tmdb.database import Database from sqlalchemy import create_engine -import time -import requests +import aiohttp -def apiRequests(command): + +async def apiRequests(command): api_key = '51d75c00dc1502dc894b7773ec3e7a15' base_url = "https://api.themoviedb.org/3/" url = base_url + command.lstrip('/') params = {'api_key': api_key} params.update({'language': 'en'}) - return requests.get(url, params=params).json() + async with aiohttp.ClientSession() as client: + async with client.get(url, params=params) as resp: + return await resp.json() class TestTmdbMethods(unittest.IsolatedAsyncioTestCase): # TMDB API async def test_search_item(self): - start = time.time() movie = Movie() await movie.load_parameters() id = await movie.search_title('Breakfast Club') @@ -139,7 +140,7 @@ class TestTmdbMethods(unittest.IsolatedAsyncioTestCase): await movie.close_session() async def test_movie_popular_length(self): - results = apiRequests('/movie/popular') + results = await apiRequests('/movie/popular') list = MoviePopular() await list.load_parameters() text = await list.query() @@ -147,7 +148,7 @@ class TestTmdbMethods(unittest.IsolatedAsyncioTestCase): await list.close_session() async def test_movie_popular_id(self): - results = apiRequests('/movie/popular') + results = await apiRequests('/movie/popular') list = MoviePopular() await list.load_parameters() await list.query() @@ -155,7 +156,7 @@ class TestTmdbMethods(unittest.IsolatedAsyncioTestCase): await list.close_session() async def test_movie_popular_html(self): - results = apiRequests('/movie/popular') + results = await apiRequests('/movie/popular') list = MoviePopular() await list.load_parameters() await list.query() @@ -166,7 +167,7 @@ class TestTmdbMethods(unittest.IsolatedAsyncioTestCase): await list.close_session() async def test_movie_popular_text(self): - results = apiRequests('/movie/popular') + results = await apiRequests('/movie/popular') list = MoviePopular() await list.load_parameters() await list.query() @@ -176,5 +177,6 @@ class TestTmdbMethods(unittest.IsolatedAsyncioTestCase): self.assertEqual(tested, test_result) await list.close_session() + if __name__ == '__main__': unittest.main()