Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 12 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

- name: Fetch base and install Poetry
run: |
git fetch origin ${{github.base_ref}}
pipx install poetry==2.1.1

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'poetry'

- name: Fetch base and install Poetry
run: |
git fetch origin ${{github.base_ref}}
pipx install poetry==2.1.1

- name: Copy base.html for use in unit tests
run: |
cp --force designsafe/templates/base.j2 designsafe/templates/base.html

- run: |
env use python3.11
poetry sync

- name: Run Server-side unit tests and generate coverage report
Expand All @@ -42,19 +42,19 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Fetch base and install Poetry
run: |
git fetch origin ${{github.base_ref}}
pipx install poetry==2.1.1

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'poetry'

- name: Fetch base and install Poetry
run: |
git fetch origin ${{github.base_ref}}
pipx install poetry==2.1.1

- name: Install Python Packages
run: |
env use python3.11
poetry sync

- name: Run Server-side linting with pytest
Expand Down
82 changes: 82 additions & 0 deletions designsafe/apps/workspace/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from mock import patch
from django.test import TestCase
from .models.app_descriptions import AppDescription
from .models.user_favorites import UserFavorite
from unittest import skip
from django.urls import reverse
from django.contrib.auth import get_user_model
Expand Down Expand Up @@ -114,3 +115,84 @@ def test_job_submit_parse_urls(self):
def test_licensed_apps(self):
# TODO: test to make sure the licensing stuff works
pass

class TestUserFavoritesApiViews(TestCase):
fixtures = ["user-data", "auth"]

def setUp(self):
user = get_user_model().objects.get(pk=2)
user.set_password("user/password")
user.save()
self.client.login(username="ds_user", password="user/password")

def test_add_favorite(self):
url = reverse("workspace_api:user_favorite_list")
response = self.client.post(
url,
json.dumps({"tool_id": "test-app-1"}),
content_type="application/json",
)
data = response.json()

self.assertEqual(response.status_code, 200)
self.assertTrue(data["success"])
self.assertTrue(data["created"])
self.assertTrue(
UserFavorite.objects.filter(user__pk=2, tool_id="test-app-1").exists()
)

def test_add_favorite_missing_tool_id(self):
url = reverse("workspace_api:user_favorite_list")
response = self.client.post(
url, json.dumps({}), content_type="application/json"
)
self.assertEqual(response.status_code, 400)

def test_list_favorites(self):
url = reverse("workspace_api:user_favorite_list")
self.client.post(
url,
json.dumps({"tool_id": "test-app-1"}),
content_type="application/json",
)

response = self.client.get(url)
data = response.json()

self.assertEqual(response.status_code, 200)
self.assertEqual(len(data), 1)
self.assertEqual(data[0]["tool_id"], "test-app-1")

def test_remove_favorite(self):
add_url = reverse("workspace_api:user_favorite_list")
self.client.post(
add_url,
json.dumps({"tool_id": "test-app-1"}),
content_type="application/json",
)
self.assertTrue(
UserFavorite.objects.filter(user__pk=2, tool_id="test-app-1").exists()
)

remove_url = reverse("workspace_api:remove_favorite_tool")
response = self.client.post(
remove_url,
json.dumps({"tool_id": "test-app-1"}),
content_type="application/json",
)
data = response.json()

self.assertEqual(response.status_code, 200)
self.assertTrue(data["success"])
self.assertFalse(
UserFavorite.objects.filter(user__pk=2, tool_id="test-app-1").exists()
)

def test_remove_favorite_missing_tool_id(self):
url = reverse("workspace_api:remove_favorite_tool")
response = self.client.post(
url, json.dumps({}), content_type="application/json"
)
self.assertEqual(response.status_code, 400)


Loading