Skip to content

Commit

Permalink
Fix date-related Resources test errors; do other fixes (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
seav authored and oliverroick committed Mar 7, 2018
1 parent f78a33d commit 81c4bde
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 113 deletions.
2 changes: 1 addition & 1 deletion cadasta/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.6.0'
__version__ = '0.6.1'
16 changes: 8 additions & 8 deletions cadasta/test/organization_tests/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ def test_user_can_create_an_org(self):
assert self.get_url_path() == expected_path
self.wd.BY_XPATH('//h1[contains(.,"{}")]'.format(name))
about = self.wd.BY_CLASS('panel-about')
about.find_element_by_xpath('//*[.="Organization description."]')
about.find_element_by_xpath('//*[@href="http://example.com"]')
about.find_element_by_xpath('//*[text()="Contact Person"]')
about.find_element_by_xpath('//*[@href="mailto:[email protected]"]')
about.find_element_by_xpath('//*[@href="tel:1234567890"]')
about.find_element_by_xpath('.//*[.="Organization description."]')
about.find_element_by_xpath('.//*[@href="http://example.com"]')
about.find_element_by_xpath('.//*[text()="Contact Person"]')
about.find_element_by_xpath('.//*[@href="mailto:[email protected]"]')
about.find_element_by_xpath('.//*[@href="tel:1234567890"]')
self.wd.BY_XPATH('//*[contains(.,"Now add your first project.")]')

def test_name_is_required(self):
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_contact_name_is_required(self):
self.update_form_field('contacts-0-tel', '1234567890')
self.click_save_button()
self.wd.BY_CLASS('contacts-form').find_element_by_xpath(
'//*[.="Please provide a name."]')
'.//*[.="Please provide a name."]')

def test_contact_email_or_phone_is_required(self):
"""Verifies Organizations test case #C9."""
Expand All @@ -155,7 +155,7 @@ def test_contact_email_or_phone_is_required(self):
self.update_form_field('contacts-0-name', 'Contact Person')
self.click_save_button()
self.wd.BY_CLASS('contacts-form').find_element_by_xpath(
'//*[.="Please provide either an email address '
'.//*[.="Please provide either an email address '
'or a phone number."]')

def test_invalid_contact_email_address_is_rejected(self):
Expand All @@ -172,4 +172,4 @@ def test_invalid_contact_email_address_is_rejected(self):
self.update_form_field('contacts-0-tel', '1234567890')
self.click_save_button()
self.wd.BY_CLASS('contacts-form').find_element_by_xpath(
'//*[.="This field should be a valid email."]')
'.//*[.="This field should be a valid email."]')
10 changes: 5 additions & 5 deletions cadasta/test/organization_tests/test_updating.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ def test_org_admin_can_update_org(self, org_admin):
self.wd.BY_XPATH('//h1[normalize-space()="FuncTest Temp Name"]')
about = self.wd.BY_CLASS('panel-about')
about.find_element_by_xpath(
'//*[.="{}"]'.format(self.org['description']))
'.//*[.="{}"]'.format(self.org['description']))
about.find_element_by_xpath(
'//*[@href="{}"]'.format(json.loads(self.org['urls'])[0]))
'.//*[@href="{}"]'.format(json.loads(self.org['urls'])[0]))
contact = self.org['contacts'][0]
about.find_element_by_xpath('//*[.="{}"]'.format(contact['name']))
about.find_element_by_xpath('.//*[.="{}"]'.format(contact['name']))
about.find_element_by_xpath(
'//*[@href="mailto:{}"]'.format(contact['email']))
'.//*[@href="mailto:{}"]'.format(contact['email']))
about.find_element_by_xpath(
'//*[@href="tel:{}"]'.format(contact['tel']))
'.//*[@href="tel:{}"]'.format(contact['tel']))

# [REVERSION]
self.select_org_menu_item('Edit organization')
Expand Down
6 changes: 3 additions & 3 deletions cadasta/test/organization_tests/test_user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_org_member_can_view_the_org_members(
' normalize-space()="Members"]]')
for member in all_org_members:
panel.find_element_by_xpath(
'//*[.="{}"]'.format(member['username']))
'.//*[.="{}"]'.format(member['username']))
self.wd.BY_XPATH(
'//*[@id="sidebar"]//a[normalize-space()="Members"]').click()
select = Select(self.wd.BY_CSS('.dataTables_length select'))
Expand Down Expand Up @@ -146,7 +146,7 @@ def test_org_admin_can_view_the_membership_page_of_an_org_member(

def content_contains_text(text):
content.find_element_by_xpath(
'//*[text()[contains(.,"{}")]]'.format(text))
'.//*[text()[contains(.,"{}")]]'.format(text))

