# -*- coding: utf-8 -*- import time from django.test import tag from django.urls import reverse from django.utils.translation import ugettext from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from dav_base.tests.generic import ScreenshotTestCase from dav_auth.tests.generic import SeleniumAuthMixin from .generic import RoleMixin TEST_TRAINER_EMAIL = 'trainer@localhost' TEST_PASSWORD = u'me||ön 21ABll' TEST_EVENT_DATA_S = { 'mode': 'training', 'sport': 'S', 'ski_lift': True, 'first_day': '24.12.2020', 'last_day': '26.12.2020', 'country': 'CH', 'location': u'St. Antönien', 'transport_other': 'Helikopter & SUV', 'meeting_point': 'dav', 'meeting_time': '10:29', 'return_arrival_time': '20:14', 'arrival_previous_day': True, 'basecamp': u'Grand Hôtel Belvedere', 'accommodation': 'NONE', 'meals_other': u'Fünf-Sterne-Küche per Zimmerservice und Minibar', 'requirements_add': u': https://de.wikipedia.org/wiki/Heliskiing', 'pre_meeting_1': '10.12.2020 18:35', 'trainer_firstname': u'Trainer1 Ö.', 'trainer_familyname': u'Ä. Tourenleiter', 'trainer_email': TEST_TRAINER_EMAIL, 'trainer_2_fullname': u'Trainer2 Überflieger', 'trainer_3_fullname': u'Trainer3 Weißalles', 'deadline': 'month', 'charge': '1800', 'additional_costs': None, 'course_topic_1': u'Grundkentnisse in der neusten Willy-Bögner-Kollektion', 'course_topic_2': u'Ein- & Aussteigen am Heliköpter', 'course_topic_3': u'Cocktailkunde für dekadentes Après-Ski', 'course_topic_4': u'Und vieles möhr', 'course_goal_1': [ u'"Gut" aussehen', u'Lässig sein', u'Geld scheißen', ], 'title': u'Heli-Skiing-Kurs für Snobs', 'description': [ u'Hier steht jetzt so allerhand Scheiß.', u'z.B. eine ÜRL: https://de.wikipedia.org (leider öhne Ümläüte)', u'& eine E-Mail-Ädresse: ' ], 'internal_note': [ u'Automatisierter Software Test', u'Viele Grüße', u' heinzel =u}', ], } TEST_EVENT_DATA_W = { 'level': 'advanced', 'first_day': '21.6.2020', 'alt_first_day': '22.06.2020', 'terrain': 'flats', 'location': u'Karlsruhe (Schloßpark)', 'transport': 'public', 'meeting_point_other': u'Bahnhof der Schloßgartenbahn', 'departure_time': '07:00', 'departure_ride': u'Schloßgartenbahn in Richtung "Schloßgartenbahnbahnhof"', 'return_departure_time': '19', 'return_arrival_time': '19:10', 'trainer_phone': u'+555 666 AB (Büro)', 'title': u'Wanderung durch den Karlsruher Schloßpark', 'description': [ u'Hier steht jetzt so allerhand Scheiß.', u'z.B. eine ÜRL: https://de.wikipedia.org (leider öhne Ümläüte)', u'& eine E-Mail-Ädresse: ' ], 'internal_note': [ u'Automatisierter Software Test', u'Viele Grüße', u' heinzel =u}', ], } TEST_EVENT_DATA_M = { 'sport': 'M', 'first_day': '21.6.2018', 'trainer_firstname': u'Other', 'trainer_familyname': u'Trainer', 'trainer_email': 'other.trainer@localhost', 'title': u'MTB-Zeitreise > 2018', 'description': [ u'Hier steht jetzt so allerhand Scheiß.', u'z.B. eine ÜRL: https://de.wikipedia.org (leider öhne Ümläüte)', u'& eine E-Mail-Ädresse: ' ], 'internal_note': [ u'Automatisierter Software Test', u'Viele Grüße', u' heinzel =u}', ], } @tag('screenshots', 'browser') class TestCase(SeleniumAuthMixin, RoleMixin, ScreenshotTestCase): headless = False screenshot_prefix = 'dav_events-' def create_event(self, event_data, auth=False, screenshots=True): data = event_data c = self.selenium c.get(self.complete_url(reverse('dav_events:root'))) if auth: sequence_name = 'create_event_auth' button = self.wait_on_presence(c, (By.ID, 'btn-events-list')) button.click() button = self.wait_on_presence(c, (By.ID, 'btn-event-create')) if screenshots: self.save_screenshot('event_list_before', sequence=sequence_name) else: sequence_name = 'create_event_unauth' button = self.wait_on_presence(c, (By.ID, 'btn-event-create')) button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('mode_form', sequence=sequence_name) if 'mode' in data: field = c.find_element(By.ID, 'id_mode') radio = field.find_element(By.CSS_SELECTOR, 'input[value=\'{}\']'.format(data['mode'])) radio.click() if 'sport' in data: field = c.find_element(By.ID, 'id_sport') radio = field.find_element(By.CSS_SELECTOR, 'input[value=\'{}\']'.format(data['sport'])) radio.click() if 'level' in data: field = c.find_element(By.ID, 'id_level') radio = field.find_element(By.CSS_SELECTOR, 'input[value=\'{}\']'.format(data['level'])) radio.click() if 'ski_lift' in data and data['ski_lift']: field = c.find_element(By.ID, 'id_ski_lift') field.click() field = c.find_element(By.CSS_SELECTOR, 'input#id_first_day_widget') field.send_keys(data['first_day']) td = c.find_element(By.CSS_SELECTOR, 'div.datetimepicker-days td.active') td.click() field = c.find_element(By.CSS_SELECTOR, 'input#id_last_day_widget') field.click() if screenshots: self.save_screenshot('last_date_widget', sequence=sequence_name) if 'last_day' in data: field.send_keys(data['last_day']) if 'alt_first_day' in data: field = c.find_element(By.CSS_SELECTOR, 'input#id_alt_first_day_widget') field.send_keys(data['alt_first_day']) if 'alt_last_day' in data: field = c.find_element(By.CSS_SELECTOR, 'input#id_alt_last_day_widget') field.send_keys(data['alt_last_day']) button = c.find_element(By.ID, 'btn-form-next') button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('location_form', sequence=sequence_name) if 'country' in data: field = c.find_element(By.ID, 'id_country') Select(field).select_by_value(data['country']) if 'terrain' in data: field = c.find_element(By.ID, 'id_terrain') Select(field).select_by_value(data['terrain']) if 'location' in data: field = c.find_element(By.ID, 'id_location') field.send_keys(data['location']) if 'transport_other' in data: field = c.find_element(By.ID, 'id_transport_other') field.send_keys(data['transport_other']) if 'transport' in data: field = c.find_element(By.ID, 'id_transport') Select(field).select_by_value(data['transport']) button = c.find_element(By.ID, 'btn-form-next') button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('journey_form', sequence=sequence_name) if 'meeting_point_other' in data: field = c.find_element(By.ID, 'id_meeting_point_other') field.send_keys(data['meeting_point_other']) if 'meeting_point' in data: field = c.find_element(By.ID, 'id_meeting_point') Select(field).select_by_value(data['meeting_point']) if 'meeting_time' in data: field = c.find_element(By.CSS_SELECTOR, 'input#id_meeting_time_widget') field.send_keys(data['meeting_time']) if 'departure_time' in data: field = c.find_element(By.CSS_SELECTOR, 'input#id_departure_time_widget') field.send_keys(data['departure_time']) if 'departure_ride' in data: field = c.find_element(By.ID, 'id_departure_ride') field.send_keys(data['departure_ride']) if 'return_departure_time' in data: field = c.find_element(By.CSS_SELECTOR, 'input#id_return_departure_time_widget') field.send_keys(data['return_departure_time']) if 'return_arrival_time' in data: field = c.find_element(By.CSS_SELECTOR, 'input#id_return_arrival_time_widget') field.send_keys(data['return_arrival_time']) if 'arrival_previous_day' in data and data['arrival_previous_day']: field = c.find_element(By.ID, 'id_arrival_previous_day') field.click() button = c.find_element(By.ID, 'btn-form-next') button.click() self.wait_until_stale(c, button) if 'last_day' in data: if screenshots: self.save_screenshot('accommodation_form', sequence=sequence_name) if 'basecamp' in data: field = c.find_element(By.ID, 'id_basecamp') field.send_keys(data['basecamp']) if 'accommodation' in data: field = c.find_element(By.ID, 'id_accommodation') Select(field).select_by_value(data['accommodation']) if 'meals_other' in data: field = c.find_element(By.ID, 'id_meals_other') field.send_keys(data['meals_other']) button = c.find_element(By.ID, 'btn-form-next') button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('requirements_form', sequence=sequence_name) if 'requirements_add' in data: field = c.find_element(By.ID, 'id_requirements') field.send_keys(Keys.RETURN) if isinstance(data['requirements_add'], list): field.send_keys(Keys.RETURN.join(data['requirements_add'])) else: field.send_keys(data['requirements_add']) if 'pre_meeting_1' in data: field = c.find_element(By.CSS_SELECTOR, 'input#id_pre_meeting_1_widget') field.send_keys(data['pre_meeting_1']) if 'pre_meeting_2' in data: field = c.find_element(By.CSS_SELECTOR, 'input#id_pre_meeting_2_widget') field.send_keys(data['pre_meeting_2']) button = c.find_element(By.ID, 'btn-form-next') button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('trainer_form', sequence=sequence_name) if 'trainer_firstname' in data: field = self.wait_on_presence(c, (By.ID, 'id_trainer_firstname')) if auth: field.clear() field.send_keys(data['trainer_firstname']) if 'trainer_familyname' in data: field = c.find_element(By.ID, 'id_trainer_familyname') if auth: field.clear() field.send_keys(data['trainer_familyname']) if 'trainer_email' in data: field = c.find_element(By.ID, 'id_trainer_email') if auth: field.clear() field.send_keys(data['trainer_email']) if 'trainer_phone' in data: field = c.find_element(By.ID, 'id_trainer_phone') if auth: field.clear() field.send_keys(data['trainer_phone']) if 'trainer_2_fullname' in data: field = c.find_element(By.ID, 'id_trainer_2_fullname') field.send_keys(data['trainer_2_fullname']) if 'trainer_3_fullname' in data: field = c.find_element(By.ID, 'id_trainer_3_fullname') field.send_keys(data['trainer_3_fullname']) button = c.find_element(By.ID, 'btn-form-next') button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('registration_form', sequence=sequence_name) if 'deadline' in data: field = c.find_element(By.ID, 'id_deadline') radio = field.find_element(By.CSS_SELECTOR, 'input[value=\'{}\']'.format(data['deadline'])) radio.click() button = c.find_element(By.ID, 'btn-form-next') button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('charges_form', sequence=sequence_name) if 'charge' in data: field = c.find_element(By.ID, 'id_charge') field.clear() field.send_keys(data['charge']) if 'additional_costs' in data: field = c.find_element(By.ID, 'id_additional_costs') field.clear() if data['additional_costs'] is not None: field.send_keys(data['additional_costs']) button = c.find_element(By.ID, 'btn-form-next') button.click() self.wait_until_stale(c, button) if 'mode' in data and data['mode'] == 'training': if screenshots: self.save_screenshot('training_form', sequence=sequence_name) field = c.find_element(By.ID, 'id_course_topic_1') if isinstance(data['course_topic_1'], list): field.send_keys(Keys.RETURN.join(data['course_topic_1'])) else: field.send_keys(data['course_topic_1']) if 'course_topic_2' in data: field = c.find_element(By.ID, 'id_course_topic_2') field.send_keys(data['course_topic_2']) if 'course_topic_3' in data: button = c.find_element(By.ID, 'btn-topic-add') button.click() field = c.find_element(By.ID, 'id_course_topic_3') field.send_keys(data['course_topic_3']) if 'course_topic_4' in data: button.click() field = c.find_element(By.ID, 'id_course_topic_4') field.send_keys(data['course_topic_4']) field = c.find_element(By.ID, 'id_course_goal_1') if isinstance(data['course_goal_1'], list): field.send_keys(Keys.RETURN.join(data['course_goal_1'])) else: field.send_keys(data['course_goal_1']) if 'course_goal_2' in data: field = c.find_element(By.ID, 'id_course_goal_2') field.send_keys(data['course_goal_2']) if 'course_goal_3' in data: button = c.find_element(By.ID, 'btn-goal-add') button.click() field = c.find_element(By.ID, 'id_course_goal_3') field.send_keys(data['course_goal_3']) if 'course_goal_4' in data: button.click() field = c.find_element(By.ID, 'id_course_goal_4') field.send_keys(data['course_goal_4']) button = c.find_element(By.ID, 'btn-form-next') button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('description_form', sequence=sequence_name) if 'title' in data: field = c.find_element(By.ID, 'id_title') field.clear() field.send_keys(data['title']) field = c.find_element(By.ID, 'id_description') if isinstance(data['description'], list): field.send_keys(Keys.RETURN.join(data['description'])) else: field.send_keys(data['description']) button = c.find_element(By.ID, 'btn-form-next') button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('summary_form', sequence=sequence_name) button = c.find_element(By.ID, 'btn-form-back') button.click() self.wait_until_stale(c, button) for i in range(0, 11): try: button = c.find_element(By.ID, 'btn-form-next') button.click() self.wait_until_stale(c, button) except NoSuchElementException: break else: # pragma: no cover self.fail('Too many sub forms') if 'internal_note' in data: field = c.find_element(By.ID, 'id_internal_note') if isinstance(data['internal_note'], list): field.send_keys(Keys.RETURN.join(data['internal_note'])) else: field.send_keys(data['internal_note']) button = c.find_element(By.ID, 'btn-form-submit') button.click() self.wait_until_stale(c, button) if not auth: if screenshots: self.save_screenshot('user_and_event_created_set_password', sequence=sequence_name) field = c.find_element(By.ID, 'id_new_password') field.send_keys(TEST_PASSWORD) field = c.find_element(By.ID, 'id_new_password_repeat') field.send_keys(TEST_PASSWORD) field.send_keys(Keys.RETURN) self.wait_until_stale(c, field) if screenshots: self.save_screenshot('finished', sequence=sequence_name) else: if screenshots: self.save_screenshot('event_list_after', sequence=sequence_name) def clone_event(self, title, screenshots=True): c = self.selenium sequence_name = 'clone_event' c.get(self.complete_url(reverse('dav_events:root'))) button = self.wait_on_presence(c, (By.ID, 'btn-events-list')) button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('event_list_before', sequence=sequence_name) link = c.find_element(By.LINK_TEXT, title) link.click() self.wait_until_stale(c, link) if screenshots: self.save_screenshot('event_details', sequence=sequence_name) button = c.find_element(By.ID, 'btn-clone') button.click() self.wait_until_stale(c, button) for i in range(0, 11): try: button = c.find_element(By.ID, 'btn-form-next') except NoSuchElementException: break if screenshots: self.save_screenshot('form', sequence=sequence_name) try: field = c.find_element(By.ID, 'id_deadline') radio = field.find_element(By.CSS_SELECTOR, 'input[value=\'OTHER\']') radio.click() except NoSuchElementException: pass button.click() self.wait_until_stale(c, button) else: # pragma: no cover self.fail('Too many sub forms') if screenshots: self.save_screenshot('summary', sequence=sequence_name) button = c.find_element(By.ID, 'btn-form-submit') button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('event-list-after', sequence=sequence_name) def edit_event(self, title, screenshots=True): c = self.selenium sequence_name = 'edit_event' c.get(self.complete_url(reverse('dav_events:root'))) button = self.wait_on_presence(c, (By.ID, 'btn-events-list')) button.click() self.wait_until_stale(c, button) link = c.find_element(By.LINK_TEXT, title) link.click() self.wait_until_stale(c, link) action_tabs = c.find_element(By.CSS_SELECTOR, '.action-tabs > ul.nav-tabs') tab = action_tabs.find_element(By.LINK_TEXT, ugettext(u'Ändern')) tab.click() self.wait_until_stale(c, tab) panels = c.find_elements(By.CSS_SELECTOR, '#form-accordion .panel-collapse') for panel in panels[:-1]: if screenshots: self.save_screenshot('edit-form', sequence=sequence_name) button = panel.find_element(By.PARTIAL_LINK_TEXT, ugettext(u'Nächster Abschnitt')) button.click() time.sleep(.5) if screenshots: self.save_screenshot('edit-form', sequence=sequence_name) button = c.find_element(By.CSS_SELECTOR, 'form button[type="submit"]') button.click() self.wait_until_stale(c, button) def accept_event(self, title, screenshots=True): c = self.selenium sequence_name = 'accept_event' c.get(self.complete_url(reverse('dav_events:root'))) button = self.wait_on_presence(c, (By.ID, 'btn-events-list')) button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('event_list_before', sequence=sequence_name) link = c.find_element(By.LINK_TEXT, title) link.click() self.wait_until_stale(c, link) if screenshots: self.save_screenshot('event_details', sequence=sequence_name) button = c.find_element(By.ID, 'btn-accept') button.click() time.sleep(.5) if screenshots: self.save_screenshot('accept_modal', sequence=sequence_name) button = c.find_element(By.CSS_SELECTOR, '#modal-accept-dialog a.btn-success') button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('accepted', sequence=sequence_name) link = c.find_element(By.LINK_TEXT, ugettext('Veranstaltungsliste')) link.click() self.wait_until_stale(c, link) if screenshots: self.save_screenshot('event_list_after', sequence=sequence_name) def confirm_publication_event(self, title, channel='all', screenshots=True): c = self.selenium sequence_name = 'confirm_publication' c.get(self.complete_url(reverse('dav_events:root'))) button = self.wait_on_presence(c, (By.ID, 'btn-events-list')) button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('event_list_before', sequence=sequence_name) link = c.find_element(By.LINK_TEXT, title) link.click() self.wait_until_stale(c, link) if screenshots: self.save_screenshot('event_details', sequence=sequence_name) button = c.find_element(By.ID, 'btn-confirmpublication') button.click() time.sleep(.5) if screenshots: self.save_screenshot('confirmpublication_modal', sequence=sequence_name) button = c.find_element(By.CSS_SELECTOR, '#btn-confirmpublication-{}'.format(channel)) button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('confirmed_{}'.format(channel), sequence=sequence_name) link = c.find_element(By.LINK_TEXT, ugettext('Veranstaltungsliste')) link.click() self.wait_until_stale(c, link) if screenshots: self.save_screenshot('event_list_after', sequence=sequence_name) def clear_event(self, title, screenshots=True): c = self.selenium sequence_name = 'clear' c.get(self.complete_url(reverse('dav_events:root'))) button = self.wait_on_presence(c, (By.ID, 'btn-events-list')) button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('event_list_before', sequence=sequence_name) link = c.find_element(By.LINK_TEXT, title) link.click() self.wait_until_stale(c, link) if screenshots: self.save_screenshot('event_details', sequence=sequence_name) button = c.find_element(By.ID, 'btn-confirmclearance') button.click() self.wait_until_stale(c, button) if screenshots: self.save_screenshot('confirmed_clearance', sequence=sequence_name) link = c.find_element(By.LINK_TEXT, ugettext('Veranstaltungsliste')) link.click() self.wait_until_stale(c, link) if screenshots: self.save_screenshot('event_list_after', sequence=sequence_name) def setUp(self): super(TestCase, self).setUp() self.manager_super = self.create_user_for_role('manager_super', 'Manager Super', 'Tourenreferent', password=TEST_PASSWORD) self.manager_w = self.create_user_for_role('manager_w', 'Manager W', 'BereichsleiterWandern', password=TEST_PASSWORD) self.manager_s = self.create_user_for_role('manager_s', 'Manager S', 'BereichsleiterSki', password=TEST_PASSWORD) self.publisher_print = self.create_user_for_role('publisher_print', 'Publisher Print', 'RedaktionPrint', password=TEST_PASSWORD) self.publisher_web = self.create_user_for_role('publisher_web', 'Publisher Web', 'RedaktionWeb', password=TEST_PASSWORD) self.publisher_facebook = self.create_user_for_role('publisher_facebook', 'Publisher Facebook', 'RedaktionFacebook', password=TEST_PASSWORD) def test_screenshots(self): # self.quit_selenium = False c = self.selenium self.get(reverse('dav_events:root')) self.save_screenshot('home') self.create_event(TEST_EVENT_DATA_S, auth=False) self.create_event(TEST_EVENT_DATA_W, auth=True) self.create_event(TEST_EVENT_DATA_M, auth=True) link = c.find_element(By.LINK_TEXT, TEST_EVENT_DATA_W['title']) link.click() self.wait_until_stale(c, link) self.save_screenshot('owner_event_details') self.logout(c) self.login(c, self.manager_s.username, TEST_PASSWORD) self.edit_event(TEST_EVENT_DATA_S['title']) self.accept_event(TEST_EVENT_DATA_S['title']) self.logout(c) self.login(c, self.manager_super.username, TEST_PASSWORD) self.accept_event(TEST_EVENT_DATA_W['title']) self.logout(c) self.login(c, self.publisher_web.username, TEST_PASSWORD) self.confirm_publication_event(TEST_EVENT_DATA_S['title'], channel='web') self.logout(c) self.login(c, self.publisher_facebook.username, TEST_PASSWORD) self.confirm_publication_event(TEST_EVENT_DATA_S['title'], channel='facebook') self.logout(c) self.login(c, self.publisher_facebook.username, TEST_PASSWORD) self.confirm_publication_event(TEST_EVENT_DATA_W['title'], channel='facebook') self.logout(c) self.login(c, self.publisher_web.username, TEST_PASSWORD) self.confirm_publication_event(TEST_EVENT_DATA_W['title'], channel='web') self.logout(c) self.login(c, TEST_TRAINER_EMAIL, TEST_PASSWORD) self.clone_event(TEST_EVENT_DATA_S['title']) self.logout(c) self.login(c, self.publisher_print.username, TEST_PASSWORD) c.get(self.complete_url(reverse('dav_events:root'))) button = self.wait_on_presence(c, (By.ID, 'btn-events-list')) button.click() self.wait_until_stale(c, button) link = c.find_element(By.PARTIAL_LINK_TEXT, ugettext(u'Veranstaltungsliste herunterladen')) link.click() self.wait_until_stale(c, link) self.save_screenshot('event_export_form') self.logout(c) self.login(c, self.manager_super.username, TEST_PASSWORD) self.clear_event(TEST_EVENT_DATA_M['title']) self.logout(c)