def test_get_filter_doramas(client, app): response = client.get('/doramas?title=Dorama 1') json_data = response.get_json() total = json_data.get('total') results = json_data.get('results') with app.app_context(): db = get_db() cur = db.execute(''' SELECT COUNT(id) as total FROM dorama WHERE UPPER(title) LIKE UPPER('%Dorama 1%') ''') expected_total = cur.fetchone()['total'] cur = db.execute(''' SELECT title, dorama.link, fansub.name as fansub FROM dorama INNER JOIN fansub ON dorama.fansubId=fansub.id WHERE UPPER(title) LIKE UPPER('%Dorama 1%') ORDER BY title ''') expected_results = cur.fetchall() db.close() assert total == expected_total assert results == expected_results response = client.get('/doramas?fansub=New') json_data = response.get_json() total = json_data.get('total') results = json_data.get('results') with app.app_context(): db = get_db() cur = db.execute(''' SELECT COUNT(dorama.id) as total FROM dorama INNER JOIN fansub ON dorama.fansubId=fansub.id WHERE UPPER(fansub.name) LIKE UPPER('%New%') ''') expected_total = cur.fetchone()['total'] cur = db.execute(''' SELECT title, dorama.link, fansub.name as fansub FROM dorama INNER JOIN fansub ON dorama.fansubId=fansub.id WHERE UPPER(fansub.name) LIKE UPPER('%New%') ORDER BY title ''') expected_results = cur.fetchall() db.close() assert total == expected_total assert results == expected_results
def test_get_limit_doramas(client, app): response = client.get('/doramas?limit=5') json_data = response.get_json() total = json_data.get('total') results = json_data.get('results') with app.app_context(): db = get_db() cur = db.execute('SELECT COUNT(id) as total FROM dorama') expected_total = cur.fetchone()['total'] cur = db.execute(''' SELECT title, dorama.link, fansub.name as fansub FROM dorama INNER JOIN fansub ON dorama.fansubId=fansub.id ORDER BY title LIMIT 5 ''') expected_results = cur.fetchall() db.close() assert total == expected_total assert results == expected_results response = client.get('/doramas?limit=5&offset=5') json_data = response.get_json() total = json_data.get('total') results = json_data.get('results') with app.app_context(): db = get_db() cur = db.execute('SELECT COUNT(id) as total FROM dorama') expected_total = cur.fetchone()['total'] cur = db.execute(''' SELECT title, dorama.link, fansub.name as fansub FROM dorama INNER JOIN fansub ON dorama.fansubId=fansub.id ORDER BY title LIMIT 5 OFFSET 5 ''') expected_results = cur.fetchall() db.close() assert total == expected_total assert results == expected_results
def test_get_filter_fansubs(client, app): response = client.get('/fansubs?name=New') json_data = response.get_json() total = json_data.get('total') results = json_data.get('results') with app.app_context(): db = get_db() cur = db.execute(''' SELECT COUNT(id) as total FROM fansub WHERE UPPER(name) LIKE UPPER('%New%') ''') expected_total = cur.fetchone()['total'] cur = db.execute(''' SELECT spider, name, link, image, facebook FROM fansub WHERE UPPER(name) LIKE UPPER('%New%') ORDER BY name ''') expected_results = cur.fetchall() db.close() assert total == expected_total assert results == expected_results
def test_get_limit_fansubs(client, app): response = client.get('/fansubs?limit=5') json_data = response.get_json() total = json_data.get('total') results = json_data.get('results') with app.app_context(): db = get_db() cur = db.execute('SELECT COUNT(id) as total FROM fansub') expected_total = cur.fetchone()['total'] cur = db.execute(''' SELECT spider, name, link, image, facebook FROM fansub ORDER BY name LIMIT 5 ''') expected_results = cur.fetchall() db.close() assert total == expected_total assert results == expected_results response = client.get('/fansubs?limit=5&offset=5') json_data = response.get_json() total = json_data.get('total') results = json_data.get('results') with app.app_context(): db = get_db() cur = db.execute('SELECT COUNT(id) as total FROM fansub') expected_total = cur.fetchone()['total'] cur = db.execute(''' SELECT spider, name, link, image, facebook FROM fansub ORDER BY name LIMIT 5 OFFSET 5 ''') expected_results = cur.fetchall() db.close() assert total == expected_total assert results == expected_results
def app(): db_fd, db_path = tempfile.mkstemp() app = create_app({'Testing': True, 'DATABASE': db_path}) with app.app_context(): db = get_db() db.execute(''' CREATE TABLE fansub ( id INTEGER PRIMARY KEY AUTOINCREMENT, spider TEXT NOT NULL, link TEXT, name TEXT, image TEXT, facebook TEXT ) ''') db.execute(''' CREATE TABLE dorama ( id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, link TEXT NOT NULL, --fansub TEXT NOT NULL fansubId INTEGER NOT NULL, FOREIGN KEY (fansubId) REFERENCES fansub (id) ) ''') db.execute(''' INSERT INTO fansub (spider, name) VALUES ('test', 'Test fansub'), ('newTest', 'New Test fansub'); ''') db.commit() for i in range(10): idx1 = i * 2 + 1 idx2 = i * 2 + 2 values = (f'Dorama {idx1}', f'link d{idx1}', f'Dorama {idx2}', f'link d{idx2}') db.execute( ''' INSERT INTO dorama (title, link, fansubId) VALUES (?, ?, 1), (?, ?, 2); ''', values) db.commit() db.execute('CREATE TABLE status (last_update TEXT)') db.execute('INSERT INTO status (last_update) VALUES (?)', (date.today().isoformat(), )) db.commit() yield app os.close(db_fd) os.unlink(db_path)
def test_get_info(client, app): response = client.get('/info') json_data = response.get_json() api_version = json_data.get('api_version') db_last_update = json_data.get('db_last_update') with app.app_context(): db = get_db() cur = db.execute('SELECT last_update FROM status') exp_last_update = cur.fetchone().get('last_update') db.close() path_version = join(dirname(__file__), '../passarama_api/VERSION') with open(path_version, 'r') as f: exp_version = f.read().strip() assert api_version == exp_version assert db_last_update == exp_last_update