content_contains_text(member['username'])
if member['full_name']:
Expand All @@ -155,7 +155,7 @@ def content_contains_text(text):

if member['username'] == org_admin['username']:
content.find_element_by_xpath(
'//*[contains(@class,"member-role")]'
'.//*[contains(@class,"member-role")]'
'//*[text()[contains(.,"Administrator")]]')
else:
role_value = 'A' if member['admin'] else 'M'
Expand Down
28 changes: 14 additions & 14 deletions cadasta/test/project_tests/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def test_org_admin_can_create_public_project(self):
assert self.get_url_path() == expected_path
self.wd.BY_XPATH('//h1[contains(.,"{}")]'.format(name))
about = self.wd.BY_CLASS('panel-about')
about.find_element_by_xpath('//*[.="Project description."]')
about.find_element_by_xpath('//*[@href="http://example.com"]')
about.find_element_by_xpath('//*[text()="Contact Person"]')
about.find_element_by_xpath('//*[@href="mailto:[email protected]"]')
about.find_element_by_xpath('//*[@href="tel:1234567890"]')
about.find_element_by_xpath('.//*[.="Project description."]')
about.find_element_by_xpath('.//*[@href="http://example.com"]')
about.find_element_by_xpath('.//*[text()="Contact Person"]')
about.find_element_by_xpath('.//*[@href="mailto:[email protected]"]')
about.find_element_by_xpath('.//*[@href="tel:1234567890"]')

def test_org_admin_can_create_private_project(self):
"""Verifies Projects test case #C2."""
Expand Down Expand Up @@ -103,11 +103,11 @@ def test_org_admin_can_create_private_project(self):
self.wd.BY_XPATH(
'//h1[contains(normalize-space(),"{} Private")]'.format(name))
about = self.wd.BY_CLASS('panel-about')
about.find_element_by_xpath('//*[.="Project description."]')
about.find_element_by_xpath('//*[@href="http://example.com"]')
about.find_element_by_xpath('//*[text()="Contact Person"]')
about.find_element_by_xpath('//*[@href="mailto:[email protected]"]')
about.find_element_by_xpath('//*[@href="tel:1234567890"]')
about.find_element_by_xpath('.//*[.="Project description."]')
about.find_element_by_xpath('.//*[@href="http://example.com"]')
about.find_element_by_xpath('.//*[text()="Contact Person"]')
about.find_element_by_xpath('.//*[@href="mailto:[email protected]"]')
about.find_element_by_xpath('.//*[@href="tel:1234567890"]')

def test_non_org_admin_cannot_create_project(self, org_member):
"""Verifies Projects test case #C3."""
Expand Down Expand Up @@ -138,7 +138,7 @@ def test_extent_description_url_contacts_is_not_required(self):
assert self.get_url_path() == expected_path
self.wd.BY_XPATH('//h1[contains(.,"{}")]'.format(name))
self.wd.BY_CLASS('panel-about').find_element_by_xpath(
'//*[contains(.,"This project needs a description.")]')
'.//*[contains(.,"This project needs a description.")]')

def test_org_is_required(self):
"""Verifies Projects test case #C5."""
Expand Down Expand Up @@ -227,7 +227,7 @@ def test_contact_name_is_required(self):
self.update_form_field('details-contacts-0-tel', '1234567890')
self.click_wizard_next_button()
self.wd.BY_CLASS('contacts-form').find_element_by_xpath(
'//*[.="Please provide a name."]')
'.//*[.="Please provide a name."]')

def test_contact_email_or_phone_is_required(self):
"""Verifies Projects test case #C14."""
Expand All @@ -242,7 +242,7 @@ def test_contact_email_or_phone_is_required(self):
self.update_form_field('details-contacts-0-name', 'Contact Person')
self.click_wizard_next_button()
self.wd.BY_CLASS('contacts-form').find_element_by_xpath(
'//*[.="Please provide either an email address '
'.//*[.="Please provide either an email address '
'or a phone number."]')

