test: fix tests

This commit is contained in:
2026-07-01 21:05:49 +03:00
parent 0730b9f567
commit fcb000afb0
10 changed files with 140 additions and 41 deletions

View File

@@ -2,8 +2,6 @@ import datetime
import json import json
import logging import logging
from bs4 import BeautifulSoup
from gallery.sketch.schedule.api import ScheduleApi from gallery.sketch.schedule.api import ScheduleApi
from gallery.sketch.schedule.model import Channel, Schedule, ScheduleValue from gallery.sketch.schedule.model import Channel, Schedule, ScheduleValue
from gallery.sketch.source import ApiSource from gallery.sketch.source import ApiSource
@@ -55,34 +53,3 @@ class MatchTvApi(ScheduleApi):
date=date, date=date,
values=values, values=values,
) )
async def get_schedule_legacy(self, channel_id: str, date: datetime.date) -> Schedule:
endpoint = f"tvguide/{channel_id}?date={date:%Y%m%d}"
data = await self.SOURCE.request(endpoint)
soup = BeautifulSoup(data, features="html.parser")
values = []
channel_name = soup.select_one(".p-tv-guide-header__title").text.replace("Телепрограмма ", "").strip()
current_day = datetime.datetime.combine(date.today(), datetime.datetime.min.time())
end = current_day + datetime.timedelta(days=1, hours=6)
prev_value: ScheduleValue | None = None
for item in soup.select(
".p-tv-guide-schedule-channel-carcass__transmissions .p-tv-guide-schedule-channel-transmission"
):
title = item.select_one(".p-tv-guide-schedule-channel-transmission__title").text.strip()
time_str = item.select_one(".p-tv-guide-schedule-channel-transmission__time-block").text.strip()
hours, minutes = map(int, time_str.split(":"))
item_date = current_day.replace(hour=hours, minute=minutes)
if prev_value is not None and item_date.hour < prev_value.start.hour:
current_day += datetime.timedelta(days=1)
item_date += datetime.timedelta(days=1)
live = "Прямая трансляция" in title
value = ScheduleValue(start=item_date, end=end, label=title, live=live)
values.append(value)
if prev_value is not None:
prev_value.end = item_date
prev_value = value
return Schedule(
channel=Channel(id=channel_id, name=channel_name, provider=self.provider),
date=date,
values=values,
)

View File

@@ -2,4 +2,4 @@
set -e set -e
cd "$(dirname $(dirname "$0"))" || exit cd "$(dirname $(dirname "$0"))" || exit
poetry run pytest tests OPENWEATHER_KEY="" poetry run pytest tests

View File

