From 0bbf2cf1e3693e018b16b88b1bea3e9d61e983df Mon Sep 17 00:00:00 2001 From: lc_hd Date: Mon, 16 Sep 2024 16:14:08 -0400 Subject: [PATCH 01/38] feat: updated requirements --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements.txt b/requirements.txt index 1b71d857..77c03bee 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ APScheduler==3.10.4 arabic-reshaper==3.0.0 asgiref==3.7.2 astroid==3.0.1 +blinker==1.7.0 boto3==1.26.77 botocore==1.29.77 cachetools==4.2.4 @@ -80,6 +81,7 @@ requests>=2.32.0 requests-oauthlib==1.3.1 rsa==4.7.2 s3transfer==0.6.0 +selenium-wire==5.1.0 six==1.15.0 sqlparse==0.5.0 toml==0.10.1 From c4fcdbc34b57cc9189fc29f927818320477290f2 Mon Sep 17 00:00:00 2001 From: lc_hd Date: Tue, 17 Sep 2024 10:23:49 -0400 Subject: [PATCH 02/38] feat: removed selenium-wire since it is outdated --- requirements.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 77c03bee..1b71d857 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,6 @@ APScheduler==3.10.4 arabic-reshaper==3.0.0 asgiref==3.7.2 astroid==3.0.1 -blinker==1.7.0 boto3==1.26.77 botocore==1.29.77 cachetools==4.2.4 @@ -81,7 +80,6 @@ requests>=2.32.0 requests-oauthlib==1.3.1 rsa==4.7.2 s3transfer==0.6.0 -selenium-wire==5.1.0 six==1.15.0 sqlparse==0.5.0 toml==0.10.1 From 65169bba138e602914c155222af0a64e751ff6cd Mon Sep 17 00:00:00 2001 From: lc_hd Date: Wed, 18 Sep 2024 11:28:16 -0400 Subject: [PATCH 03/38] feat: created placeholder code to house external api --- tests/external_api/urls.py | 10 ++++++++++ tests/external_api/views.py | 8 ++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/external_api/urls.py create mode 100644 tests/external_api/views.py diff --git a/tests/external_api/urls.py b/tests/external_api/urls.py new file mode 100644 index 00000000..e6901cf6 --- /dev/null +++ b/tests/external_api/urls.py @@ -0,0 +1,10 @@ +from localcontexts.urls import urlpatterns +from django.urls import path + +from . views import placeholder_view + + +class UrlsWithMockedExternalApi: + urlpatterns = urlpatterns + [ + path('placeholder-url/', placeholder_view) + ] diff --git a/tests/external_api/views.py b/tests/external_api/views.py new file mode 100644 index 00000000..b073be35 --- /dev/null +++ b/tests/external_api/views.py @@ -0,0 +1,8 @@ +from django.http import JsonResponse + + +def placeholder_view(request): + data = { + 'place-holder-key': 'place-holder-value' + } + return JsonResponse(data) From f4327a30aa4a60608dcad8f92c1ec24bbce76392 Mon Sep 17 00:00:00 2001 From: lc_hd Date: Wed, 18 Sep 2024 11:30:24 -0400 Subject: [PATCH 04/38] feat: created a test to verify external apis can be mocked --- tests/functional/test_create_community_gis_ui.py | 4 ++++ tests/functional/ui_feature_testcase_base.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/functional/test_create_community_gis_ui.py b/tests/functional/test_create_community_gis_ui.py index d4eadb04..e11b4746 100644 --- a/tests/functional/test_create_community_gis_ui.py +++ b/tests/functional/test_create_community_gis_ui.py @@ -247,3 +247,7 @@ def test_clicking_skip_this_step_on_upload_shapefile_page_navigates_to_confirm_p # verify user is on the upload shapefile page assert self.py.url().endswith(self.confirm_community_path) + + def test_placeholder(self): + url = urllib.parse.urljoin(self.live_server_url, 'placeholder-url') + self.py.visit(url) diff --git a/tests/functional/ui_feature_testcase_base.py b/tests/functional/ui_feature_testcase_base.py index 80e9ac46..e40fc7bb 100644 --- a/tests/functional/ui_feature_testcase_base.py +++ b/tests/functional/ui_feature_testcase_base.py @@ -2,13 +2,16 @@ import pytest -from django.contrib.auth.hashers import make_password from django.urls import reverse +from django.contrib.auth.hashers import make_password +from django.test.utils import override_settings from django.contrib.staticfiles.testing import StaticLiveServerTestCase from factories.accounts_factories import UserFactory +from external_api.urls import UrlsWithMockedExternalApi +@override_settings(ROOT_URLCONF=UrlsWithMockedExternalApi) @pytest.mark.usefixtures("py") class UiFeatureHelper(StaticLiveServerTestCase): def login(self,): From 377e538d6760ff0b8494ba257e93ccf5541538cd Mon Sep 17 00:00:00 2001 From: lc_hd Date: Wed, 18 Sep 2024 14:55:08 -0400 Subject: [PATCH 05/38] feat: added templatetag for transforming external_urls to internal_urls when mocking --- api/templatetags/__init__.py | 0 api/templatetags/custom_api_tags.py | 33 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 api/templatetags/__init__.py create mode 100644 api/templatetags/custom_api_tags.py diff --git a/api/templatetags/__init__.py b/api/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/api/templatetags/custom_api_tags.py b/api/templatetags/custom_api_tags.py new file mode 100644 index 00000000..c6027986 --- /dev/null +++ b/api/templatetags/custom_api_tags.py @@ -0,0 +1,33 @@ +import os +from urllib.parse import urlparse +from urllib.parse import urljoin + +from django import template + + +register = template.Library() + + +@register.simple_tag +def external_api(external_url: str) -> str: + """ + Tag converts an external_url into an internal_url + so the response can be mocked with a fixture. + + Args: + external_url: Url to an external API resource. + + Returns: + When TEST_LIVE_SERVER_DOMAIN is available, the url is transformed so + the external domain is swapped with the TEST_LIVE_SERVER_DOMAIN. + """ + test_live_server_domain = os.environ.get('TEST_LIVE_SERVER_DOMAIN') + if not test_live_server_domain: + return external_url + url_components = urlparse(external_url) + + try: + # return the internal_url formed by the domain and url_components.path + return urljoin(test_live_server_domain, url_components.path) + except Exception: + return external_url From 00af964d9fdf272a3462cc266c7d3fef3431a2ae Mon Sep 17 00:00:00 2001 From: lc_hd Date: Wed, 18 Sep 2024 14:56:18 -0400 Subject: [PATCH 06/38] feat: use external_api template_tag for Native Land API --- templates/communities/add-community-boundary.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/communities/add-community-boundary.html b/templates/communities/add-community-boundary.html index 0878d27c..5bf42918 100644 --- a/templates/communities/add-community-boundary.html +++ b/templates/communities/add-community-boundary.html @@ -1,4 +1,4 @@ -{% extends 'register-base.html' %} {% block title %} Add Community {% endblock %} {% load static %} {% block card %} +{% extends 'register-base.html' %} {% block title %} Add Community {% endblock %} {% load static %} {% block card %} {% load custom_api_tags %}
+
No boundary Present
- + {% if preview_boundary %} + if (localStorage.hasOwnProperty('boundary_preview')) { + boundary = JSON.parse( + localStorage.getItem('boundary_preview') + ) + boundaryExists() + } + {% elif boundary|length > 0 %} {% endif %} From e83e31a8d6d32cc1857630495c5e8f4557fef96f Mon Sep 17 00:00:00 2001 From: lc_hd Date: Fri, 20 Sep 2024 21:51:10 -0400 Subject: [PATCH 23/38] feat: the boundary-preview is set in localStorage --- .../update-boundary-via-native-land-and-shapefile.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/templates/communities/update-boundary-via-native-land-and-shapefile.html b/templates/communities/update-boundary-via-native-land-and-shapefile.html index f5852e39..2645eee8 100644 --- a/templates/communities/update-boundary-via-native-land-and-shapefile.html +++ b/templates/communities/update-boundary-via-native-land-and-shapefile.html @@ -338,8 +338,11 @@ } function setViewLocationsHref(selectionUnit, boundary) { - // set href for view-boundary-location - const href = `{% url 'boundary-preview' %}?boundary=${JSON.stringify(boundary)}` + // set boundary-preview value in localStorage + localStorage.setItem('boundary_preview', JSON.stringify(boundary)) + + // set href for view-boundary-location + const href = "{% url 'boundary-preview' %}" selectionUnit.querySelector('.view-boundary-link').setAttribute('href', href) } From c42275b0e5d6385283a0d76be50a5c3b47467c65 Mon Sep 17 00:00:00 2001 From: lc_hd Date: Fri, 20 Sep 2024 21:55:47 -0400 Subject: [PATCH 24/38] feat: the boundary-preview is set in localStorage --- .../update-boundary-via-native-land-and-shapefile.html | 5 ++++- .../update-boundary-via-native-land-and-shapefile.html | 2 +- templates/widget_forms/boundary_widget.html | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/templates/boundary/update-boundary-via-native-land-and-shapefile.html b/templates/boundary/update-boundary-via-native-land-and-shapefile.html index e4b3c1c4..d1c9a61b 100644 --- a/templates/boundary/update-boundary-via-native-land-and-shapefile.html +++ b/templates/boundary/update-boundary-via-native-land-and-shapefile.html @@ -389,8 +389,11 @@ } function setViewLocationsHref(selectionUnit, boundary) { + // set boundary-preview value in localStorage + localStorage.setItem('boundary_preview', JSON.stringify(boundary)) + // set href for view-boundary-location - const href = `{% url 'boundary-preview' %}?boundary=${JSON.stringify(boundary)}` + const href = "{% url 'boundary-preview' %}" selectionUnit.querySelector('.view-boundary-link').setAttribute('href', href) } diff --git a/templates/communities/update-boundary-via-native-land-and-shapefile.html b/templates/communities/update-boundary-via-native-land-and-shapefile.html index 2645eee8..432da51b 100644 --- a/templates/communities/update-boundary-via-native-land-and-shapefile.html +++ b/templates/communities/update-boundary-via-native-land-and-shapefile.html @@ -340,7 +340,7 @@ function setViewLocationsHref(selectionUnit, boundary) { // set boundary-preview value in localStorage localStorage.setItem('boundary_preview', JSON.stringify(boundary)) - + // set href for view-boundary-location const href = "{% url 'boundary-preview' %}" selectionUnit.querySelector('.view-boundary-link').setAttribute('href', href) diff --git a/templates/widget_forms/boundary_widget.html b/templates/widget_forms/boundary_widget.html index 13d671e9..37798f1c 100644 --- a/templates/widget_forms/boundary_widget.html +++ b/templates/widget_forms/boundary_widget.html @@ -84,8 +84,11 @@ return } + // set boundary-preview value in localStorage + localStorage.setItem('boundary_preview', JSON.stringify(boundary)) + // open boundary preview - const url = `{% url 'boundary-preview' %}?boundary=[${boundary}]` + const url = "{% url 'boundary-preview' %}" window.open(url, '_blank'); } async function uploadShapeFileData(self) { From f7d74b951ac7b0d0b1dfdcd81151bafc1a80297f Mon Sep 17 00:00:00 2001 From: lc_hd Date: Sat, 21 Sep 2024 00:38:49 -0400 Subject: [PATCH 25/38] feat: removed unused tets code --- tests/functional/test_create_community_gis_ui.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/functional/test_create_community_gis_ui.py b/tests/functional/test_create_community_gis_ui.py index 3e996bda..e80bdd73 100644 --- a/tests/functional/test_create_community_gis_ui.py +++ b/tests/functional/test_create_community_gis_ui.py @@ -248,7 +248,3 @@ def test_clicking_skip_this_step_on_upload_shapefile_page_navigates_to_confirm_p # verify user is on the upload shapefile page assert self.py.url().endswith(self.confirm_community_path) - - def test_placeholder(self): - url = urllib.parse.urljoin(self.live_server_url, 'placeholder-url') - self.py.visit(url) From 7c046df66cbc84eafd1fb8400ae780f2360f44cc Mon Sep 17 00:00:00 2001 From: lc_hd Date: Mon, 23 Sep 2024 10:52:22 -0400 Subject: [PATCH 26/38] feat: when "Clear Boundary" button is cliced, the BoundaryPayload is reset --- .../boundary/update-boundary-via-native-land-and-shapefile.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/boundary/update-boundary-via-native-land-and-shapefile.html b/templates/boundary/update-boundary-via-native-land-and-shapefile.html index f57781c2..b12daced 100644 --- a/templates/boundary/update-boundary-via-native-land-and-shapefile.html +++ b/templates/boundary/update-boundary-via-native-land-and-shapefile.html @@ -553,6 +553,8 @@ clearShapeFileInput(selectionUnit) selectInitialShareBoundaryPublicly() disableContinueButton() + BoundaryPayLoad = {} + setBoundaryPayloadForInputElement() } \ No newline at end of file From f207bfb7e8ba9385ec95ae1b2a18337b36b99974 Mon Sep 17 00:00:00 2001 From: lc_hd Date: Mon, 23 Sep 2024 10:53:33 -0400 Subject: [PATCH 27/38] feat: code does not attempt to save boundary payload when it is an empty dictionary --- helpers/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers/utils.py b/helpers/utils.py index e67577a2..f5080eb7 100644 --- a/helpers/utils.py +++ b/helpers/utils.py @@ -455,7 +455,7 @@ def create_or_update_boundary( raw_boundary_payload = post_data.get('boundary-payload') - if raw_boundary_payload in ['', None]: + if raw_boundary_payload in ['', '{}', None]: return data = json.loads(raw_boundary_payload) From 4603ac8b5788b36fab71626a0c0426375461e56f Mon Sep 17 00:00:00 2001 From: lc_hd Date: Fri, 27 Sep 2024 17:49:13 -0400 Subject: [PATCH 28/38] feat: added data-test-id to reference element --- templates/partials/_project-actions.html | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/partials/_project-actions.html b/templates/partials/_project-actions.html index 5f15ba45..8197d8fc 100644 --- a/templates/partials/_project-actions.html +++ b/templates/partials/_project-actions.html @@ -267,6 +267,7 @@

Are you sure?

{% if 'native-land.ca' in project.source_of_boundary and project.name_of_boundary %} From 593ce0d572b3dfbd7c4abe513ee9fd442db849de Mon Sep 17 00:00:00 2001 From: lc_hd Date: Fri, 27 Sep 2024 17:51:12 -0400 Subject: [PATCH 29/38] feat: created testcase which verifies cleared boundaries are not saved --- tests/functional/test_preview_boundary_ui.py | 103 +++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 tests/functional/test_preview_boundary_ui.py diff --git a/tests/functional/test_preview_boundary_ui.py b/tests/functional/test_preview_boundary_ui.py new file mode 100644 index 00000000..f891ea17 --- /dev/null +++ b/tests/functional/test_preview_boundary_ui.py @@ -0,0 +1,103 @@ +import time +import urllib + +import pytest +from django.urls import reverse + +from functional.ui_feature_testcase_base import UiFeatureHelper +from factories.projects_factories import ProjectFactory +from communities.models import Community, Boundary +from projects.models import Project + + +@pytest.mark.usefixtures("py") +class TestBoundaryPreviewFeatures(UiFeatureHelper): + def setUp(self): + self.login() + self.original_source_of_boundary = 'native-land.ca' + self.original_name_of_boundary = 'placeholder-boundary-name' + self.original_boundary_coordinates = [ + [0, 0], [0, 1], [0, 2] + ] + self.project = None + self.community = None + + def accept_cookies(self): + # this removes the accept-cookies overlay so other + # buttons below overlay can be clicked + self.py.get("[class~='cookie-btn']").click() + + def select_specific_nld_territory(self, nld_terriroty: str): + time.sleep(5) # wait for ajax call for NLD to load + self.py.get(".input-field.search").type(nld_terriroty) + self.py.get(".region-results .result-item").click() + + def create_project_and_community(self): + self.community = Community( + community_creator=self.user, + ) + self.community.save() + boundary = Boundary( + coordinates=self.original_boundary_coordinates + ) + boundary.save() + self.project = ProjectFactory( + project_creator=self.user, + boundary=boundary, + source_of_boundary=self.original_source_of_boundary, + name_of_boundary=self.original_name_of_boundary, + urls=[] + ) + self.project.save() + + def confirm_preexisting_boundary_was_not_overwritten(self): + # confirm in the UI on project actions view page + boundary_title = self.py.get("[data-test-id='native-land-link']") + boundary_title.should().be_visible() + boundary_title.should().have_text( + self.original_name_of_boundary + ) + + boundary_url_source = boundary_title.get_attribute('href') + assert self.original_source_of_boundary in boundary_url_source, 'Unexpected Url' + + # reload project and confirm its boundary coordinates are the same + reloaded_project = Project.objects.get(unique_id=self.project.unique_id) + reloaded_boundary_coordinates = reloaded_project.boundary.get_coordinates() + original_boundary_coordinates = self.project.boundary.get_coordinates() + assert original_boundary_coordinates == reloaded_boundary_coordinates, 'Unexpected Coordinates' + + def test_that_cleared_boundaries_are_not_saved(self): + self.create_project_and_community() + + # visit project edit page for community + project_url = urllib.parse.urljoin( + self.live_server_url, reverse( + 'edit-project', + kwargs={ + 'pk': self.community.id, + 'project_uuid': self.project.unique_id, + } + ) + ) + self.py.visit(project_url) + + # click accept cookies button + time.sleep(5) # wait for accept banner to appear + self.accept_cookies() + + # select NLD territory + selected_territory = 'Panamakas' + self.select_specific_nld_territory(selected_territory) + + # clear boundary + time.sleep(5) # wait for boundary selection to occur + clear_boundary_button = self.py.get("#cancel-btn") + clear_boundary_button.click() + + # save page + time.sleep(5) # wait for boundary selection to occur + save_project_button = self.py.get("#submitProjectBtn") + save_project_button.click() + + self.confirm_preexisting_boundary_was_not_overwritten() From 39fbe569b41aa2e495634d80af347affe56cc2ac Mon Sep 17 00:00:00 2001 From: lc_hd Date: Mon, 30 Sep 2024 12:09:59 -0400 Subject: [PATCH 30/38] feat: added similar testcase but for institutions --- tests/functional/test_preview_boundary_ui.py | 91 ++++++++++++++++++-- 1 file changed, 82 insertions(+), 9 deletions(-) diff --git a/tests/functional/test_preview_boundary_ui.py b/tests/functional/test_preview_boundary_ui.py index f891ea17..3e0538e3 100644 --- a/tests/functional/test_preview_boundary_ui.py +++ b/tests/functional/test_preview_boundary_ui.py @@ -7,6 +7,7 @@ from functional.ui_feature_testcase_base import UiFeatureHelper from factories.projects_factories import ProjectFactory from communities.models import Community, Boundary +from institutions.models import Institution from projects.models import Project @@ -19,8 +20,10 @@ def setUp(self): self.original_boundary_coordinates = [ [0, 0], [0, 1], [0, 2] ] - self.project = None + self.community_project = None + self.institution_project = None self.community = None + self.institution = None def accept_cookies(self): # this removes the accept-cookies overlay so other @@ -41,16 +44,34 @@ def create_project_and_community(self): coordinates=self.original_boundary_coordinates ) boundary.save() - self.project = ProjectFactory( + self.community_project = ProjectFactory( project_creator=self.user, boundary=boundary, source_of_boundary=self.original_source_of_boundary, name_of_boundary=self.original_name_of_boundary, urls=[] ) - self.project.save() + self.community_project.save() - def confirm_preexisting_boundary_was_not_overwritten(self): + def create_project_and_institution(self): + self.institution = Institution( + institution_creator=self.user, + ) + self.institution.save() + boundary = Boundary( + coordinates=self.original_boundary_coordinates + ) + boundary.save() + self.institution_project = ProjectFactory( + project_creator=self.user, + boundary=boundary, + source_of_boundary=self.original_source_of_boundary, + name_of_boundary=self.original_name_of_boundary, + urls=[] + ) + self.institution_project.save() + + def confirm_preexisting_project_boundary_was_not_overwritten_for_community(self): # confirm in the UI on project actions view page boundary_title = self.py.get("[data-test-id='native-land-link']") boundary_title.should().be_visible() @@ -62,12 +83,29 @@ def confirm_preexisting_boundary_was_not_overwritten(self): assert self.original_source_of_boundary in boundary_url_source, 'Unexpected Url' # reload project and confirm its boundary coordinates are the same - reloaded_project = Project.objects.get(unique_id=self.project.unique_id) + reloaded_project = Project.objects.get(unique_id=self.community_project.unique_id) reloaded_boundary_coordinates = reloaded_project.boundary.get_coordinates() - original_boundary_coordinates = self.project.boundary.get_coordinates() + original_boundary_coordinates = self.community_project.boundary.get_coordinates() assert original_boundary_coordinates == reloaded_boundary_coordinates, 'Unexpected Coordinates' - def test_that_cleared_boundaries_are_not_saved(self): + def confirm_preexisting_project_boundary_was_not_overwritten_for_institution(self): + # confirm in the UI on project actions view page + boundary_title = self.py.get("[data-test-id='native-land-link']") + boundary_title.should().be_visible() + boundary_title.should().have_text( + self.original_name_of_boundary + ) + + boundary_url_source = boundary_title.get_attribute('href') + assert self.original_source_of_boundary in boundary_url_source, 'Unexpected Url' + + # reload project and confirm its boundary coordinates are the same + reloaded_project = Project.objects.get(unique_id=self.institution_project.unique_id) + reloaded_boundary_coordinates = reloaded_project.boundary.get_coordinates() + original_boundary_coordinates = self.institution_project.boundary.get_coordinates() + assert original_boundary_coordinates == reloaded_boundary_coordinates, 'Unexpected Coordinates' + + def test_that_cleared_project_boundaries_are_not_saved_for_a_community(self): self.create_project_and_community() # visit project edit page for community @@ -76,7 +114,42 @@ def test_that_cleared_boundaries_are_not_saved(self): 'edit-project', kwargs={ 'pk': self.community.id, - 'project_uuid': self.project.unique_id, + 'project_uuid': self.community_project.unique_id, + } + ) + ) + self.py.visit(project_url) + + # click accept cookies button + time.sleep(5) # wait for accept banner to appear + self.accept_cookies() + + # select NLD territory + selected_territory = 'Panamakas' + self.select_specific_nld_territory(selected_territory) + + # clear boundary + time.sleep(5) # wait for boundary selection to occur + clear_boundary_button = self.py.get("#cancel-btn") + clear_boundary_button.click() + + # save page + time.sleep(5) # wait for boundary selection to occur + save_project_button = self.py.get("#submitProjectBtn") + save_project_button.click() + + self.confirm_preexisting_project_boundary_was_not_overwritten_for_community() + + def test_that_cleared_project_boundaries_are_not_saved_for_an_institution(self): + self.create_project_and_institution() + + # visit project edit page for institution + project_url = urllib.parse.urljoin( + self.live_server_url, reverse( + 'inst-edit-project', + kwargs={ + 'pk': self.institution.id, + 'project_uuid': self.institution_project.unique_id, } ) ) @@ -100,4 +173,4 @@ def test_that_cleared_boundaries_are_not_saved(self): save_project_button = self.py.get("#submitProjectBtn") save_project_button.click() - self.confirm_preexisting_boundary_was_not_overwritten() + self.confirm_preexisting_project_boundary_was_not_overwritten_for_institution() From f86731d55c2982e1f2011d96f44c14b787544fbf Mon Sep 17 00:00:00 2001 From: lc_hd Date: Mon, 30 Sep 2024 13:38:12 -0400 Subject: [PATCH 31/38] feat: updated name of testcase --- ...boundary_ui.py => test_cleared_boundaries_are_not_saved_ui.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/functional/{test_preview_boundary_ui.py => test_cleared_boundaries_are_not_saved_ui.py} (100%) diff --git a/tests/functional/test_preview_boundary_ui.py b/tests/functional/test_cleared_boundaries_are_not_saved_ui.py similarity index 100% rename from tests/functional/test_preview_boundary_ui.py rename to tests/functional/test_cleared_boundaries_are_not_saved_ui.py From 96906aac9930b50e93d839d74407edcca812f164 Mon Sep 17 00:00:00 2001 From: lc_hd Date: Mon, 30 Sep 2024 14:09:19 -0400 Subject: [PATCH 32/38] feat: created testcase file --- tests/functional/test_preview_boundary_ui.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/functional/test_preview_boundary_ui.py diff --git a/tests/functional/test_preview_boundary_ui.py b/tests/functional/test_preview_boundary_ui.py new file mode 100644 index 00000000..e69de29b From a3722d0329035e94d755d1f30af5bbded171c14b Mon Sep 17 00:00:00 2001 From: lc_hd Date: Mon, 30 Sep 2024 14:10:48 -0400 Subject: [PATCH 33/38] feat: updated testcase name --- tests/functional/test_cleared_boundaries_are_not_saved_ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/test_cleared_boundaries_are_not_saved_ui.py b/tests/functional/test_cleared_boundaries_are_not_saved_ui.py index 3e0538e3..91151a83 100644 --- a/tests/functional/test_cleared_boundaries_are_not_saved_ui.py +++ b/tests/functional/test_cleared_boundaries_are_not_saved_ui.py @@ -12,7 +12,7 @@ @pytest.mark.usefixtures("py") -class TestBoundaryPreviewFeatures(UiFeatureHelper): +class TestBoundaryClearedFeatures(UiFeatureHelper): def setUp(self): self.login() self.original_source_of_boundary = 'native-land.ca' From 9aedcc186205605b7e55a7ef03af6e2a1896b484 Mon Sep 17 00:00:00 2001 From: lc_hd Date: Mon, 30 Sep 2024 15:39:37 -0400 Subject: [PATCH 34/38] feat: added testcase for community project previews --- tests/functional/test_preview_boundary_ui.py | 0 .../test_project_preview_boundary_ui.py | 85 +++++++++++++++++++ 2 files changed, 85 insertions(+) delete mode 100644 tests/functional/test_preview_boundary_ui.py create mode 100644 tests/functional/test_project_preview_boundary_ui.py diff --git a/tests/functional/test_preview_boundary_ui.py b/tests/functional/test_preview_boundary_ui.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/functional/test_project_preview_boundary_ui.py b/tests/functional/test_project_preview_boundary_ui.py new file mode 100644 index 00000000..1fc739a3 --- /dev/null +++ b/tests/functional/test_project_preview_boundary_ui.py @@ -0,0 +1,85 @@ +import time +import urllib + +import pytest +from django.urls import reverse + +from functional.ui_feature_testcase_base import UiFeatureHelper +from factories.projects_factories import ProjectFactory +from communities.models import Community, Boundary +from helpers.views import boundary_preview +from institutions.models import Institution +from projects.models import Project + + +@pytest.mark.usefixtures("py") +class TestProjectBoundaryPreviewFeatures(UiFeatureHelper): + def setUp(self): + self.login() + self.community_project = None + self.institution_project = None + self.community = None + self.institution = None + + def accept_cookies(self): + # this removes the accept-cookies overlay so other + # buttons below overlay can be clicked + time.sleep(5) # wait for accept banner to appear + self.py.get("[class~='cookie-btn']").click() + + def select_specific_nld_territory(self): + time.sleep(5) # wait for ajax call for NLD to load + selected_territory = 'Panamakas' + self.py.get(".input-field.search").type(selected_territory) + self.py.get(".region-results .result-item").click() + + def create_project_and_community(self): + self.community = Community( + community_creator=self.user, + ) + self.community.save() + self.community_project = ProjectFactory( + project_creator=self.user, + urls=[] + ) + self.community_project.save() + + def create_project_and_institution(self): + self.institution = Institution( + institution_creator=self.user, + ) + self.institution.save() + self.institution_project = ProjectFactory( + project_creator=self.user, + urls=[] + ) + self.institution_project.save() + + def verify_expected_boundary_data_is_present(self): + # grab the boundary variable from Javascript + boundary = self.py.webdriver.execute_script('return boundary') + assert len(boundary) > 0, 'Boundary preview data should exist' + + def test_project_boundary_preview_for_a_community(self): + self.accept_cookies() + self.create_project_and_community() + + # visit project edit page for community + community_project_url = urllib.parse.urljoin( + self.live_server_url, reverse( + 'edit-project', + kwargs={ + 'pk': self.community.id, + 'project_uuid': self.community_project.unique_id, + } + ) + ) + self.py.visit(community_project_url) + self.select_specific_nld_territory() + + time.sleep(5) # wait for Javascript actions + boundary_preview_url = urllib.parse.urljoin( + self.live_server_url, reverse('boundary-preview') + ) + self.py.visit(boundary_preview_url) + self.verify_expected_boundary_data_is_present() From 5294995b2d0f59c21847447e1a42f50634b2a872 Mon Sep 17 00:00:00 2001 From: lc_hd Date: Mon, 30 Sep 2024 15:45:10 -0400 Subject: [PATCH 35/38] feat: added testcase for institution project previews --- .../test_project_preview_boundary_ui.py | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/functional/test_project_preview_boundary_ui.py b/tests/functional/test_project_preview_boundary_ui.py index 1fc739a3..4d730644 100644 --- a/tests/functional/test_project_preview_boundary_ui.py +++ b/tests/functional/test_project_preview_boundary_ui.py @@ -6,10 +6,8 @@ from functional.ui_feature_testcase_base import UiFeatureHelper from factories.projects_factories import ProjectFactory -from communities.models import Community, Boundary -from helpers.views import boundary_preview +from communities.models import Community from institutions.models import Institution -from projects.models import Project @pytest.mark.usefixtures("py") @@ -83,3 +81,27 @@ def test_project_boundary_preview_for_a_community(self): ) self.py.visit(boundary_preview_url) self.verify_expected_boundary_data_is_present() + + def test_project_boundary_preview_for_an_institution(self): + self.accept_cookies() + self.create_project_and_institution() + + # visit project edit page for community + institution_project_url = urllib.parse.urljoin( + self.live_server_url, reverse( + 'inst-edit-project', + kwargs={ + 'pk': self.institution.id, + 'project_uuid': self.institution_project.unique_id, + } + ) + ) + self.py.visit(institution_project_url) + self.select_specific_nld_territory() + + time.sleep(5) # wait for Javascript actions + boundary_preview_url = urllib.parse.urljoin( + self.live_server_url, reverse('boundary-preview') + ) + self.py.visit(boundary_preview_url) + self.verify_expected_boundary_data_is_present() From a00c507824b3764dcc58da46681c243bea598070 Mon Sep 17 00:00:00 2001 From: lc_hd Date: Mon, 30 Sep 2024 16:43:12 -0400 Subject: [PATCH 36/38] feat: added ttestcase for when no preview boundary is selected --- .../test_project_preview_boundary_ui.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/functional/test_project_preview_boundary_ui.py b/tests/functional/test_project_preview_boundary_ui.py index 4d730644..d60169f7 100644 --- a/tests/functional/test_project_preview_boundary_ui.py +++ b/tests/functional/test_project_preview_boundary_ui.py @@ -58,6 +58,13 @@ def verify_expected_boundary_data_is_present(self): boundary = self.py.webdriver.execute_script('return boundary') assert len(boundary) > 0, 'Boundary preview data should exist' + def verify_expected_boundary_data_is_not_present(self): + # grab the boundary variable from Javascript + boundary = self.py.webdriver.execute_script('return boundary') + default_boundary_count = 1 + assert len(boundary) == default_boundary_count, 'Boundary preview data should not exist' + self.py.get("#no-boundary-container").should().be_visible() + def test_project_boundary_preview_for_a_community(self): self.accept_cookies() self.create_project_and_community() @@ -105,3 +112,18 @@ def test_project_boundary_preview_for_an_institution(self): ) self.py.visit(boundary_preview_url) self.verify_expected_boundary_data_is_present() + + def test_project_boundary_preview_without_selecting_any_boundary_data(self): + """ + The preview should not show boundary data + since no preview data was selected + """ + self.accept_cookies() + self.create_project_and_institution() + + time.sleep(5) # wait for Javascript actions + boundary_preview_url = urllib.parse.urljoin( + self.live_server_url, reverse('boundary-preview') + ) + self.py.visit(boundary_preview_url) + self.verify_expected_boundary_data_is_not_present() From 1d8c4fa0408b88581c11f4f6d38638bd07525d89 Mon Sep 17 00:00:00 2001 From: lc_hd Date: Tue, 1 Oct 2024 12:08:10 -0400 Subject: [PATCH 37/38] feat: added testcase for researcher preview boundary --- .../test_project_preview_boundary_ui.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/functional/test_project_preview_boundary_ui.py b/tests/functional/test_project_preview_boundary_ui.py index d60169f7..70893e2d 100644 --- a/tests/functional/test_project_preview_boundary_ui.py +++ b/tests/functional/test_project_preview_boundary_ui.py @@ -6,6 +6,7 @@ from functional.ui_feature_testcase_base import UiFeatureHelper from factories.projects_factories import ProjectFactory +from researchers.models import Researcher from communities.models import Community from institutions.models import Institution @@ -14,8 +15,10 @@ class TestProjectBoundaryPreviewFeatures(UiFeatureHelper): def setUp(self): self.login() + self.researcher_project = None self.community_project = None self.institution_project = None + self.researcher = None self.community = None self.institution = None @@ -31,6 +34,17 @@ def select_specific_nld_territory(self): self.py.get(".input-field.search").type(selected_territory) self.py.get(".region-results .result-item").click() + def create_project_and_researcher(self): + self.researcher = Researcher( + user=self.user, + ) + self.researcher.save() + self.researcher_project = ProjectFactory( + project_creator=self.user, + urls=[] + ) + self.researcher_project.save() + def create_project_and_community(self): self.community = Community( community_creator=self.user, @@ -65,6 +79,30 @@ def verify_expected_boundary_data_is_not_present(self): assert len(boundary) == default_boundary_count, 'Boundary preview data should not exist' self.py.get("#no-boundary-container").should().be_visible() + def test_project_boundary_preview_for_a_researcher(self): + self.accept_cookies() + self.create_project_and_researcher() + + # visit project edit page for researcher + researcher_project_url = urllib.parse.urljoin( + self.live_server_url, reverse( + 'researcher-edit-project', + kwargs={ + 'researcher_id': self.researcher.id, + 'project_uuid': self.researcher_project.unique_id, + } + ) + ) + self.py.visit(researcher_project_url) + self.select_specific_nld_territory() + + time.sleep(5) # wait for Javascript actions + boundary_preview_url = urllib.parse.urljoin( + self.live_server_url, reverse('boundary-preview') + ) + self.py.visit(boundary_preview_url) + self.verify_expected_boundary_data_is_present() + def test_project_boundary_preview_for_a_community(self): self.accept_cookies() self.create_project_and_community() From d534c6c571c0342653d87bce7fb782194984108c Mon Sep 17 00:00:00 2001 From: lc_hd Date: Tue, 1 Oct 2024 12:54:30 -0400 Subject: [PATCH 38/38] feat: created testcase for community settings boundary preview --- ...dary_ui.py => test_preview_boundary_ui.py} | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) rename tests/functional/{test_project_preview_boundary_ui.py => test_preview_boundary_ui.py} (87%) diff --git a/tests/functional/test_project_preview_boundary_ui.py b/tests/functional/test_preview_boundary_ui.py similarity index 87% rename from tests/functional/test_project_preview_boundary_ui.py rename to tests/functional/test_preview_boundary_ui.py index 70893e2d..36595b19 100644 --- a/tests/functional/test_project_preview_boundary_ui.py +++ b/tests/functional/test_preview_boundary_ui.py @@ -165,3 +165,27 @@ def test_project_boundary_preview_without_selecting_any_boundary_data(self): ) self.py.visit(boundary_preview_url) self.verify_expected_boundary_data_is_not_present() + + def test_community_settings_boundary_preview(self): + self.accept_cookies() + community = Community( + community_creator=self.user, + ) + community.save() + + # visit community boundary settings + community_boundary_settings_url = urllib.parse.urljoin( + self.live_server_url, reverse( + 'update-community-boundary', + kwargs={'pk': community.id} + ) + ) + self.py.visit(community_boundary_settings_url) + self.select_specific_nld_territory() + + time.sleep(5) # wait for Javascript actions + boundary_preview_url = urllib.parse.urljoin( + self.live_server_url, reverse('boundary-preview') + ) + self.py.visit(boundary_preview_url) + self.verify_expected_boundary_data_is_present() \ No newline at end of file