def test_invalid_contact_email_address_is_rejected(self):
Expand All @@ -260,4 +260,4 @@ def test_invalid_contact_email_address_is_rejected(self):
self.update_form_field('details-contacts-0-tel', '1234567890')
self.click_wizard_next_button()
self.wd.BY_CLASS('contacts-form').find_element_by_xpath(
'//*[.="This field should be a valid email."]')
'.//*[.="This field should be a valid email."]')
10 changes: 5 additions & 5 deletions cadasta/test/project_tests/test_updating.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ def test_pm_can_update_project(self, prj_manager):
self.org['name']))
about = self.wd.BY_CLASS('panel-about')
about.find_element_by_xpath(
'//*[.="{}"]'.format(self.prj['description']))
'.//*[.="{}"]'.format(self.prj['description']))
about.find_element_by_xpath(
'//*[@href="{}"]'.format(json.loads(self.prj['urls'])[0]))
'.//*[@href="{}"]'.format(json.loads(self.prj['urls'])[0]))
contact = self.prj['contacts'][0]
about.find_element_by_xpath('//*[.="{}"]'.format(contact['name']))
about.find_element_by_xpath('.//*[.="{}"]'.format(contact['name']))
about.find_element_by_xpath(
'//*[@href="mailto:{}"]'.format(contact['email']))
'.//*[@href="mailto:{}"]'.format(contact['email']))
about.find_element_by_xpath(
'//*[@href="tel:{}"]'.format(contact['tel']))
'.//*[@href="tel:{}"]'.format(contact['tel']))

# [REVERSION]
self.select_prj_menu_item('Edit project details')
Expand Down
2 changes: 1 addition & 1 deletion cadasta/test/record_tests/test_location_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_unauthorized_user_cannot_create_location(
self.open(self.prj_dashboard_path)
try:
self.wd.BY_CSS('.page-header .btn-group').find_element_by_xpath(
'//*[normalize-space()="Add location"]')
'.//*[normalize-space()="Add location"]')
self.wd.BY_CSS('.page-header .btn-group .dropdown-toggle')
raise AssertionError('Project add location/menu is present')
except NoSuchElementException:
Expand Down
2 changes: 1 addition & 1 deletion cadasta/test/record_tests/test_party_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def test_unauthorized_user_cannot_create_party(
self.open(self.prj_dashboard_path)
try:
self.wd.BY_CSS('.page-header .btn-group').find_element_by_xpath(
'//*[normalize-space()="Add location"]')
'.//*[normalize-space()="Add location"]')
self.wd.BY_CSS('.page-header .btn-group .dropdown-toggle')
raise AssertionError('Project add location/menu is present')
except NoSuchElementException:
Expand Down
12 changes: 9 additions & 3 deletions cadasta/test/resource_tests/resources_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
from ..util import random_string


SHORT_MONTH_NAMES = (None, 'Jan.', 'Feb.', 'March', 'April', 'May', 'June',
'July', 'Aug.', 'Sept.', 'Oct.', 'Nov.', 'Dec.')


class ResourcesUtil(SeleniumTestCase):

def get_test_resource_data(self, filename):
dir_path = join(dirname(dirname(abspath(__file__))), 'files')
return {
'filename': filename,
'path': join(dir_path, filename),
'name': 'File ' + random_string(),
'name': 'File ' + random_string()[0:12],
'prefill': re.split('\.', re.sub('_', ' ', filename))[0],
'description': random_string(),
'type': re.split('\.', filename)[-1],
Expand All @@ -29,8 +33,10 @@ def do_table_search(self, query, filter_id='paginated-table-filter'):
def get_min_max_date(self):
max_date = date.today()
min_date = max_date + timedelta(days=-1)
max_date = max_date.strftime('%b %-d, %Y')
min_date = min_date.strftime('%b %-d, %Y')
max_date = max_date.strftime(
'{} %-d, %Y'.format(SHORT_MONTH_NAMES[max_date.month]))
min_date = min_date.strftime(
'{} %-d, %Y'.format(SHORT_MONTH_NAMES[min_date.month]))
return (min_date, max_date)

def delete_resource(self, resource, is_on_resource_page=True):
Expand Down
Loading

0 comments on commit 81c4bde

Please sign in to comment.