Tests for errant import data
----------------------------

This file has examples of bad data for the School Years sheet:

    >>> browser = Browser('manager', 'schooltool')
    >>> browser.getLink('Manage').click()
    >>> browser.getLink('XLS Import').click()
    >>> import pkg_resources
    >>> browser.getControl('XLS File').add_file(
    ...     pkg_resources.resource_stream('schooltool.export.ftests', 'errant_years.xls'),
    ...     'application/excel',
    ...     'sample_data.xls')
    >>> browser.getControl('Submit').click()
    >>> browser.printQuery("//p[@class='error']")
    <p class="error">School Years C2 has no date in it</p>
    <p class="error">School Years D2 has no date in it</p>
    <p class="error">School Years D3 end date cannot be before start date</p>
    <p class="error">School Years C5 start date overlaps another year</p>
    <p class="error">School Years D6 end date overlaps another year</p>

This file has examples of bad data for the Terms sheet:

    >>> browser.getLink('Manage').click()
    >>> browser.getLink('XLS Import').click()
    >>> import pkg_resources
    >>> browser.getControl('XLS File').add_file(
    ...     pkg_resources.resource_stream('schooltool.export.ftests', 'errant_terms.xls'),
    ...     'application/excel',
    ...     'sample_data.xls')
    >>> browser.getControl('Submit').click()
    >>> browser.printQuery("//p[@class='error']")
    <p class="error">Terms B2 missing required text</p>
    <p class="error">Terms C2 missing required text</p>
    <p class="error">Terms D2 has no date in it</p>
    <p class="error">Terms E2 has no date in it</p>
    <p class="error">Terms A3 invalid school year</p>
    <p class="error">Terms A4 invalid school year</p>
    <p class="error">Terms E5 end date cannot be before start date</p>
    <p class="error">Terms D6 start date before start of school year</p>
    <p class="error">Terms E7 end date after end of school year</p>
    <p class="error">Terms D10 start date overlaps another term</p>
    <p class="error">Terms E11 end date overlaps another term</p>
    <p class="error">Terms A15 has no date in it</p>
    <p class="error">Terms B16 has no date in it</p>
    <p class="error">Terms E17 end date cannot be before start date</p>

This file has examples of bad data for the School Timetables sheet:

    >>> browser.getLink('Manage').click()
    >>> browser.getLink('XLS Import').click()
    >>> import pkg_resources
    >>> browser.getControl('XLS File').add_file(
    ...     pkg_resources.resource_stream('schooltool.export.ftests', 'errant_timetables.xls'),
    ...     'application/excel',
    ...     'sample_data.xls')
    >>> browser.getControl('Submit').click()
    >>> browser.printQuery("//p[@class='error']")
    <p class="error">School Timetables B1 missing required text</p>
    <p class="error">School Timetables B2 missing required text</p>
    <p class="error">School Timetables B3 missing required text</p>
    <p class="error">School Timetables B4 missing required text</p>
    <p class="error">School Timetables B5 missing required text</p>
    <p class="error">School Timetables B10 missing required text</p>
    <p class="error">School Timetables B15 missing required text</p>
    <p class="error">School Timetables B20 missing required text</p>
    <p class="error">School Timetables B25 missing required text</p>
    <p class="error">School Timetables B35 missing required text</p>
    <p class="error">School Timetables B48 missing required text</p>

This file has examples of bad data for the Resouces sheet:

    >>> browser.getLink('Manage').click()
    >>> browser.getLink('XLS Import').click()
    >>> import pkg_resources
    >>> browser.getControl('XLS File').add_file(
    ...     pkg_resources.resource_stream('schooltool.export.ftests', 'errant_resources.xls'),
    ...     'application/excel',
    ...     'sample_data.xls')
    >>> browser.getControl('Submit').click()
    >>> browser.printQuery("//p[@class='error']")
    <p class="error">Resources B2 missing required text</p>
    <p class="error">Resources C2 missing required text</p>
    <p class="error">Resources B3 must be either 'Location', 'Equipment' or 'Resource'</p>

We'll add some demo fields to test importing demos.

    >>> browser.getLink('Manage').click()
    >>> browser.getLink('Demographics').click()
    >>> browser.getLink('New Text Field').click()
    >>> browser.getControl("Title").value = 'Text Demo'
    >>> browser.getControl("ID").value = 'text_demo'
    >>> browser.getControl(name="form.widgets.required:list").value = ["true"]
    >>> browser.getControl('Add').click()

    >>> browser.getLink('Manage').click()
    >>> browser.getLink('Demographics').click()
    >>> browser.getLink('New Date Field').click()
    >>> browser.getControl("Title").value = 'Date Demo'
    >>> browser.getControl("ID").value = 'date_demo'
    >>> browser.getControl(name="form.widgets.required:list").value = ["true"]
    >>> browser.getControl('Add').click()

    >>> browser.getLink('Manage').click()
    >>> browser.getLink('Demographics').click()
    >>> browser.getLink('New Yes/No Field').click()
    >>> browser.getControl("Title").value = 'Bool Demo'
    >>> browser.getControl("ID").value = 'bool_demo'
    >>> browser.getControl(name="form.widgets.required:list").value = ["true"]
    >>> browser.getControl('Add').click()

