-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue #174] fixed wrong variable name in the work entry form
[Issue #174] because of failed test in case of non existing Human Resource for active user there was an unhandled exception. Created proper exception handling
- Loading branch information
Showing
6 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import pytest | ||
from django.test import LiveServerTestCase | ||
from selenium import webdriver | ||
from selenium.common.exceptions import TimeoutException | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions | ||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.common.keys import Keys | ||
from koalixcrm.test_support_functions import * | ||
from koalixcrm.crm.factories.factory_user import AdminUserFactory | ||
from koalixcrm.crm.factories.factory_customer import StandardCustomerFactory | ||
from koalixcrm.crm.factories.factory_customer_group import StandardCustomerGroupFactory | ||
from koalixcrm.crm.factories.factory_currency import StandardCurrencyFactory | ||
from koalixcrm.crm.factories.factory_human_resource import StandardHumanResourceFactory | ||
from koalixcrm.djangoUserExtension.factories.factory_user_extension import StandardUserExtensionFactory | ||
|
||
|
||
class TimeTrackingAddRow(LiveServerTestCase): | ||
|
||
def setUp(self): | ||
firefox_options = webdriver.firefox.options.Options() | ||
firefox_options.set_headless(headless=True) | ||
self.selenium = webdriver.Firefox(firefox_options=firefox_options) | ||
self.test_user = AdminUserFactory.create() | ||
self.test_customer_group = StandardCustomerGroupFactory.create() | ||
self.test_customer = StandardCustomerFactory.create(is_member_of=(self.test_customer_group,)) | ||
self.test_currency = StandardCurrencyFactory.create() | ||
self.test_user_extension = StandardUserExtensionFactory.create(user=self.test_user) | ||
|
||
def tearDown(self): | ||
self.selenium.quit() | ||
|
||
@pytest.mark.front_end_tests | ||
def test_add_new_row(self): | ||
selenium = self.selenium | ||
# login | ||
selenium.get('%s%s' % (self.live_server_url, '/koalixcrm/crm/reporting/time_tracking/')) | ||
# the browser will be redirected to the login page | ||
timeout = 5 | ||
try: | ||
element_present = expected_conditions.presence_of_element_located((By.ID, 'id_username')) | ||
WebDriverWait(selenium, timeout).until(element_present) | ||
except TimeoutException: | ||
print("Timed out waiting for page to load") | ||
username = selenium.find_element_by_xpath('//*[@id="id_username"]') | ||
password = selenium.find_element_by_xpath('//*[@id="id_password"]') | ||
submit_button = selenium.find_element_by_xpath('/html/body/div/article/div/div/form/div/ul/li/input') | ||
username.send_keys("admin") | ||
password.send_keys("admin") | ||
submit_button.send_keys(Keys.RETURN) | ||
# after the login, the browser is redirected to the target url /koalixcrm/crm/reporting/time_tracking | ||
try: | ||
element_present = expected_conditions.presence_of_element_located((By.ID, 'id_form-0-project')) | ||
WebDriverWait(selenium, timeout).until(element_present) | ||
except TimeoutException: | ||
print("Timed out waiting for page to load") | ||
# find the form element | ||
assert_when_element_does_not_exist(self, '//*[@id="id_form-0-project"]') | ||
assert_when_element_does_not_exist(self, '//*[@id="id_form-0-task"]') | ||
assert_when_element_does_not_exist(self, '//*[@id="id_form-0-date"]') | ||
assert_when_element_does_not_exist(self, '//*[@id="id_form-0-start_time"]') | ||
assert_when_element_does_not_exist(self, '//*[@id="id_form-0-stop_time"]') | ||
assert_when_element_does_not_exist(self, '//*[@id="id_form-0-description"]') | ||
assert_when_element_does_not_exist(self, 'save') | ||
# check existence of a second form before pressing add more | ||
assert_when_element_exists(self, '//*[@id="id_form-1-project"]') | ||
add_more_button = selenium.find_element_by_xpath('//*[@id="add_more"]') | ||
add_more_button.send_keys(Keys.RETURN) | ||
# check existence of a second form after pressing add more | ||
assert_when_element_does_not_exist(self, '//*[@id="id_form-1-project"]') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from django.http import HttpResponseRedirect, Http404 | ||
from django.shortcuts import render | ||
from django.template.context_processors import csrf | ||
from django.contrib.admin import helpers | ||
from django.contrib.admin.widgets import * | ||
from koalixcrm.djangoUserExtension.exceptions import TooManyUserExtensionsAvailable | ||
|
||
|
||
class ReportingPeriodMissingForm(forms.Form): | ||
NEXT_STEPS = ( | ||
('create_human_resource', 'Create Human Resource'), | ||
('return_to_start', 'Return To Start'), | ||
) | ||
next_steps = forms.ChoiceField(required=True, | ||
widget=forms.Select, | ||
choices=NEXT_STEPS) | ||
|
||
|
||
def user_is_not_human_resource(request): | ||
try: | ||
if request.POST.get('post'): | ||
if 'confirm_selection' in request.POST: | ||
reporting_period_missing_form = ReportingPeriodMissingForm(request.POST) | ||
if reporting_period_missing_form.is_valid(): | ||
if reporting_period_missing_form.cleaned_data['next_steps'] == 'return_to_start': | ||
return HttpResponseRedirect('/admin/') | ||
else: | ||
return HttpResponseRedirect('/admin/crm/humanresource/add/') | ||
else: | ||
reporting_period_missing_form = ReportingPeriodMissingForm(initial={'next_steps': 'create_user_extension'}) | ||
title = "User is not registered as Human Resource" | ||
description = "The operation you have selected requires that the currently active user is a registered " \ | ||
"as a Human Resource. " | ||
c = {'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME, | ||
'form': reporting_period_missing_form, | ||
'description': description, | ||
'title': title} | ||
c.update(csrf(request)) | ||
return render(request, 'crm/admin/exception.html', c) | ||
except TooManyUserExtensionsAvailable: | ||
raise Http404 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters