diff --git a/communities/utils.py b/communities/utils.py index e15205630..0dd635334 100644 --- a/communities/utils.py +++ b/communities/utils.py @@ -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) diff --git a/communities/views.py b/communities/views.py index e1ed87379..bccab2a59 100644 --- a/communities/views.py +++ b/communities/views.py @@ -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') diff --git a/tests/functional/test_create_community_gis_ui.py b/tests/functional/test_create_community_gis_ui.py index cbf3e7b06..d5db771cf 100644 --- a/tests/functional/test_create_community_gis_ui.py +++ b/tests/functional/test_create_community_gis_ui.py @@ -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 @@ -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() @@ -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') @@ -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 @@ -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)