This file has examples of bad data for the Persons sheet:

    >>> browser.getLink('Manage').click()
    >>> browser.getLink('XLS Import').click()
    >>> import pkg_resources
    >>> browser.getControl('XLS File').add_file(
    ...     pkg_resources.resource_stream('schooltool.export.ftests', 'errant_persons.xls'),
    ...     'application/excel',
    ...     'sample_data.xls')
    >>> browser.getControl('Submit').click()
    >>> browser.printQuery("//p[@class='error']")
    <p class="error">Persons C2 missing required text</p>
    <p class="error">Persons E2 missing required text</p>
    <p class="error">Persons H2 has no date in it</p>
    <p class="error">Persons P2 missing required text</p>
    <p class="error">Persons Q2 has no date in it</p>
    <p class="error">Persons R2 missing required text</p>
    <p class="error">Persons Q3 has no date in it</p>
    <p class="error">Persons R3 must be either True or False</p>
    <p class="error">Persons A4 Username cannot contain non-ascii characters: gr...ta</p>

We'll remove the demo fields to not break future tests.

    >>> browser.getLink('Manage').click()
    >>> browser.getLink('Demographics').click()
    >>> browser.getControl(name='delete:list').value = ['text_demo', 'date_demo', 'bool_demo']
    >>> browser.getControl('Delete').click()

This file has examples of bad data for the Courses sheet:

    >>> browser.getLink('Manage').click()
    >>> browser.getLink('XLS Import').click()
    >>> import pkg_resources
    >>> browser.getControl('XLS File').add_file(
    ...     pkg_resources.resource_stream('schooltool.export.ftests', 'errant_courses.xls'),
    ...     'application/excel',
    ...     'sample_data.xls')
    >>> browser.getControl('Submit').click()
    >>> browser.printQuery("//p[@class='error']")
    <p class="error">Courses B2 missing required text</p>
    <p class="error">Courses C2 missing required text</p>
    <p class="error">Courses A4 invalid school year</p>

This file has examples of bad data for the Sections sheet:

    >>> browser.getLink('Manage').click()
    >>> browser.getLink('XLS Import').click()
    >>> import pkg_resources
    >>> browser.getControl('XLS File').add_file(
    ...     pkg_resources.resource_stream('schooltool.export.ftests', 'errant_sections.xls'),
    ...     'application/excel',
    ...     'sample_data.xls')
    >>> browser.getControl('Submit').click()
    >>> browser.printQuery("//p[@class='error']")
    <p class="error">School Timetables B5 missing required text</p>
    <p class="error">Sections 1 B1 missing required text</p>
    <p class="error">Sections 1 D1 missing required text</p>
    <p class="error">Sections_3 B1 invalid school year</p>
    <p class="error">Sections_4 D1 is not a valid term in the given school year</p>
    <p class="error">Sections_5 A12 is not a valid username</p>
    <p class="error">Sections_5 A17 is not a valid username</p>
    <p class="error">Sections_5 A20 is not a valid timetable in the given school year</p>

This file has examples of bad data for the Groups sheet:

    >>> browser.getLink('Manage').click()
    >>> browser.getLink('XLS Import').click()
    >>> import pkg_resources
    >>> browser.getControl('XLS File').add_file(
    ...     pkg_resources.resource_stream('schooltool.export.ftests', 'errant_groups.xls'),
    ...     'application/excel',
    ...     'sample_data.xls')
    >>> browser.getControl('Submit').click()
    >>> browser.printQuery("//p[@class='error']")
    <p class="error">Groups B1 missing required text</p>
    <p class="error">Groups B2 missing required text</p>
    <p class="error">Groups B3 missing required text</p>
    <p class="error">Groups A11 invalid school year</p>
    <p class="error">Groups A23 is not a valid username</p>

This file has examples of bad data for the Contact Persons and Contact
Relationships sheets:

    >>> browser.getLink('Manage').click()
    >>> browser.getLink('XLS Import').click()
    >>> import pkg_resources
    >>> browser.getControl('XLS File').add_file(
    ...     pkg_resources.resource_stream('schooltool.export.ftests', 'errant_contacts.xls'),
    ...     'application/excel',
    ...     'sample_data.xls')
    >>> browser.getControl('Submit').click()
    >>> browser.printQuery("//p[@class='error']")
    <p class="error">Contact Persons A2 Username cannot contain non-ascii characters: student00&#195;&#179;</p>
    <p class="error">Contact Persons C3 missing required text</p>
    <p class="error">Contact Persons E3 missing required text</p>
    <p class="error">Contact Persons B4 must be empty when ID is a user id</p>
    <p class="error">Contact Persons C4 must be empty when ID is a user id</p>
    <p class="error">Contact Persons D4 must be empty when ID is a user id</p>
    <p class="error">Contact Persons E4 must be empty when ID is a user id</p>
    <p class="error">Contact Persons F4 must be empty when ID is a user id</p>
    <p class="error">Contact Relationships B2 missing required text</p>
    <p class="error">Contact Relationships A3 Username cannot contain non-ascii characters: student00&#195;&#179;</p>
    <p class="error">Contact Relationships B3 Username cannot contain non-ascii characters: student00&#195;&#179;</p>
    <p class="error">Contact Relationships A4 is not a valid username</p>
    <p class="error">Contact Relationships B4 is not a valid username or contact id</p>
    <p class="error">Contact Relationships C4 is not a valid contact relationship</p>

