Skip to content

Commit

Permalink
Merge pull request #561 from ChanceM/fix/test-builds
Browse files Browse the repository at this point in the history
  • Loading branch information
CGBassPlayer authored Sep 7, 2023
2 parents 37ab978 + aa6cfba commit a26f6c8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
3 changes: 2 additions & 1 deletion Dockerfile.tests
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# python3.10, and is latest version (python verison pinned in the test/Pipfile as well (make sure to change there as well))
FROM mcr.microsoft.com/playwright/python:v1.25.2-jammy

RUN pip install pipenv
# Rollback and pin version as there is a bug in the l
RUN pip install pipenv==2023.7.23

CMD [ "--base-url", "http://localhost:1313", "-m", "not periodic" ]
ENTRYPOINT [ "pytest" ]
Expand Down
27 changes: 14 additions & 13 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from _pytest.fixtures import SubRequest
from pytest_base_url.plugin import base_url
from playwright.sync_api import Playwright, APIRequestContext, Route, Page, Browser
import json

@fixture
def get_test_dir() -> Path:
Expand Down Expand Up @@ -47,7 +48,7 @@ def mobile_device_tuple(
# so we're not having to hard-code the URL
base_url: base_url,
) -> Tuple[Page,str]:

# based on here: https://playwright.dev/python/docs/emulation#devices
context = browser.new_context(
base_url=base_url,
Expand Down Expand Up @@ -154,28 +155,28 @@ def expect_nav_items() -> List[Dict[str,str]]:
]

@fixture
def get_live_event(get_test_dir: Path) -> str:
return Path(get_test_dir / 'fixture_files/jb-live_sample-live-event.json').read_text()

@fixture
def set_live(get_live_event: str) -> Tuple[Callable, str]:
return (_replace_live_event,get_live_event)
# return replace_live_event
def set_live() -> Callable:
return _replace_live_event

@staticmethod
def _replace_live_event(page: Page, live_event: str) -> None:
def _replace_live_event(page: Page) -> None:
def handle_route(route: Route) -> None:
# fetch original response
response = page.request.fetch(route.request)
json_data = response.json()

# override response values
if json_data.get('data'):
json_data['data'][0]['isLive'] = True
json_data['total'] = 1

# setting live event
route.fulfill(
# Pass all fields from the response
response=response,
# override body
body=live_event.strip()
body=json.dumps(json_data),
)
page.route(
"https://jupiter.tube/api/v1/video-channels/live/videos?isLive=true&skipCount=false&count=1&sort=-createdAt",
"https://jupiter.tube/api/v1/video-channels/live/**",
handle_route
)
)
19 changes: 5 additions & 14 deletions test/e2e/test_live.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
from pathlib import Path
from typing import Tuple, Callable
from playwright.sync_api import Page, expect, Locator, FrameLocator

from playwright.sync_api import Page, expect, Locator, FrameLocator, Route

def test_live_indicator(
page: Page,
set_live: Tuple[Callable, str],
set_live: Callable,
screenshot_dir: Path,
):
# explicitly defining tuple objects for clarity
replace_live_event: Callable = set_live[0]
live_event: str = set_live[1]

# intercepting reponses for live event, and make live
replace_live_event(page, live_event)
set_live(page)

# go to the live page
page.goto("/live")
Expand All @@ -36,13 +31,9 @@ def test_live_indicator(

def test_mobile_live_indicator(
mobile_device_tuple: Tuple[Page, str],
set_live: Tuple[Callable, str],
set_live: Callable,
screenshot_dir: Path,
):
# explicitly defining tuple objects for clarity
replace_live_event: Callable = set_live[0]
live_event: str = set_live[1]

# set mobile page to variable
mobile_device = mobile_device_tuple[0]
# set screenshot dir for mobile device
Expand All @@ -51,7 +42,7 @@ def test_mobile_live_indicator(
)

# intercepting reponses for live event, and make live
replace_live_event(mobile_device, live_event)
set_live(mobile_device)

mobile_device.goto("/live")

Expand Down

0 comments on commit a26f6c8

Please sign in to comment.