Skip to content

Commit

Permalink
chore(tests): Fix hardcoded year in magic link test data
Browse files Browse the repository at this point in the history
  • Loading branch information
birkjernstrom committed Jan 2, 2025
1 parent c1aa4be commit d7c5e9f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
26 changes: 16 additions & 10 deletions server/tests/magic_link/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
from pytest_mock import MockerFixture

from polar.config import settings
from polar.kit import template
from polar.kit.crypto import generate_token_hash_pair, get_token_hash
from polar.kit.db.postgres import AsyncSession
from polar.kit.utils import utc_now
from polar.magic_link.service import InvalidMagicLink
from polar.magic_link.service import magic_link as magic_link_service
from polar.models import MagicLink, User
Expand Down Expand Up @@ -105,15 +107,17 @@ async def test_send(

# Run with `POLAR_TEST_RECORD=1 pytest` to produce new golden files :-)
record = os.environ.get("POLAR_TEST_RECORD", False) == "1"
record_file_name = "./tests/magic_link/testdata/magic_link.html"
record_file_path = template.path(__file__, "testdata/magic_link.html")

if record:
with open(record_file_name, "w+") as f:
with open(record_file_path, "w+") as f:
f.write(sent_content)

with open(record_file_name) as f:
content = f.read()
assert content == sent_content
content = template.render(
record_file_path,
year=str(utc_now().year),
)
assert content == sent_content


@pytest.mark.asyncio
Expand All @@ -139,15 +143,17 @@ async def test_send_return_to(

# Run with `POLAR_TEST_RECORD=1 pytest` to produce new golden files :-)
record = os.environ.get("POLAR_TEST_RECORD", False) == "1"
record_file_name = "./tests/magic_link/testdata/magic_link_return_to.html"
record_file_path = template.path(__file__, "testdata/magic_link_return_to.html")

if record:
with open(record_file_name, "w+") as f:
with open(record_file_path, "w+") as f:
f.write(sent_content)

with open(record_file_name) as f:
content = f.read()
assert content == sent_content
content = template.render(
record_file_path,
year=str(utc_now().year),
)
assert content == sent_content


@pytest.mark.asyncio
Expand Down
2 changes: 1 addition & 1 deletion server/tests/magic_link/testdata/magic_link.html
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ <h1>Hi,</h1>
<tr>
<td class="content-cell" align="center">
<p class="f-fallback sub align-center">
Polar Software Inc 2024
Polar Software Inc {{year}}
</p>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion server/tests/magic_link/testdata/magic_link_return_to.html
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ <h1>Hi,</h1>
<tr>
<td class="content-cell" align="center">
<p class="f-fallback sub align-center">
Polar Software Inc 2024
Polar Software Inc {{year}}
</p>
</td>
</tr>
Expand Down

0 comments on commit d7c5e9f

Please sign in to comment.