Skip to content

Commit

Permalink
Fix Tests & Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensWe committed Aug 27, 2024
1 parent bd681c0 commit ce7622a
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 54 deletions.
6 changes: 5 additions & 1 deletion amt/site/static/images/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion amt/site/templates/footer.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

</ul>
</div>


<div class="rvo-footer-column">
<h3 class="utrecht-heading-3 rvo-footer-menu-title">{% trans %}Language{% endtrans %}</h3>
<ul class="rvo-footer-menu">
Expand All @@ -41,7 +43,7 @@
<a {% if available_translation == language %}class="selected"{% endif %}
id="langselect-{{ available_translation }}"
class="rvo-link rvo-link--with-icon rvo-link--no-underline"
href="avascript:setCookie('lang', '{{ available_translation }}', 9999); window.location.reload()"
href="javascript:setCookie('lang', '{{ available_translation }}', 9999); window.location.reload()"
>
<span
class="utrecht-icon rvo-icon rvo-icon-wereldbol rvo-icon--sm rvo-icon--wit rvo-link__icon--before"
Expand Down
14 changes: 1 addition & 13 deletions amt/site/templates/header.html.j2

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions amt/site/templates/projects/_list.html.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% for project in projects %}
{% if loop.last and projects|length == limit %}
<li class="rvo-item-list" data-marker="last-element" hx-get="/projects/?skip={{ next }}&search={{ search }}"
hx-swap="afterend" hx-trigger="revealed"><a href="/project/{{ project.id }}">{{ project.name }}</a></li>
<li class="rvo-item-list" data-marker="last-element" hx-get="/projects/?skip={{ next }}&search={{ search }}" hx-swap="afterend" hx-trigger="revealed"><a href="/project/{{ project.id }}">{{ project.name }}</a></li>
{% else %}
<li><a href="/project/{{ project.id }}">{{ project.name }}</a></li>
{% endif %}
Expand Down
1 change: 0 additions & 1 deletion amt/site/templates/projects/index.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<main class="rvo-max-width-layout rvo-max-width-layout--sm">
<div class="rvo-content">


<h1 class="utrecht-heading-1">{% trans %}Projects{% endtrans %}</h1>

<form>
Expand Down
9 changes: 1 addition & 8 deletions amt/site/templates/projects/new.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,7 @@
class="rvo-checkbox rvo-checkbox--not-checked"
for="{{ instrument.urn }}"
>
<input
id="{{ instrument.urn }}"
name="instruments"
class="rvo-checkbox__input"
type="checkbox"
value="{{ instrument.urn }}"
/>
{{ instrument.name }}
<input id="{{ instrument.urn }}" name="instruments" class="rvo-checkbox__input" type="checkbox" value="{{ instrument.urn }}" />{{ instrument.name }}
</label>
{% endfor %}
</div>
Expand Down
43 changes: 22 additions & 21 deletions tests/api/routes/test_projects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Generator
from unittest.mock import MagicMock, Mock
from unittest.mock import MagicMock , Mock

import pytest
from amt.schema.project import ProjectNew
Expand All @@ -13,10 +13,10 @@


@pytest.fixture

Check failure on line 15 in tests/api/routes/test_projects.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (I001)

tests/api/routes/test_projects.py:1:1: I001 Import block is un-sorted or un-formatted
def init_instruments() -> Generator[None, None, None]: # noqa: PT004
def init_instruments() -> Generator[None , None , None]: # noqa: PT004
origin = InstrumentsService.fetch_instruments
InstrumentsService.fetch_instruments = Mock(
return_value=[default_instrument(urn="urn1", name="name1"), default_instrument(urn="urn2", name="name2")]
return_value=[default_instrument(urn="urn1" , name="name1") , default_instrument(urn="urn2" , name="name2")]
)
yield
InstrumentsService.fetch_instruments = origin
Expand All @@ -26,44 +26,45 @@ def test_projects_get_root(client: TestClient) -> None:
response = client.get("/projects/")

assert response.status_code == 200
assert b'<ul class="project-list" id="project-search-results">' in response.content
assert b'<ul class="rvo-item-list" id="project-search-results">' in response.content


def test_projects_get_root_missing_slash(client: TestClient) -> None:
response = client.get("/projects")

assert response.status_code == 200
assert b'<ul class="project-list" id="project-search-results">' in response.content
assert b'<ul class="rvo-item-list" id="project-search-results">' in response.content


def test_projects_get_root_htmx(client: TestClient) -> None:
response = client.get("/projects/", headers={"HX-Request": "true"})
response = client.get("/projects/" , headers={"HX-Request": "true"})

assert response.status_code == 200
assert b'<ul class="project-list" id="project-search-results">' not in response.content
assert b'<ul class="rvo-item-list" id="project-search-results">' not in response.content


def test_get_new_projects(client: TestClient, init_instruments: Generator[None, None, None]) -> None:
def test_get_new_projects(client: TestClient , init_instruments: Generator[None , None , None]) -> None:
# when
response = client.get("/projects/new")

# then
import json
import json

Check failure on line 51 in tests/api/routes/test_projects.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F811)

tests/api/routes/test_projects.py:51:12: F811 Redefinition of unused `json` from line 50

Check failure on line 51 in tests/api/routes/test_projects.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F401)

tests/api/routes/test_projects.py:51:12: F401 `json` imported but unused
with open('data.json' , 'bw+') as f:

Check failure on line 52 in tests/api/routes/test_projects.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (I001)

