84 lines
4.8 KiB
Python
84 lines
4.8 KiB
Python
"""Regression coverage for app advertisements disguised as movie records."""
|
|
import json
|
|
import sqlite3
|
|
import unittest
|
|
from urllib.parse import urlencode
|
|
|
|
import test_catalog_api as fixtures
|
|
|
|
|
|
class CatalogueAdTests(unittest.TestCase):
|
|
setUp = fixtures.CatalogTests.setUp
|
|
tearDown = fixtures.CatalogTests.tearDown
|
|
open = fixtures.CatalogTests.open
|
|
|
|
def test_app_promotions_and_typographic_variants_are_rejected(self):
|
|
self.open()
|
|
for text in [
|
|
'نورتون', 'نُوْرتـو\u200cن', 'N O R T O N',
|
|
'آموزش زبان به سبک موسویباکس',
|
|
'آموزش زبان به سبک مووی باکس',
|
|
'آموزش زبان به سبک مُووی باكْس',
|
|
'نسخه جدید هورتون', 'نسخه جدید هُورتـون',
|
|
'اپلیکیشن هورتون', 'نرم افزار هورتون',
|
|
]:
|
|
with self.subTest(text=text):
|
|
self.assertFalse(self.api.allowed_text(text))
|
|
for text in [
|
|
'Horton Hears a Who!', 'نام پارسی انیمیشن: هورتون',
|
|
'آموزش زبان New Headway', 'The Marriage App',
|
|
'فیلمی درباره یک اپلیکیشن خیالی', 'بازیگران: Alex Horton',
|
|
]:
|
|
with self.subTest(text=text):
|
|
self.assertTrue(self.api.allowed_text(text))
|
|
|
|
def test_ads_are_absent_from_every_title_surface_and_direct_lookup(self):
|
|
with sqlite3.connect(self.path) as db:
|
|
original = json.loads(db.execute('SELECT raw_json FROM titles WHERE id=1').fetchone()[0])
|
|
records = [
|
|
(66, 'نورتون', ''),
|
|
(67, 'آموزش زبان به سبک مووی باکس', ''),
|
|
(68, 'آموزش زبان به سبک موسویباکس', ''),
|
|
(69, 'نسخه جدید هورتون', ''),
|
|
(70, 'Horton Hears a Who!', 'نام پارسی انیمیشن: هورتون'),
|
|
(71, 'آموزش زبان New Headway', 'مجموعه ویدیویی آموزش مهارت مکالمه'),
|
|
(72, 'The Marriage App', 'فیلمی درباره یک اپلیکیشن خیالی'),
|
|
(73, 'Language companion', 'اپلیکیشن هورتون'),
|
|
]
|
|
for title_id, title, description in records:
|
|
raw = {**original, 'id': title_id, 'title': title, 'description': description}
|
|
db.execute('INSERT INTO titles(id,type,title,description,year,imdb,rating,raw_json) VALUES (?,?,?,?,?,?,?,?)',
|
|
(title_id, 'movie', title, description, 2026, 9.9, 5, json.dumps(raw)))
|
|
db.execute('INSERT INTO title_genres VALUES (?,2)', (title_id,))
|
|
db.execute('INSERT INTO title_countries VALUES (?,1)', (title_id,))
|
|
catalog = self.open()
|
|
ads = {66, 67, 68, 69, 73}
|
|
actual = set()
|
|
for page in range(4):
|
|
for order in ['created', 'imdb', 'rating', 'year', 'title', 'random']:
|
|
for path in [f'/api/movie/by/filtres/0/{order}/{page}/public/',
|
|
f'/api/poster/by/filtres/2/1/{order}/{page}/public/']:
|
|
rows = catalog.dispatch(path)
|
|
self.assertFalse(ads & {row['id'] for row in rows}, path)
|
|
actual.update(row['id'] for row in rows)
|
|
self.assertTrue({70, 71, 72} <= actual)
|
|
for group in catalog.dispatch('/api/first/public/')['genres']:
|
|
self.assertFalse(ads & {row['id'] for row in group['posters']})
|
|
for action in ['best-rand-top', 'best-rand-year']:
|
|
rows = catalog.dispatch('/api-user/newapi/like.php?' + urlencode({'action': action}))
|
|
self.assertFalse(ads & {row['id'] for row in rows})
|
|
for query in ['نورتون', 'هورتون', 'آموزش زبان', 'موسوی', 'مووی', 'Language companion']:
|
|
rows = catalog.dispatch('/api-user/newapi/like.php?' + urlencode({'action': 'search-movie', 'q': query}))
|
|
self.assertFalse(ads & {row['id'] for row in rows}, query)
|
|
rows = catalog.dispatch('/api-user/newapi/filter.php?action=pishnahad&garid=2&pageno=1')
|
|
self.assertFalse(ads & {row['id'] for row in rows})
|
|
for title_id in ads:
|
|
for path in [f'/api/movie/by/{title_id}/public/', f'/api/season/by/serie/{title_id}/public/']:
|
|
with self.assertRaises(self.api.ApiError) as error:
|
|
catalog.dispatch(path)
|
|
self.assertEqual(error.exception.status, 404)
|
|
for title_id in [70, 71, 72]:
|
|
self.assertEqual(catalog.dispatch(f'/api/movie/by/{title_id}/public/')['id'], title_id)
|
|
detail = catalog.dispatch('/api/movie/by/1/public/')
|
|
self.assertEqual(detail['sources'], original['sources'])
|