Update
This commit is contained in:
parent
aca07828f1
commit
9e836ea152
@ -135,19 +135,20 @@ def seed_data(environment, **kwargs):
|
|||||||
|
|
||||||
logger.info(f"Created {len(POST_UIDS)} seed posts")
|
logger.info(f"Created {len(POST_UIDS)} seed posts")
|
||||||
|
|
||||||
for seed in SEED_USERS[:2]:
|
for post_uid in POST_UIDS:
|
||||||
try:
|
for seed in SEED_USERS[:2]:
|
||||||
opener = logged_in_opener(seed["email"])
|
try:
|
||||||
body = urllib.parse.urlencode({
|
opener = logged_in_opener(seed["email"])
|
||||||
"content": f"Seed comment by {seed['username']}",
|
body = urllib.parse.urlencode({
|
||||||
"post_uid": POST_UIDS[0],
|
"content": f"Seed comment by {seed['username']}",
|
||||||
}).encode()
|
"post_uid": post_uid,
|
||||||
opener.open(
|
}).encode()
|
||||||
urllib.request.Request(f"{host}/comments/create", data=body),
|
opener.open(
|
||||||
timeout=10,
|
urllib.request.Request(f"{host}/comments/create", data=body),
|
||||||
)
|
timeout=10,
|
||||||
except Exception as e:
|
)
|
||||||
logger.warning(f"Create seed comment failed: {e}")
|
except Exception as e:
|
||||||
|
logger.warning(f"Create seed comment failed: {e}")
|
||||||
|
|
||||||
for seed in SEED_USERS[:2]:
|
for seed in SEED_USERS[:2]:
|
||||||
try:
|
try:
|
||||||
@ -306,11 +307,11 @@ def seed_data(environment, **kwargs):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Harvest from {seed['username']} failed: {e}")
|
logger.warning(f"Harvest from {seed['username']} failed: {e}")
|
||||||
|
|
||||||
if POST_UIDS:
|
for post_uid in POST_UIDS:
|
||||||
try:
|
try:
|
||||||
opener = logged_in_opener(SEED_USERS[0]["email"])
|
opener = logged_in_opener(SEED_USERS[0]["email"])
|
||||||
resp = opener.open(
|
resp = opener.open(
|
||||||
urllib.request.Request(f"{host}/posts/{POST_UIDS[0]}"),
|
urllib.request.Request(f"{host}/posts/{post_uid}"),
|
||||||
timeout=10,
|
timeout=10,
|
||||||
)
|
)
|
||||||
html = resp.read().decode("utf-8", errors="replace")
|
html = resp.read().decode("utf-8", errors="replace")
|
||||||
@ -1021,3 +1022,70 @@ class AdminUser(HttpUser):
|
|||||||
self.client.post(
|
self.client.post(
|
||||||
f"/admin/users/{uid}/toggle", name="admin/users/toggle"
|
f"/admin/users/{uid}/toggle", name="admin/users/toggle"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AnonymousUser(HttpUser):
|
||||||
|
weight = 3
|
||||||
|
wait_time = between(1, 5)
|
||||||
|
|
||||||
|
@task(5)
|
||||||
|
def browse_feed(self):
|
||||||
|
self.client.get("/feed", name="feed")
|
||||||
|
|
||||||
|
@task(3)
|
||||||
|
def browse_post(self):
|
||||||
|
if POST_SLUGS:
|
||||||
|
self.client.get(
|
||||||
|
f"/posts/{random.choice(POST_SLUGS)}", name="posts/[uid]"
|
||||||
|
)
|
||||||
|
|
||||||
|
@task(2)
|
||||||
|
def browse_public(self):
|
||||||
|
path = random.choice([
|
||||||
|
"/", "/news", "/gists", "/projects", "/leaderboard",
|
||||||
|
])
|
||||||
|
self.client.get(path, name="public/[page]")
|
||||||
|
|
||||||
|
@task(2)
|
||||||
|
def browse_detail(self):
|
||||||
|
if NEWS_SLUGS:
|
||||||
|
self.client.get(
|
||||||
|
f"/news/{random.choice(NEWS_SLUGS)}", name="news/[slug]"
|
||||||
|
)
|
||||||
|
if GIST_SLUGS:
|
||||||
|
self.client.get(
|
||||||
|
f"/gists/{random.choice(GIST_SLUGS)}", name="gists/[slug]"
|
||||||
|
)
|
||||||
|
if PROJECT_SLUGS:
|
||||||
|
self.client.get(
|
||||||
|
f"/projects/{random.choice(PROJECT_SLUGS)}", name="projects/[slug]"
|
||||||
|
)
|
||||||
|
|
||||||
|
@task(2)
|
||||||
|
def guest_vote_redirects_to_login(self):
|
||||||
|
if not POST_UIDS:
|
||||||
|
return
|
||||||
|
uid = random.choice(POST_UIDS)
|
||||||
|
with self.client.post(
|
||||||
|
f"/votes/post/{uid}", data={"value": 1},
|
||||||
|
headers={"x-requested-with": "fetch"},
|
||||||
|
catch_response=True, name="votes/post/guest-redirect",
|
||||||
|
) as resp:
|
||||||
|
if "/auth/login" in resp.url:
|
||||||
|
resp.success()
|
||||||
|
else:
|
||||||
|
resp.failure(f"guest vote not redirected to login: {resp.url}")
|
||||||
|
|
||||||
|
@task(1)
|
||||||
|
def guest_guarded_get_redirects_to_login(self):
|
||||||
|
with self.client.get(
|
||||||
|
"/messages", catch_response=True, name="guarded/guest-redirect",
|
||||||
|
) as resp:
|
||||||
|
if "/auth/login" in resp.url:
|
||||||
|
resp.success()
|
||||||
|
else:
|
||||||
|
resp.failure(f"guarded GET not redirected to login: {resp.url}")
|
||||||
|
|
||||||
|
@task(1)
|
||||||
|
def login_with_next(self):
|
||||||
|
self.client.get("/auth/login", params={"next": "/feed"}, name="auth/login?next")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user