Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #15

Closed
wants to merge 34 commits into from
Closed
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a77a2fd
Added an app viewer user
alfredeen Jan 12, 2024
313c1a8
Work on login to Serve as test user.
alfredeen Jan 16, 2024
cafb743
Completed authentication methods. Work on user type power user..
alfredeen Jan 16, 2024
18d1b91
Better handling of switching between test environments.
alfredeen Jan 19, 2024
1258332
Began test plan classroom. Implemented power user create and delete u…
alfredeen Jan 22, 2024
bc8afc2
Finished test plan classroom.
alfredeen Jan 22, 2024
b587c8b
Added config files for pre-commit and flake8.
alfredeen Feb 1, 2024
f7d59b6
Moved code check config files up to root level.
alfredeen Feb 1, 2024
19bf226
Reformatted with code linters and checkers
alfredeen Feb 1, 2024
69a766f
Reformatted and code changes for the mypy type checker.
alfredeen Feb 1, 2024
a0ce0e8
Introduced the standard logging library. Converted most prints to log…
alfredeen Feb 1, 2024
c3a7965
Updated test logic so sync with changes to Serve.
alfredeen Apr 17, 2024
70be1ee
Added k8s manifests
alfredeen Apr 19, 2024
cc4fec1
Added more k8s manifests
alfredeen Apr 22, 2024
24eaf78
Creating resources in namespace locust. Added a cert manager for TLS.
alfredeen Apr 24, 2024
54d019e
Removed the ingress class name from the ingress.
alfredeen Apr 24, 2024
61d93d3
Added basic auth to Locust web UI
alfredeen Apr 29, 2024
7503323
Added secret locust-secrets with settings from .env
alfredeen Apr 29, 2024
6ec2f64
Base64 of values
alfredeen Apr 29, 2024
de48bfe
Updated the image version used
alfredeen Apr 29, 2024
31c8aea
Added a container to the k8s deployment with locust-timescale. Added …
alfredeen Apr 30, 2024
bd21920
Fixed a secret setting value
alfredeen May 2, 2024
17ee5ca
Using kustomize to customize k8s manifests for local development and …
alfredeen May 2, 2024
da92671
Created a version of the k8s manifest deployment without using kustom…
alfredeen May 2, 2024
37234b2
Set security context in deployment manifests.
alfredeen May 6, 2024
ca74e89
Added more security context
alfredeen May 6, 2024
9914983
Small fix
alfredeen May 6, 2024
250e848
Updated the ingress cert issuer for the new cluster
alfredeen May 15, 2024
091f03b
Updated the ingress cert issuer for the new cluster
alfredeen May 15, 2024
1306819
Removed some of the security context for the locust timescale postgre…
alfredeen May 15, 2024
637cf89
Removed some of the security context for the locust timescale postgre…
alfredeen May 15, 2024
65c85f0
Removed some of the security context for the locust timescale postgre…
alfredeen May 15, 2024
e4eee79
Fixed some load tests that were missing trailing slashes or using the…
alfredeen Oct 3, 2024
ea1267e
Upgraded linting and other tools in the pre-commit action. Also fixed…
alfredeen Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 103 additions & 2 deletions source/tests/base_user_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ def power_user_task(self):
logger.info("Opening project at URL %s", self.project_url)
self.client.get(self.project_url)

# TODO: create JupyterLab app
# TODO: create JupyterLab app

# TODO: open the app

# TODO: delete the app
# TODO: delete the app

# Delete the project
self.delete_project()
Expand Down Expand Up @@ -279,6 +279,64 @@ def delete_project(self):
# logger.debug(response.content)
response.failure("Delete project failed. Response URL does not contain /projects.")

def create_project(self, project_name):
# Update the csrf token
self.get_token("/projects/create?template=Default project")

project_data = dict(
name=project_name,
template_id=1,
description="Project desc",
csrfmiddlewaretoken=self.csrftoken,
)

with self.client.post(
url="/projects/create/?template=Default%20project",
data=project_data,
headers={"Referer": "foo"},
name="---CREATE-NEW-PROJECT",
catch_response=True,
) as response:
logger.debug("create project response.status_code = %s, %s", response.status_code, response.reason)
# If succeeds then url = /projects/<project-name>/
logger.debug("create project response.url = %s", response.url)
if project_name in response.url:
logger.info("Successfully created project %s", project_name)
self.project_url = response.url
else:
logger.warning(f"Create project failed. Response URL {response.url} does not contain project name {project_name}")
#logger.debug(response.content)
response.failure("Create project failed. Response URL does not contain project name.")

def delete_project(self):
# Update the csrf token
self.get_token("/projects")

delete_project_url = f"{self.project_url}delete/" # The project_url already contains a trailing slash
logger.info("Deleting the project at URL: %s", delete_project_url)

delete_project_data = dict(csrfmiddlewaretoken=self.csrftoken)

with self.client.get(
url=delete_project_url,
data=delete_project_data,
headers={"Referer": "foo"},
name="---DELETE-PROJECT",
catch_response=True,
) as response:
logger.debug("delete project response.status_code = %s, %s", response.status_code, response.reason)
# If succeeds then status_code == 200 and url = /projects/
logger.debug("delete project response.url = %s", response.url)
if response.status_code == 200 and "/projects" in response.url:
logger.info("Successfully deleted project at %s", self.project_url)
else:
logger.warning(
f"Delete project failed for project {self.project_url}. \
Response status not 200 or URL does not contain /projects."
)
# logger.debug(response.content)
response.failure("Delete project failed. Response URL does not contain /projects.")

def login(self):
logger.info("Login as user %s", self.username)

Expand Down Expand Up @@ -365,6 +423,49 @@ def open_user_app(self):
self.client.get(APP_SHINYPROXY, name="user-app-shiny-proxy")


class AppViewerUser(HttpUser):
""" Base class for API client system that makes API calls. """
abstract = True

user_type = None

def on_start(self):
"""Called when a User starts running."""
self.client.verify = False # Don't to check if certificate is valid

# Tasks

@task
def open_user_app(self):
"""Note that this approach does not actually create any resources on the k8s cluster."""
print(f"executing task open_user_app, running on host: {self.host}")
APP_SHINYPROXY = "UNSET"

if self.host == "https://serve-dev.scilifelab.se":
# Dev
# ex: https://loadtest-shinyproxy.staging.serve-dev.scilifelab.se/app/loadtest-shinyproxy
# from host: https://staging.serve-dev.scilifelab.se
APP_SHINYPROXY = self.host.replace("https://", "https://loadtest-shinyproxy.")
APP_SHINYPROXY += "/app/loadtest-shinyproxy"

elif "staging" in self.host:
# Staging
# ex: https://loadtest-shinyproxy.serve-staging.serve-dev.scilifelab.se/app/loadtest-shinyproxy
# from host: https://serve-staging.serve-dev.scilifelab.se
APP_SHINYPROXY = self.host.replace("https://", "https://loadtest-shinyproxy.")
APP_SHINYPROXY += "/app/loadtest-shinyproxy"

elif "serve.scilifelab.se" in self.host:
# Production
# ex: https://adhd-medication-sweden.serve.scilifelab.se/app/adhd-medication-sweden
APP_SHINYPROXY = self.host.replace("https://", "https://adhd-medication-sweden.")
APP_SHINYPROXY += "/app/adhd-medication-sweden"

logger.debug("making GET request to user app URL: %s", APP_SHINYPROXY)

self.client.get(APP_SHINYPROXY, name="user-app-shiny-proxy")


class OpenAPIClientBaseUser(HttpUser):
"""Base class for API client system that makes API calls."""

Expand Down
Loading