@@ -5,7 +5,7 @@ from tests.common.mock import MockSource
MATCHTV_MOCK_SOURCE = MockSource( MATCHTV_MOCK_SOURCE = MockSource(
Path(__file__).parent, Path(__file__).parent,
{ {
"test": "test.html", "test": "test.json",
"channels": "channels.json", "channels": "channels.json",
}, },
) )

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,115 @@
{
"result": {
"info": {
"filters": [
"\u0444\u0443\u0442\u0431\u043e\u043b",
"\u0445\u043e\u043a\u043a\u0435\u0439",
"\u0435\u0434\u0438\u043d\u043e\u0431\u043e\u0440\u0441\u0442\u0432\u0430",
"\u0431\u0430\u0441\u043a\u0435\u0442\u0431\u043e\u043b",
"\u0431\u0438\u0430\u0442\u043b\u043e\u043d",
"\u043b\u044b\u0436\u0438"
],
"availableDates": { "min": "2026-06-24T00:00:00+03:00", "max": "2026-07-05T00:00:00+03:00" }
},
"channels": [
{
"id": 10,
"tvChannelId": 130,
"alias": "matchtv",
"name": "\u041c\u0430\u0442\u0447 \u0422\u0412",
"url": "\/channel\/matchtv",
"icon": "https:\/\/fb-cdn.matchtv.ru\/files\/default\/upload\/4fbd\/42cc\/4fbd42ccdde063ff630a7970dbce1034.png",
"currentTransmissionProgress": 97,
"schedule": [
{
"time": "06:00",
"title": "\u0412\u0441\u0435 \u043d\u0430 \u041c\u0430\u0442\u0447! \u041f\u0440\u044f\u043c\u043e\u0439 \u044d\u0444\u0438\u0440",
"genre": "",
"current": false
},
{ "time": "09:00", "title": "\u041d\u043e\u0432\u043e\u0441\u0442\u0438", "genre": "", "current": false },
{
"time": "09:05",
"title": "\u0424\u0443\u0442\u0431\u043e\u043b. \u0427\u0435\u043c\u043f\u0438\u043e\u043d\u0430\u0442 \u043c\u0438\u0440\u0430-2026. 1\/16 \u0444\u0438\u043d\u0430\u043b\u0430. \u041a\u043e\u0442-\u0434\u0027\u0418\u0432\u0443\u0430\u0440 - \u041d\u043e\u0440\u0432\u0435\u0433\u0438\u044f. \u0422\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u044f \u0438\u0437 \u0421\u0428\u0410 [6+]",
"genre": "\u0444\u0443\u0442\u0431\u043e\u043b",
"current": false
},
{
"time": "11:20",
"title": "\u0423\u043b\u0451\u0442\u043d\u044b\u0439 \u0444\u0443\u0442\u0431\u043e\u043b. \u041f\u0440\u044f\u043c\u043e\u0439 \u044d\u0444\u0438\u0440",
"genre": "",
"current": false
},
{
"time": "12:10",
"title": "\u0424\u0443\u0442\u0431\u043e\u043b. \u0427\u0435\u043c\u043f\u0438\u043e\u043d\u0430\u0442 \u043c\u0438\u0440\u0430-2026. \u041e\u0431\u0437\u043e\u0440 [6+]",
"genre": "",
"current": false
},
{ "time": "12:40", "title": "\u041d\u043e\u0432\u043e\u0441\u0442\u0438", "genre": "", "current": false },
{
"time": "12:45",
"title": "\u0424\u0443\u0442\u0431\u043e\u043b. \u0427\u0435\u043c\u043f\u0438\u043e\u043d\u0430\u0442 \u043c\u0438\u0440\u0430-2026. 1\/16 \u0444\u0438\u043d\u0430\u043b\u0430. \u041c\u0435\u043a\u0441\u0438\u043a\u0430 - \u042d\u043a\u0432\u0430\u0434\u043e\u0440. \u0422\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u044f \u0438\u0437 \u041c\u0435\u043a\u0441\u0438\u043a\u0438 [6+]",
"genre": "\u0444\u0443\u0442\u0431\u043e\u043b",
"current": false
},
{
"time": "15:00",
"title": "\u0424\u0443\u0442\u0431\u043e\u043b. \u0427\u0435\u043c\u043f\u0438\u043e\u043d\u0430\u0442 \u043c\u0438\u0440\u0430-2026. 1\/16 \u0444\u0438\u043d\u0430\u043b\u0430. \u0424\u0440\u0430\u043d\u0446\u0438\u044f - \u0428\u0432\u0435\u0446\u0438\u044f. \u0422\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u044f \u0438\u0437 \u0421\u0428\u0410 [6+]",
"genre": "\u0444\u0443\u0442\u0431\u043e\u043b",
"current": false
},
{
"time": "17:15",
"title": "\u0424\u0443\u0442\u0431\u043e\u043b. \u0427\u0435\u043c\u043f\u0438\u043e\u043d\u0430\u0442 \u043c\u0438\u0440\u0430-2026. \u041e\u0431\u0437\u043e\u0440 [6+]",
"genre": "",
"current": false
},
{ "time": "17:45", "title": "\u041d\u043e\u0432\u043e\u0441\u0442\u0438", "genre": "", "current": false },
{
"time": "17:50",
"title": "\u0412\u0441\u0435 \u043d\u0430 \u041c\u0430\u0442\u0447! \u041f\u0440\u044f\u043c\u043e\u0439 \u044d\u0444\u0438\u0440",
"genre": "",
"current": false
},
{
"time": "18:30",
"title": "\u0424\u0443\u0442\u0431\u043e\u043b. \u0427\u0435\u043c\u043f\u0438\u043e\u043d\u0430\u0442 \u043c\u0438\u0440\u0430-2026. 1\/16 \u0444\u0438\u043d\u0430\u043b\u0430. \u0410\u043d\u0433\u043b\u0438\u044f - \u0414\u0420 \u041a\u043e\u043d\u0433\u043e. \u041f\u0440\u044f\u043c\u0430\u044f \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u044f \u0438\u0437 \u0421\u0428\u0410",
"genre": "\u0444\u0443\u0442\u0431\u043e\u043b",
"current": true
},
{
"time": "21:05",
"title": "\u0412\u0441\u0435 \u043d\u0430 \u041c\u0430\u0442\u0447! \u041f\u0440\u044f\u043c\u043e\u0439 \u044d\u0444\u0438\u0440",
"genre": "",
"current": false
},
{
"time": "22:00",
"title": "\u0424\u0443\u0442\u0431\u043e\u043b. \u0427\u0435\u043c\u043f\u0438\u043e\u043d\u0430\u0442 \u043c\u0438\u0440\u0430-2026. 1\/16 \u0444\u0438\u043d\u0430\u043b\u0430. \u0411\u0435\u043b\u044c\u0433\u0438\u044f - \u0421\u0435\u043d\u0435\u0433\u0430\u043b. \u041f\u0440\u044f\u043c\u0430\u044f \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u044f \u0438\u0437 \u0421\u0428\u0410",
"genre": "\u0444\u0443\u0442\u0431\u043e\u043b",
"current": false
},
{
"time": "01:05",
"title": "\u0412\u0441\u0435 \u043d\u0430 \u041c\u0430\u0442\u0447! \u041f\u0440\u044f\u043c\u043e\u0439 \u044d\u0444\u0438\u0440",
"genre": "",
"current": false
},
{
"time": "02:00",
"title": "\u0424\u0443\u0442\u0431\u043e\u043b. \u0427\u0435\u043c\u043f\u0438\u043e\u043d\u0430\u0442 \u043c\u0438\u0440\u0430-2026. 1\/16 \u0444\u0438\u043d\u0430\u043b\u0430. \u0421\u0428\u0410 - \u0411\u043e\u0441\u043d\u0438\u044f \u0438 \u0413\u0435\u0440\u0446\u0435\u0433\u043e\u0432\u0438\u043d\u0430. \u041f\u0440\u044f\u043c\u0430\u044f \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u044f \u0438\u0437 \u0421\u0428\u0410",
"genre": "\u0444\u0443\u0442\u0431\u043e\u043b",
"current": false
},
{
"time": "05:05",
"title": "\u0412\u0441\u0435 \u043d\u0430 \u041c\u0430\u0442\u0447! \u041f\u0440\u044f\u043c\u043e\u0439 \u044d\u0444\u0438\u0440",
"genre": "",
"current": false
}
]
}
]
}
}

