Skip to content

Commit

Permalink
[Issue #174] fixed testcase for the excepetion case no human resource…
Browse files Browse the repository at this point in the history
… available
  • Loading branch information
scaphilo committed Oct 12, 2018
1 parent d6a137a commit 8a768e7
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 20 deletions.
5 changes: 4 additions & 1 deletion koalixcrm/crm/documents/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ class OptionContract(admin.ModelAdmin):
'default_customer',
'default_supplier',
'staff',
'default_currency')
'default_currency',
'date_of_creation',
'last_modification',
'last_modified_by')
list_display_links = ('id',)
list_filter = ('default_customer',
'default_supplier',
Expand Down
63 changes: 47 additions & 16 deletions koalixcrm/crm/tests/test_user_is_not_human_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
Expand All @@ -11,7 +12,6 @@
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


Expand Down Expand Up @@ -50,21 +50,52 @@ def test_add_new_row(self):
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'))
element_present = expected_conditions.presence_of_element_located((By.ID, 'id_next_steps'))
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"]')

""" Because the user is not equipped with a corresponding human_resource, the user must receive an exception
screen giving im the possibility to select what he wants to do next
In this test_step it is checked whether the form contains the required fields. the test will then select
to return to the start page instead of defining a new human resource"""

assert_when_element_does_not_exist(self, '//*[@id="id_next_steps"]')
assert_when_element_does_not_exist(self, 'confirm_selection')
submit_button = selenium.find_element_by_xpath('/html/body/div/article/div/form/table/tbody/tr[3]/td/input[2]')
selection = Select(selenium.find_element_by_xpath('//*[@id="id_next_steps"]'))
selection.select_by_value("return_to_start")
submit_button.send_keys(Keys.RETURN)
try:
element_present = expected_conditions.presence_of_element_located((By.ID, 'grp-content-title'))
WebDriverWait(selenium, timeout).until(element_present)
except TimeoutException:
print("Timed out waiting for page to load")
assert_when_element_is_not_equal_to(self, 'grp-content-title', "<h1>Site administration</h1>")

""" Because the user is still not equipped with a corresponding human_resource, the user must
receive an exception screen giving im the possibility to select what he wants to do next
In this test_step it is checked whether the form contains the required fields. the test will then select
to return to the start page instead of defining a new human resource"""

selenium.get('%s%s' % (self.live_server_url, '/koalixcrm/crm/reporting/time_tracking/'))
try:
element_present = expected_conditions.presence_of_element_located((By.ID, 'id_next_steps'))
WebDriverWait(selenium, timeout).until(element_present)
except TimeoutException:
print("Timed out waiting for page to load")
assert_when_element_does_not_exist(self, '//*[@id="id_next_steps"]')
assert_when_element_does_not_exist(self, 'confirm_selection')
submit_button = selenium.find_element_by_xpath('/html/body/div/article/div/form/table/tbody/tr[3]/td/input[2]')
selection = Select(selenium.find_element_by_xpath('//*[@id="id_next_steps"]'))
selection.select_by_value("create_human_resource")
submit_button.send_keys(Keys.RETURN)
try:
element_present = expected_conditions.presence_of_element_located((By.ID, 'grp-content-title'))
WebDriverWait(selenium, timeout).until(element_present)
except TimeoutException:
print("Timed out waiting for page to load")
assert_when_element_is_not_equal_to(self, 'grp-content-title', "<h1>Add human resource</h1>")

""" This test is passed here, other testcases are performed to ensure proper functionality of this view
when the human resource is properly set"""
5 changes: 3 additions & 2 deletions koalixcrm/crm/views/time_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
def work_report(request):
try:
human_resource = HumanResource.objects.filter(user=UserExtension.get_user_extension(request.user))
if human_resource is None:
raise UserIsNoHumanResource()
if len(human_resource) == 0:
error_message = "User "+request.user.__str__()+" is not registered as human resource"
raise UserIsNoHumanResource(error_message)
if request.POST.get('post'):
if 'cancel' in request.POST:
return HttpResponseRedirect('/admin/')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@


class UserExtension(models.Model):
user = models.ForeignKey("auth.User", blank=False, null=False)
user = models.ForeignKey("auth.User",
blank=False,
null=False)
default_template_set = models.ForeignKey("TemplateSet")
default_currency = models.ForeignKey("crm.Currency")

Expand Down
9 changes: 9 additions & 0 deletions koalixcrm/test_support_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ def assert_when_element_exists(testcase, xpath):
print(xpath+" does exist")


def assert_when_element_is_not_equal_to(testcase, xpath, string):
try:
element = testcase.selenium.find_element_by_xpath(xpath)
if element.text != string:
print("issue")
except NoSuchElementException:
return


def make_date_utc(input_date):
output_date = pytz.timezone("UTC").localize(input_date, is_dst=None)
return output_date

0 comments on commit 8a768e7

Please sign in to comment.