def test_cannot_view_hidden_event(self): event = EventFactory(visible=False) self.client.force_login(UserFactory()) response = self.client.get(event.get_absolute_url()) self.assertTemplateUsed(response, "jeugdraad/alert.html") self.assertEqual( response.context["message"], "You are not allowed to view this event" )
def test_redirects_to_visible_event(self): EventFactory.create_batch(4, visible=False) visible_event = EventFactory(visible=True) self.client.force_login(UserFactory()) response = self.client.get("/") self.assertRedirects( response, visible_event.get_absolute_url(), status_code=302 )
def test_typeahead_thumbprint_never(self): event = EventFactory() self.client.force_login(UserFactory()) response = self.client.get(event.get_absolute_url()) self.assertEqual( response.context["typeahead_thumbprint"], "never", "typeahead thumbprint is not correct", )
def test_only_hidden_events_with_perm(self, mock_has_perm): mock_has_perm.return_value = True event = EventFactory(visible=False) user = UserFactory() self.client.force_login(user) response = self.client.get("/") self.assertRedirects(response, event.get_absolute_url(), status_code=302) mock_has_perm.assert_any_call(user, "booking.view_event", event)
def test_defaults_to_group_from_user(self): event = EventFactory() users = UserFactory.create_batch(5) self.client.force_login(users[2]) response = self.client.get(event.get_absolute_url(), follow=True) self.assertEqual( response.context["current_group"], users[2].group, "the rendered group is not the user's own group", ) self.assertTemplateUsed(response, "booking/event/event.html")
def test_view_event(self): event = EventFactory() self.client.force_login(UserFactory()) response = self.client.get(event.get_absolute_url()) self.assertEqual( response.context["current_event"], event, "the rendered event is not the requested event", ) self.assertEqual(response.status_code, 200) self.assertTemplateUsed("booking/event/event.html")
def test_exception_if_user_has_no_group_and_no_perm(self): event = EventFactory() users = UserFactory.create_batch(5) user_without_group = UserFactory(group=None) self.client.force_login(user_without_group) response = self.client.get(event.get_absolute_url(), follow=True) self.assertTemplateUsed(response, "jeugdraad/alert.html") self.assertEqual( response.context["message"], "You are not assigned to a group. Please contact a board member to resolve " "this issue.", )
def test_typeahead_thumbprint_not_none(self): materials = MaterialFactory.create_batch(3) last_material = MaterialFactory() self.assertNotEqual(materials[0].last_modified, last_material.last_modified) event = EventFactory() self.client.force_login(UserFactory()) response = self.client.get(event.get_absolute_url()) self.assertEqual( response.context["typeahead_thumbprint"], last_material.last_modified.isoformat(), "typeahead thumbprint is not correct", )
def test_defaults_to_all_if_user_has_no_group_and_perm(self, mock_has_perm): mock_has_perm.return_value = True event = EventFactory() users = UserFactory.create_batch(5) user_without_group = UserFactory(group=None) self.client.force_login(user_without_group) response = self.client.get(event.get_absolute_url(), follow=True) self.assertEqual( response.context["current_group"], None, "the rendered group is not 'all'" ) self.assertTemplateUsed(response, "booking/event/event.html") mock_has_perm.assert_any_call( user_without_group, "booking.view_others_groups_bookings", None )
def test_view_hidden_event_with_perm(self, mock_has_perm): mock_has_perm.return_value = True event = EventFactory(visible=False) user = UserFactory() self.client.force_login(user) response = self.client.get(event.get_absolute_url()) self.assertEqual( response.context["current_event"], event, "the rendered event is not the requested event", ) self.assertEqual(response.status_code, 200) self.assertTemplateUsed("booking/event/event.html") mock_has_perm.assert_any_call(user, "booking.view_event", event)
def test_navigation_search_material_and_material_alias(self): self.browser.set_window_size(1024, 768) event = EventFactory() material = MaterialFactory() # Bob is a logged in user bob = UserFactory() self.create_pre_authenticated_session(bob) # Bob opens the event page self.browser.get(self.live_server_url + event.get_absolute_url()) self.check_if_typeahead_loaded() # Bob clicks the search bar and enters the name of the material search_input = self.browser.find_element(By.ID, "navSearch") search_input.send_keys(material.name) search_input.send_keys(Keys.ENTER) # Bob sees the details for the typed material catalog_view_page = CatalogViewPage(self) catalog_view_page.verify_material_attributes( self.browser.find_element(By.ID, "catalogModal"), material ) # Bob closes the modal by pressing escape ActionChains(self.browser).send_keys(Keys.ESCAPE).perform() # Bob clicks the search bar and enters the alias of the material search_input = self.browser.find_element(By.ID, "navSearch") for _ in range(len(material.name)): search_input.send_keys(Keys.BACK_SPACE) search_input.send_keys(str(material.aliases.first())) search_input.send_keys(Keys.ENTER) # Choose the suggestion and submit form # Bob sees the details for the typed material self.wait_for( lambda: catalog_view_page.verify_material_attributes( self.browser.find_element(By.ID, "catalogModal"), material ) )
def test_can_open_catalog_from_event_page(self): event = EventFactory() # Bob is a logged in user bob = UserFactory() self.create_pre_authenticated_session(bob) # Bob opens the event page self.browser.get(self.live_server_url + event.get_absolute_url()) # Bob finds the button for switching to the catalog self.wait_for( lambda: self.assertCSSElementExists(".nav-link[href='/catalog/']") ) # Bob switches to the catalog self.browser.find_element( By.CSS_SELECTOR, ".nav-link[href='/catalog/']" ).click() # Bob sees the catalog masonry self.wait_for( lambda: self.assertCSSElementExists( ".catalog-masonry", msg="no masonry with materials was found on the page", ) ) # Bob finds beschuiten (rol) on the page data_attr = f"/catalog/{self.material.pk}/modal" selector = f"[data-catalog-item='{data_attr}']" self.wait_for( lambda: self.assertCSSElementExists( selector, msg="link to catalog item was not found", ) )
def test_redirects_to_latest_event(self): EventFactory.create_batch(4, event_end=now() + timedelta(days=24)) latest_event = EventFactory(event_end=now() + timedelta(days=50)) self.client.force_login(UserFactory()) response = self.client.get("/") self.assertRedirects(response, latest_event.get_absolute_url(), status_code=302)
def test_redirects_to_event(self): # There is only one event event = EventFactory() self.client.force_login(UserFactory()) response = self.client.get("/") self.assertRedirects(response, event.get_absolute_url(), status_code=302)