Skip to content

Commit

Permalink
Reformatted and code changes for the mypy type checker.
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredeen committed Feb 1, 2024
1 parent 36c5c7f commit b67f157
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 105 deletions.
53 changes: 53 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This file contains project information.
# It also contains settings for linters and code checkers isort, black and mypy.
# Note that these settings are not respected with pre-commit run --all-files
# In that case add configurations to the .pre-commit-config.yaml file.

[project]
name = "serve-load-testing"
version = "1.0.0"
description = "Load testing of the SciLifeLab Serve platform."
requires-python = "=3.8"
keywords = ["load testing", "locust", "python"]

[tool.isort]
profile = 'black'

[tool.black]
line-length = 120
target-version = ['py38']
include = '\.pyi?$'
extend-exclude = '''
/(
\.git
| \.mypy_cache
| \.venv
| venv
| migrations
)/
'''

[tool.mypy]
strict = false
python_version = "3.8"
ignore_missing_imports = true
warn_return_any = true
exclude = ["venv", ".venv", "examples"]

[[tool.mypy.overrides]]
module = "*.migrations.*"
ignore_errors = true

[[tool.mypy.overrides]]
module = [
"flatten_json.*",
"guardian.*",
"tagulous.*",
"dash.*",
"markdown.*",
"pytz.*",
"requests.*",
"setuptools.*",
"yaml.*",
]
ignore_missing_imports = true
12 changes: 3 additions & 9 deletions source/tests-dev/appviewer_requestshtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def apps_runner(n_requests: int = 1):
"""

if n_requests > MAX_APPS_PER_APP_TYPE_LIMIT:
raise Exception(
f"Too many instances of user apps requested to be opened. Max = {MAX_APPS_PER_APP_TYPE_LIMIT}"
)
raise Exception(f"Too many instances of user apps requested to be opened. Max = {MAX_APPS_PER_APP_TYPE_LIMIT}")

start_time = time()
n_fails = 0
Expand All @@ -64,9 +62,7 @@ def apps_runner(n_requests: int = 1):
print(f"Iteration: {i}")
try:
response = open_user_app_sync(url)
print(
f"DEBUG: open_user_app_sync response = {response.status_code}, {response.reason}"
)
print(f"DEBUG: open_user_app_sync response = {response.status_code}, {response.reason}")
# print(response.content)
except Exception as ex:
n_fails += 1
Expand All @@ -77,9 +73,7 @@ def apps_runner(n_requests: int = 1):
sleep(DELAY_BETWEEN_USER_APP_TYPES_SECONDS)

duration_s = time() - start_time
print(
f"Duration (sec) for opening {n_requests} user apps = {duration_s}. Nr failures = {n_fails}"
)
print(f"Duration (sec) for opening {n_requests} user apps = {duration_s}. Nr failures = {n_fails}")


def open_user_app_sync(url: str):
Expand Down
22 changes: 6 additions & 16 deletions source/tests-dev/authenticated.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def get_token(self):
def login(self):
print(f"DEBUG: Login as user {username}")

login_data = dict(
username=username, password=password, csrfmiddlewaretoken=self.csrftoken
)
login_data = dict(username=username, password=password, csrfmiddlewaretoken=self.csrftoken)

with self.client.post(
url="/accounts/login/",
Expand All @@ -46,21 +44,17 @@ def login(self):
name="---ON START---LOGIN",
catch_response=True,
) as response:
print(
f"DEBUG: login response.status_code = {response.status_code}, {response.reason}"
)
print(f"DEBUG: login response.status_code = {response.status_code}, {response.reason}")
# if login succeeds then url = /accounts/login/, else /projects/
print(f"DEBUG: login response.url = {response.url}")
if "/projects" in response.url:
self.is_authenticated = True
else:
response.failure(
f"Login as user {username} failed. Response URL does not contain /projects"
)
response.failure(f"Login as user {username} failed. Response URL does not contain /projects")

def logout(self):
print(f"DEBUG: Log out user {username}")
logout_data = dict(username=username, csrfmiddlewaretoken=self.csrftoken)
# logout_data = dict(username=username, csrfmiddlewaretoken=self.csrftoken)
self.client.get("/accounts/logout/", name="---ON STOP---LOGOUT")

@task
Expand All @@ -75,9 +69,7 @@ def browse_protected_page(self):

request_data = dict(username=username, csrfmiddlewaretoken=self.csrftoken)

response = self.client.get(
page_rel_url, data=request_data, headers={"Referer": "foo"}, verify=False
)
response = self.client.get(page_rel_url, data=request_data, headers={"Referer": "foo"}, verify=False)

with self.client.get(
page_rel_url,
Expand All @@ -86,9 +78,7 @@ def browse_protected_page(self):
verify=False,
catch_response=True,
) as response:
print(
f"DEBUG: protected page response.status_code = {response.status_code}, {response.reason}"
)
print(f"DEBUG: protected page response.status_code = {response.status_code}, {response.reason}")
# if login succeeds then url = ?, else ?
print(f"DEBUG: protected page {response.url=}")
if page_rel_url not in response.url:
Expand Down
14 changes: 6 additions & 8 deletions source/tests-dev/register_user_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ class VisitingBaseUser(HttpUser):

# abstract = True

user_type = None
user_type = ""
user_individual_id = 0
local_individual_id = 0
user_has_registered = False

def get_user_id():
@classmethod
def get_user_id(cls):
"""Increments the class property user_individual_id.
Used to assign a unique id to each individual of this user type.
"""
Expand All @@ -30,9 +31,8 @@ def on_start(self):
"""Called when a User starts running."""
self.client.verify = False # Don't check if certificate is valid
self.local_individual_id = VisitingBaseUser.get_user_id()
print(
f"ONSTART new user type {self.user_type}, individual {self.local_individual_id}"
)
print(f"ONSTART new user type {self.user_type}, individual {self.local_individual_id}")
self.email = "UNSET"

# Tasks

Expand Down Expand Up @@ -72,9 +72,7 @@ def register_user(self):
name="---REGISTER-NEW-USER-ACCOUNT",
catch_response=True,
) as response:
print(
f"DEBUG: signup response.status_code = {response.status_code}, {response.reason}"
)
print(f"DEBUG: signup response.status_code = {response.status_code}, {response.reason}")
# if login succeeds then url = /accounts/login/
print(f"DEBUG: signup response.url = {response.url}")
if "/accounts/login" in response.url:
Expand Down
Loading

0 comments on commit b67f157

Please sign in to comment.