mirror of
https://github.com/ihabunek/toot
synced 2025-02-03 20:57:38 +01:00
Implement base_url as fixture
This commit is contained in:
parent
56cc056639
commit
4df2abf5cd
@ -25,9 +25,6 @@ from toot.console import run_command
|
||||
from toot.exceptions import ApiError, ConsoleError
|
||||
from toot.output import print_out
|
||||
|
||||
# Host name of a test instance to run integration tests against
|
||||
# DO NOT USE PUBLIC INSTANCES!!!
|
||||
BASE_URL = os.getenv("TOOT_TEST_BASE_URL")
|
||||
|
||||
# Mastodon database name, used to confirm user registration without having to click the link
|
||||
DATABASE_DSN = os.getenv("TOOT_TEST_DATABASE_DSN")
|
||||
@ -38,17 +35,10 @@ TRUMPET = str(Path(__file__).parent.parent.parent / "trumpet.png")
|
||||
ASSETS_DIR = str(Path(__file__).parent.parent / "assets")
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Fixtures
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def create_app():
|
||||
if not BASE_URL:
|
||||
pytest.skip("Skipping integration tests, BASE_URL not set")
|
||||
instance = api.get_instance(BASE_URL)
|
||||
response = api.create_app(BASE_URL)
|
||||
return App(instance["uri"], BASE_URL, response["client_id"], response["client_secret"])
|
||||
def create_app(base_url):
|
||||
instance = api.get_instance(base_url)
|
||||
response = api.create_app(base_url)
|
||||
return App(instance["uri"], base_url, response["client_id"], response["client_secret"])
|
||||
|
||||
|
||||
def register_account(app: App):
|
||||
@ -67,9 +57,26 @@ def confirm_user(email):
|
||||
conn.commit()
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Fixtures
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# Host name of a test instance to run integration tests against
|
||||
# DO NOT USE PUBLIC INSTANCES!!!
|
||||
@pytest.fixture(scope="session")
|
||||
def app():
|
||||
return create_app()
|
||||
def base_url():
|
||||
base_url = os.getenv("TOOT_TEST_BASE_URL")
|
||||
|
||||
if not base_url:
|
||||
pytest.skip("Skipping integration tests, TOOT_TEST_BASE_URL not set")
|
||||
|
||||
return base_url
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def app(base_url):
|
||||
return create_app(base_url)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
|
@ -1,6 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from tests.integration.conftest import BASE_URL
|
||||
from toot import api
|
||||
from toot.exceptions import ConsoleError
|
||||
|
||||
@ -12,8 +11,8 @@ def test_instance(app, run):
|
||||
assert "running Mastodon" in out
|
||||
|
||||
|
||||
def test_instance_anon(app, run_anon):
|
||||
out = run_anon("instance", BASE_URL)
|
||||
def test_instance_anon(app, run_anon, base_url):
|
||||
out = run_anon("instance", base_url)
|
||||
assert "Mastodon" in out
|
||||
assert app.instance in out
|
||||
assert "running Mastodon" in out
|
||||
@ -57,7 +56,7 @@ def test_search_hashtag(app, user, run):
|
||||
assert out == "Hashtags:\n#hashtag_x, #hashtag_y, #hashtag_z"
|
||||
|
||||
|
||||
def test_tags(run):
|
||||
def test_tags(run, base_url):
|
||||
out = run("tags_followed")
|
||||
assert out == "You're not following any hashtags."
|
||||
|
||||
@ -65,19 +64,19 @@ def test_tags(run):
|
||||
assert out == "✓ You are now following #foo"
|
||||
|
||||
out = run("tags_followed")
|
||||
assert out == f"* #foo\t{BASE_URL}/tags/foo"
|
||||
assert out == f"* #foo\t{base_url}/tags/foo"
|
||||
|
||||
out = run("tags_follow", "bar")
|
||||
assert out == "✓ You are now following #bar"
|
||||
|
||||
out = run("tags_followed")
|
||||
assert out == "\n".join([
|
||||
f"* #bar\t{BASE_URL}/tags/bar",
|
||||
f"* #foo\t{BASE_URL}/tags/foo",
|
||||
f"* #bar\t{base_url}/tags/bar",
|
||||
f"* #foo\t{base_url}/tags/foo",
|
||||
])
|
||||
|
||||
out = run("tags_unfollow", "foo")
|
||||
assert out == "✓ You are no longer following #foo"
|
||||
|
||||
out = run("tags_followed")
|
||||
assert out == f"* #bar\t{BASE_URL}/tags/bar"
|
||||
assert out == f"* #bar\t{base_url}/tags/bar"
|
||||
|
Loading…
x
Reference in New Issue
Block a user