Skip to content

Commit

Permalink
feat: redirect user to the create-boundary page in sandbox to match w…
Browse files Browse the repository at this point in the history
…hen not in sandbox
  • Loading branch information
lc-hd committed Oct 25, 2024
1 parent 2d3c566 commit 0166b60
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions communities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def has_new_community_id(function):
@wraps(function)
def wrap(request, *args, **kwargs):
if not request.session.get('new_community_id'):
print('Not NEW COMMUNITY ID IS PRESENT')
return render(request, '403.html', status=403)
return function(request, *args, **kwargs)

Expand Down
3 changes: 2 additions & 1 deletion communities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,13 @@ def create_community(request):
if env == 'SANDBOX':
data.is_approved = True
data.save()
request.session['new_community_id'] = data.id

# Add to user affiliations
affiliation = UserAffiliation.objects.prefetch_related('communities').get(user=request.user)
affiliation.communities.add(data)
affiliation.save()
return redirect('dashboard')
return redirect('community-boundary')
elif subscription_form.is_valid():
handle_community_creation(request, data, subscription_form, env)
return redirect('community-boundary')
Expand Down
31 changes: 25 additions & 6 deletions tests/functional/test_create_community_gis_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import faker
import pytest
from django.shortcuts import redirect
from django.urls import reverse
from selenium.webdriver.common.alert import Alert

Expand All @@ -15,6 +16,22 @@
from communities.models import Community



@pytest.fixture
def session_data(request):
# Access the session object
session = request.session

# Set values in the session
session['user_id'] = 123
session['username'] = 'testuser'

yield session

# Optionally, clean up the session after the test
session.clear()


class TestFeatures(UiFeatureHelper):
def setUp(self):
self.login()
Expand All @@ -37,9 +54,9 @@ def fill_out_and_submit_account_creation_form(self):
self.community_name = self.fake.name()

# fill out form
self.py.get("[name='first_name']").type(self.community_name)
self.py.get("[name='first_name']").type(self.fake.name())
self.py.get("[name='last_name']").type(self.fake.name())
self.py.get("[name='community_name']").type(self.fake.name())
self.py.get("[name='community_name']").type(self.community_name)
self.py.get("[name='community_entity']").type(self.fake.name())
self.py.get("[name='state_province_region']").type(self.fake.name())
self.py.get("[name='country']").type('Antartica')
Expand All @@ -54,8 +71,10 @@ def fill_out_and_submit_account_creation_form(self):
# bypass validate_recaptcha on the backend when clicking this button
with patch('communities.views.validate_recaptcha') as mock_validate_recaptcha:
mock_validate_recaptcha.return_value = True
self.py.get(".primary-btn").click()

with patch('communities.views.dev_prod_or_local') as mock_dev_prod_or_local:
mock_dev_prod_or_local.return_value = 'SANDBOX'
self.py.get(".primary-btn").click()

def select_native_land_method_and_submit(self):
# pick NLD add boundary radio button
Expand Down Expand Up @@ -99,9 +118,9 @@ def navigate_to_search_native_land_digital_database_page(self):
assert self.select_add_boundary_method_path in self.get_current_url()

self.select_native_land_method_and_submit()
#
# # verify user is on select boundary by nld page
# assert self.select_nld_add_boundary_method_path in self.get_current_url()

# verify user is on select boundary by nld page
assert self.select_nld_add_boundary_method_path in self.get_current_url()

def navigate_to_upload_shapefile_page(self):
create_community_url = urllib.parse.urljoin(self.live_server_url, self.create_community_path)
Expand Down

0 comments on commit 0166b60

Please sign in to comment.