chore: checkpoint baseline (routers, tests, pyproject)
This commit is contained in:
parent
a58498a315
commit
986f1dfef4
37 changed files with 2527 additions and 1664 deletions
43
tests/test_reddit_client.py
Normal file
43
tests/test_reddit_client.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
"""Tests for Reddit client."""
|
||||
|
||||
import time
|
||||
|
||||
from src.reddit_client import Post, RateLimiter
|
||||
|
||||
|
||||
class TestRateLimiter:
|
||||
def test_first_request_no_wait(self):
|
||||
limiter = RateLimiter(requests_per_minute=60)
|
||||
start = time.time()
|
||||
limiter.wait()
|
||||
elapsed = time.time() - start
|
||||
assert elapsed < 0.1
|
||||
|
||||
def test_respects_rate_limit(self):
|
||||
limiter = RateLimiter(requests_per_minute=120) # 0.5s interval
|
||||
limiter.wait()
|
||||
limiter.last_request = time.time() # simulate request just happened
|
||||
start = time.time()
|
||||
limiter.wait()
|
||||
elapsed = time.time() - start
|
||||
assert elapsed >= 0.4 # Should wait ~0.5s
|
||||
|
||||
|
||||
class TestPost:
|
||||
def test_post_creation(self):
|
||||
post = Post(
|
||||
id="test",
|
||||
subreddit="pics",
|
||||
author="user",
|
||||
title="Title",
|
||||
url="https://example.com",
|
||||
score=100,
|
||||
created_utc=1700000000.0,
|
||||
over_18=False,
|
||||
is_gallery=False,
|
||||
preview=None,
|
||||
media_metadata=None,
|
||||
)
|
||||
assert post.id == "test"
|
||||
assert post.permalink is None
|
||||
assert post.flair is None
|
||||
Loading…
Add table
Add a link
Reference in a new issue