View File

@@ -6,6 +6,7 @@ OPENWEATHER_MOCK_SOURCE = MockSource(
Path(__file__).parent, Path(__file__).parent,
{ {
"forecast": "forecast.json", "forecast": "forecast.json",
"direct": "geo-direct.json", "direct": "direct.json",
"reverse": "reverse.json",
}, },
) )

View File

@@ -0,0 +1,18 @@
[
{
"name": "Oryol",
"local_names": {
"be": "Арол",
"ca": "Oriol",
"cs": "Orjol",
"de": "Orjol",
"en": "Oryol",
"ru": "Орёл",
"sr": "Орел"
},
"lat": 52.968017149999994,
"lon": 36.09949941816104,
"country": "RU",
"state": "Oryol Oblast"
}
]

View File

@@ -19,6 +19,6 @@ async def test_search(matchtv_api: MatchTvApi):
async def test_channel(matchtv_api: MatchTvApi): async def test_channel(matchtv_api: MatchTvApi):
result = await matchtv_api.get_channel_schedule("test", datetime.date.today()) result = await matchtv_api.get_schedule("test", datetime.date.today())
assert result is not None assert result is not None
assert len(result.values) > 0 assert len(result.values) > 0

View File

@@ -15,10 +15,10 @@ def yandextv_api_fixture() -> YandexTvApi:
async def test_search(yandextv_api: YandexTvApi): async def test_search(yandextv_api: YandexTvApi):
result = await yandextv_api.find_channels("матч") result = await yandextv_api.find_channels("матч")
assert len(result) == 8 assert len(result) == 4
async def test_channel(yandextv_api: YandexTvApi): async def test_channel(yandextv_api: YandexTvApi):
result = await yandextv_api.get_channel_schedule("test", datetime.date.today()) result = await yandextv_api.get_schedule("test", datetime.date.today())
assert result is not None assert result is not None
assert len(result.values) > 0 assert len(result.values) > 0