Skip to content

Commit

Permalink
feat: added similar testcase but for institutions
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-hd committed Sep 30, 2024
1 parent 593ce0d commit 39fbe56
Showing 1 changed file with 82 additions and 9 deletions.
91 changes: 82 additions & 9 deletions tests/functional/test_preview_boundary_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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,
}
)
)
Expand All @@ -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()

0 comments on commit 39fbe56

Please sign in to comment.