tests/api/routes/test_projects.py:50:1: I001 Import block is un-sorted or un-formatted
f.write(response.content)
assert response.status_code == 200
assert response.headers["content-type"] == "text/html; charset=utf-8"

assert (
b'<input type="checkbox" id="urn1" name="instruments" value="urn1" /><label for="urn1">name1</label>'
in response.content
b'<input id="urn1" name="instruments" class="rvo-checkbox__input" type="checkbox" value="urn1" />name1' in response.content

Check failure on line 58 in tests/api/routes/test_projects.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (E501)

tests/api/routes/test_projects.py:58:121: E501 Line too long (131 > 120)
)
assert (
b'<input type="checkbox" id="urn2" name="instruments" value="urn2" /><label for="urn2">name2</label>'
in response.content
b'<input id="urn2" name="instruments" class="rvo-checkbox__input" type="checkbox" value="urn2" />name2' in response.content

Check failure on line 61 in tests/api/routes/test_projects.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (E501)

tests/api/routes/test_projects.py:61:121: E501 Line too long (131 > 120)
)


def test_post_new_projects_bad_request(client: TestClient, mock_csrf: Generator[None, None, None]) -> None:
def test_post_new_projects_bad_request(client: TestClient , mock_csrf: Generator[None , None , None]) -> None:
# when
client.cookies["fastapi-csrf-token"] = "1"
response = client.post("/projects/new", json={}, headers={"X-CSRF-Token": "1"})
response = client.post("/projects/new" , json={} , headers={"X-CSRF-Token": "1"})

# then
assert response.status_code == 400
Expand All @@ -72,13 +73,13 @@ def test_post_new_projects_bad_request(client: TestClient, mock_csrf: Generator[


def test_post_new_projects(
client: TestClient, mock_csrf: Generator[None, None, None], init_instruments: Generator[None, None, None]
client: TestClient , mock_csrf: Generator[None , None , None] , init_instruments: Generator[None , None , None]
) -> None:
client.cookies["fastapi-csrf-token"] = "1"
new_project = ProjectNew(name="default project")

# when
response = client.post("/projects/new", json=new_project.model_dump(), headers={"X-CSRF-Token": "1"})
response = client.post("/projects/new" , json=new_project.model_dump() , headers={"X-CSRF-Token": "1"})

# then
assert response.status_code == 200
Expand All @@ -87,17 +88,17 @@ def test_post_new_projects(


def test_post_new_projects_write_system_card(
client: TestClient, mock_csrf: Generator[None, None, None], init_instruments: Generator[None, None, None]
client: TestClient , mock_csrf: Generator[None , None , None] , init_instruments: Generator[None , None , None]
) -> None:
# Given
client.cookies["fastapi-csrf-token"] = "1"
origin = FileSystemStorageService.write
FileSystemStorageService.write = MagicMock()
project_new = ProjectNew(name="name1")
system_card = SystemCard(name=project_new.name, selected_instruments=[])
system_card = SystemCard(name=project_new.name , selected_instruments=[])

# when
client.post("/projects/new", json=project_new.model_dump(), headers={"X-CSRF-Token": "1"})
client.post("/projects/new" , json=project_new.model_dump() , headers={"X-CSRF-Token": "1"})

# then
FileSystemStorageService.write.assert_called_with(system_card.model_dump())
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/test_move_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_e2e_move_task_order_in_same_column(page: Page) -> None:
tasks_in_column = page.locator("#column-1").locator(".progress-card-container").all()

expect(tasks_in_column[0]).to_have_id("card-container-2")
expect(tasks_in_column[1]).to_have_id("card-container-3")
expect(tasks_in_column[2]).to_have_id("card-container-1")
expect(tasks_in_column[1]).to_have_id("card-container-1")
expect(tasks_in_column[2]).to_have_id("card-container-3")

card1.drag_to(target=card2)
4 changes: 2 additions & 2 deletions tests/e2e/test_scroll_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def test_e2e_scroll_projects(page: Page) -> None:
page.goto("/projects/")

project_links = page.locator(".project-list > li").count()
project_links = page.locator("#project-search-results > li").count()

assert project_links == 100

Expand All @@ -18,5 +18,5 @@ def test_e2e_scroll_projects(page: Page) -> None:
response = response_info.value
assert response.status == 200

project_links = page.locator(".project-list > li").count()
project_links = page.locator("#project-search-results > li").count()
assert project_links > 100
6 changes: 3 additions & 3 deletions tests/e2e/test_search_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def test_e2e_search_projects(page: Page) -> None:
page.goto("/projects/")

project_links = page.locator(".project-list > li").count()
project_links = page.locator("#project-search-results > li").count()

assert 90 <= project_links <= 101

Expand All @@ -24,13 +24,13 @@ def test_e2e_search_projects(page: Page) -> None:
def test_e2e_search_scroll_projects(page: Page) -> None:
page.goto("/projects/")

project_links = page.locator(".project-list > li").count()
project_links = page.locator("#project-search-results > li").count()

assert 90 <= project_links <= 101

page.locator("#project-search-input").fill("Project")

with page.expect_request("/projects/?skip=0&search=Project", timeout=3000) as _:
project_links = page.locator(".project-list > li").count()
project_links = page.locator("#project-search-results > li").count()
expect(page.get_by_text("Project 100", exact=True)).to_be_visible()
assert 90 <= project_links <= 101

0 comments on commit ce7622a

Please sign in to comment.