Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
chore: Removed slow test cases (only take 0.1 seconds now)
Browse files Browse the repository at this point in the history
  • Loading branch information
dikayx committed Aug 5, 2024
1 parent a3babaf commit c198bd9
Showing 1 changed file with 2 additions and 44 deletions.
46 changes: 2 additions & 44 deletions tests/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,57 +31,15 @@ def test_submit_form_elements(client):
assert b'Paste the email data here...' in response.data


# Test the CSRF token is included in the form
def test_csrf_token_in_form(client):
response = client.get('/')
assert b'name="csrf_token"' in response.data


# Test the CSRF token has a valid value
# Test the CSRF token is included and has a value
def test_csrf_token_value_print(client):
response = client.get('/')
assert b'name="csrf_token"' in response.data
csrf_token_regex = rb'<input\n\s*type="hidden"\n\s*name="csrf_token"\n\s*value="[^"]+"\n\s*/>'
csrf_token = re.search(csrf_token_regex, response.data).group(0)
assert csrf_token


# Test valid data submission
def test_valid_data_submission(client):
valid_headers = """Return-Path: <[email protected]>
Authentication-Results: gmx.net; dkim=pass [email protected]
Received: from mout-csbulk.1and1.com ([212.227.15.53]) by mx-ha.gmx.net
(mxgmx103 [212.227.17.5]) with ESMTPS (Nemesis) id 1MeCZ5-1nWyOC0iSF-00bMu8
for <[email protected]>; Thu, 30 Jun 2022 12:47:23 +0200
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mailings.gmx.net;
s=isystem1; t=1656586043;
bh=zi4FqYIdpIwcsf+sK0WA75BbiA5zVTCs/dPw6mK+63Y=;
h=X-UI-Sender-Class:Date:To:From:Reply-To:Subject;
b=D/x4ENmFX26x0Yfir0uzyaDldP00MNpErNvYpU8FKs6E+QxC5a8hvWuvZNBvMkEp3
Jaui124uVl4eqGhgwHeeRht2KGErlPr90RwShXzHDTutfK8dE8iB8/Vnh/MUyWdJzE
AGicEqtR+Sbb3GA5tI0TjuT8AHeu2SjfW1+6pnPM=
X-UI-Sender-Class: b1815dde-56d5-42be-91f0-18350f97da04
Received: from esix-sender-gmx-bs04.ui-portal.com ([10.74.4.16]) by
mrs-csbulk.1and1.com (mrsbulk009 [172.19.128.198]) with ESMTPSA (Nemesis) id
0LgNmu-1nJRz43zSG-00nlFe for < [email protected]>; Thu, 30 Jun 2022
12:47:23 +0200
Date: Thu, 30 Jun 2022 12:47:22 +0200
To: [email protected]
From: GMX Magazin <[email protected]>
Reply-To: [email protected]
Subject: Ihr Stromtarif + iPad oder 4K-TV
Message-ID: <E5-3hqyee3o-elaine/10/[email protected]>
…"""

response = client.get('/')
csrf_token_regex = rb'<input\n\s*type="hidden"\n\s*name="csrf_token"\n\s*value="[^"]+"\n\s*/>'
# Extract only the value of the CSRF token
csrf_token = re.search(csrf_token_regex, response.data).group(0)
csrf_token = csrf_token.split(b'value="')[1].split(b'"')[0]

post_response = client.post('/', data={'headers': valid_headers, 'csrf_token': csrf_token}, follow_redirects=True)
assert post_response.status_code == 200


# Test invalid data submission
def test_invalid_data_submission(client):
invalid_headers = "Not a valid email header"
Expand Down

0 comments on commit c198bd9

Please sign in to comment.