=====================
Student Interventions
=====================

These are the functional tests for the intervention package.

First we need to set up the school.

    >>> from schooltool.intervention.browser import ftests
    >>> from schooltool.app.browser.ftests import setup
    >>> setup.setUpBasicSchool()
    >>> manager = setup.logIn('manager', 'schooltool')


Interventions
-------------

Now we come to the main intervention center that gives us access to all of the
intervention data associated with a given student for a given school year.
We'll create some teachers and students and put them in some sections.
We will also create a principal and guidance counselor and put them in the
adminstators group.  These users will show up as part of the list of persons
responsible for any student and will also have permission to work with the
intervention of any student.

    >>> from schooltool.intervention.browser.ftests import (
    ...     addPerson, addCourseSectionMembers, fillInContactInfo)

    >>> manager.getLink('Home').click()
    >>> fillInContactInfo('manager', email='manager@example.com')

    >>> addPerson('Teacher1', 'Teacher1', 'teacher1', 'pwd', groups=['teachers'])
    >>> addPerson('Teacher2', 'Teacher2', 'teacher2', 'pwd', groups=['teachers'])
    >>> addPerson('Student1', 'Student1', 'student1', 'pwd', groups=['students'])
    >>> addPerson('Student2', 'Student2', 'student2', 'pwd', groups=['students'])
    >>> addPerson('Student3', 'Student3', 'student3', 'pwd', groups=['students'])
    >>> addCourseSectionMembers('course1', 'section1', ['Teacher1'],
    ...     ['Student1', 'Student3'])
    >>> addCourseSectionMembers('course2', 'section2', ['Teacher2'],
    ...     ['Student2'])
    >>> addPerson('Counselor', 'Counselor', 'counselor', 'pwd', groups=['administrators'])
    >>> addPerson('Principal', 'Principal', 'principal', 'pwd', groups=['administrators'])
    >>> addPerson('Search Person', 'Person Search', 'sperson', 'pwd')

Let's add a parent contact and an advisor which will show up when adding goals
and messages.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()
    >>> manager.getLink('Student1').click()
    >>> manager.getLink('Contacts').click()
    >>> manager.getLink('Manage Contacts').click()
    >>> manager.getLink('Create new contact').click()
    >>> manager.getControl('First name').value = 'Parent1'
    >>> manager.getControl('Last name').value = 'Parent1'
    >>> manager.getControl('Email').value = 'parent@somewhere.com'
    >>> manager.getControl('Relationship').value = ['parent']
    >>> manager.getControl('Add').click()

    >>> manager.getLink('Advisors').click()
    >>> manager.getControl(name='add_item.teacher2').value = 'checked'
    >>> manager.getControl('Add').click()

To navigate to a student's intervention, a manager can navigate to the student
and click on the 'Intervention Center' action link.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()
    >>> manager.getLink('Student1').click()
    >>> manager.getLink('Intervention Center').click()
    >>> print manager.contents
    <BLANKLINE>
    ...Student Intervention Center...
    ...Student1 Student1...
    ...Messages and Observations...
    ...There are none...
    ...New Message...
    ...Goals and Interventions...
    ...There are none...
    ...New Goal...
    ...Change of Status Messages...
    ...There are none...
    ...New Status Message...


Intervention Messages
---------------------

The first thing we'll add is a new message.  Calling up the add view, we'll
note that the list of possible recipients will include, in order, the student's
advisors, the school administrators, the student's teachers, the student,
and the student's parents.  Advisors and parents will have all caps prefixes
before their names to make it easier for the user to pick them out.  Also,
the advisors will be pre-checked.

    >>> manager.getLink('New Message').click()
    >>> print manager.contents
    <BLANKLINE>
    ...Recipients...
    ...checked="checked"...
    ...Teacher2 Teacher2 (advisor)...
    ...Counselor...
    ...Principal...
    ...Teacher1...
    ...Student1...
    ...Parent1 Parent1 (parent)...

We'll test how the add view handles missing input.  We'll need to uncheck the
advisor to make the recipients input cause the error.

    >>> manager.getControl(name='person.teacher2').value = False
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    >>> print manager.contents
    <BLANKLINE>
    ...There are <strong>2</strong> input errors...
    ...Required data was not supplied...
    ...Required input is missing...

We'll fill in the required fields and hit the Add button.  Note that upon
successfully adding the message, an email will appear in the output.  This
is the result of the dummy mail sender that we use during testing that prints
emails that would otherwise be sent to the smtp mail server that a live
environment would have configured.  Also note that the parent's email address
will be picked up from the student's demos.

    >>> manager.getControl(name='person.teacher1').value = True
    >>> manager.getControl(name='person.student1:1').value = True
    >>> manager.getControl(name='field.body').value = 'hi\nthere'
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    From: manager@example.com
    To: parent@somewhere.com, teacher1@example.com
    Subject: INTERVENTION MESSAGE: Student1 Student1
    SchoolTool Administrator writes:
    <BLANKLINE>
    hi
    there

Note that the successfully added message appears in the Intervention Center
with the username of the sender, in this case, manager.

    >>> print manager.contents
    <BLANKLINE>
    ...Messages and Observations...
    ...Message from SchoolTool Administrator...
    ...New Message...

Let's make sure we can view the message that we just added.  Note that the
message body will be broken into <p> tags, one for each line.

    >>> manager.getLink('Message from SchoolTool Administrator').click()
    >>> analyze.printQuery("id('content-body')//div//span", manager.contents)
    <span>Parent1 Parent1, Teacher1 Teacher1</span>
    >>> analyze.printQuery("id('content-body')//p", manager.contents)
    <p>hi</p>
    <p>there</p>

We should be able to return to the Intervention Center with a link.

    >>> manager.getLink('Intervention Center').click()
    >>> print manager.contents
    <BLANKLINE>
    ...Messages and Observations...
    ...Message from SchoolTool Administrator...
    ...New Message...

We'll add a second message to test the system's handling of multiple
messages.  Messages are sorted by date.

    >>> manager.getLink('New Message').click()
    >>> manager.getControl(name='person.teacher1').value = True
    >>> manager.getControl(name='field.body').value = 'hello again'
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    From: manager@example.com
    To: teacher1@example.com, teacher2@example.com
    Subject: INTERVENTION MESSAGE: Student1 Student1
    SchoolTool Administrator writes:
    <BLANKLINE>
    hello again
    >>> print manager.contents
    <BLANKLINE>
    ...Messages and Observations...
    ...student1/messages/2...Message from SchoolTool Administrator...
    ...student1/messages/1...Message from SchoolTool Administrator...
    ...New Message...

There is a button that allows us to call up the report that presents all of
the messages together.  The messages are sorted by creation date.

    >>> manager.getLink('View All Messages').click()
    >>> analyze.printQuery("id('content-body')//span", manager.contents)
    <span>Message sent by SchoolTool Administrator on ...</span>
    <span>Teacher1 Teacher1, Teacher2 Teacher2</span>
    <span>Message sent by SchoolTool Administrator on ...</span>
    <span>Parent1 Parent1, Teacher1 Teacher1</span>
    >>> analyze.printQuery("id('content-body')//p", manager.contents)
    <p>hello again</p>
    <p>hi</p>
    <p>there</p>

We'll return the the Intervention Center.

    >>> manager.getLink('Intervention Center').click()
    >>> print manager.contents
    <BLANKLINE>
    ...Messages and Observations...
    ...Message from SchoolTool Administrator...
    ...Message from SchoolTool Administrator...
    ...New Message...


Intervention Goals
------------------

The next thing to start adding is Goals.  We'll test how the add view
handles missing input while we're at it.  To make the persons responsible
field have missing data, we'll need to uncheck the advisor that comes
pre-checked.

    >>> from datetime import date
    >>> manager.getLink('New Goal').click()
    >>> manager.getControl(name='person.teacher2').value = False
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    >>> print manager.contents
    <BLANKLINE>
    ...There are <strong>7</strong> input errors...
    ...Persons responsible...
    ...Required data was not supplied...
    ...Presenting concerns...
    ...Required input is missing...
    ...Goal...
    ...Required input is missing...
    ...Strengths...
    ...Required input is missing...
    ...Indicators...
    ...Required input is missing...
    ...Intervention...
    ...Required input is missing...
    ...Timeline...
    ...Required input is missing...
    ...checked="checked"...
    ...Goal not met...
    ...Goal met...

Now we'll fill in the required fields.  We'll include the student and the
parent in the persons responsible list to demostrate how adding the goal
will split the email by staff and students/parents.  Students and parents
will not get a link back to the intervention center in their email.

    >>> manager.getControl('Presenting concerns').value = 'Poor attendence'
    >>> manager.getControl(name='field.goal').value = 'Get student to come in more often'
    >>> manager.getControl('Strengths').value = 'Attentive when there'
    >>> manager.getControl('Indicators').value = 'Student appears at least 4 time a week'
    >>> manager.getControl('Intervention').value = 'Call parents to arrange better attendence'
    >>> manager.getControl('Timeline').value = str(date.today())
    >>> manager.getControl(name='person.teacher1').value = True
    >>> manager.getControl(name='person.student1').value = True
    >>> manager.getControl(name='person.student1:1').value = True
    >>> manager.getControl(name='goal_met').value = ['Yes']
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    From: manager@example.com
    To: teacher1@example.com
    Subject: INTERVENTION GOAL ADDED: Student1 Student1
    The following goal was added for Student1 Student1:
    <BLANKLINE>
    Presenting concerns
    -------------------
    <BLANKLINE>
    Poor attendence
    <BLANKLINE>
    Goal
    ----
    <BLANKLINE>
    Get student to come in more often
    <BLANKLINE>
    Strengths
    ---------
    <BLANKLINE>
    Attentive when there
    <BLANKLINE>
    Indicators
    ----------
    <BLANKLINE>
    Student appears at least 4 time a week
    <BLANKLINE>
    Intervention
    ------------
    <BLANKLINE>
    Call parents to arrange better attendence
    <BLANKLINE>
    Timeline
    --------
    <BLANKLINE>
    ...
    <BLANKLINE>
    Persons responsible
    -------------------
    <BLANKLINE>
    Parent1 Parent1
    Student1 Student1
    Teacher1 Teacher1
    <BLANKLINE>
    Intervention Center
    -------------------
    <BLANKLINE>
    http://localhost/schooltool.interventions/2005-2006/student1
    <BLANKLINE>
    From: manager@example.com
    To: parent@somewhere.com, student1@example.com
    Subject: INTERVENTION GOAL ADDED: Student1 Student1
    The following goal was added for Student1 Student1:
    <BLANKLINE>
    Presenting concerns
    -------------------
    <BLANKLINE>
    Poor attendence
    <BLANKLINE>
    Goal
    ----
    <BLANKLINE>
    Get student to come in more often
    <BLANKLINE>
    Strengths
    ---------
    <BLANKLINE>
    Attentive when there
    <BLANKLINE>
    Indicators
    ----------
    <BLANKLINE>
    Student appears at least 4 time a week
    <BLANKLINE>
    Intervention
    ------------
    <BLANKLINE>
    Call parents to arrange better attendence
    <BLANKLINE>
    Timeline
    --------
    <BLANKLINE>
    ...
    <BLANKLINE>
    Persons responsible
    -------------------
    <BLANKLINE>
    Parent1 Parent1
    Student1 Student1
    Teacher1 Teacher1

Note that the successfully added goal appears in the Intervention Center as
'Goal 1'.

    >>> print manager.contents
    <BLANKLINE>
    ...Goals and Interventions...
    ...Goal 1...
    ...New Goal...

Let's make sure we can view the message that we just added.

    >>> manager.getLink('Goal 1').click()
    >>> print manager.contents
    <BLANKLINE>
    ...Persons responsible...
    ...Parent1 Parent1...
    ...Student1 Student1...
    ...Teacher1 Teacher1...
    ...Presenting concerns...
    ...Poor attendence...
    ...Goal...
    ...Get student to come in more often...
    ...Strengths...
    ...Attentive when there...
    ...Indicators...
    ...Student appears at least 4 time a week...
    ...Intervention...
    ...Call parents to arrange better attendence...
    ...Timeline...
    ...Goal met...
    ...Yes...
    ...Follow up notes...

Now that we've added a goal, let's edit it's strengths attribute and see that
the change is reflected in the goal's view.

    >>> manager.getLink('Edit').click()
    >>> print manager.contents
    <BLANKLINE>
    ...Goal not met...
    ...checked="checked"...
    ...Goal met...
    >>> manager.getControl('Strengths').value = 'Good listener'
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    >>> print manager.contents
    <BLANKLINE>
    ...Strengths...
    ...Good listener...
    ...Indicators...

We should be able to return to the Intervention Center with a link.

    >>> manager.getLink('Intervention Center').click()
    >>> print manager.contents
    <BLANKLINE>
    ...Goals and Interventions...
    ...Goal 1...
    ...New Goal...

Let's add a second goal to test our handling of multiple goals both in the
notification view and the goals report.

    >>> manager.getLink('New Goal').click()
    >>> manager.getControl('Presenting concerns').value = 'Rude behavior'
    >>> manager.getControl(name='field.goal').value = 'Get student to be more polite'
    >>> manager.getControl('Strengths').value = 'Good grades'
    >>> manager.getControl('Indicators').value = 'Student no longer offends classmates'
    >>> manager.getControl('Intervention').value = 'Call parents to alert them to bad manners'
    >>> manager.getControl('Timeline').value = str(date.today())
    >>> manager.getControl(name='person.teacher2').value = False
    >>> manager.getControl(name='person.teacher1').value = True
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    From: manager@example.com
    To: teacher1@example.com
    Subject: INTERVENTION GOAL ADDED: Student1 Student1
    The following goal was added for Student1 Student1:
    <BLANKLINE>
    Presenting concerns
    -------------------
    <BLANKLINE>
    Rude behavior
    <BLANKLINE>
    Goal
    ----
    <BLANKLINE>
    Get student to be more polite
    <BLANKLINE>
    Strengths
    ---------
    <BLANKLINE>
    Good grades
    <BLANKLINE>
    Indicators
    ----------
    <BLANKLINE>
    Student no longer offends classmates
    <BLANKLINE>
    Intervention
    ------------
    <BLANKLINE>
    Call parents to alert them to bad manners
    <BLANKLINE>
    Timeline
    --------
    <BLANKLINE>
    ...
    <BLANKLINE>
    Persons responsible
    -------------------
    <BLANKLINE>
    Teacher1 Teacher1
    <BLANKLINE>
    Intervention Center
    -------------------
    <BLANKLINE>
    http://localhost/schooltool.interventions/2005-2006/student1
    >>> print manager.contents
    <BLANKLINE>
    ...Goals and Interventions...
    ...Goal 1...
    ...Goal 2...
    ...New Goal...

There is a button that allows us to call up the report that presents all of
the goals together.  Its output is a concatonation of what the view of goal 1
and the view of goal 2 would present.

    >>> manager.getLink('View All Goals').click()
    >>> print manager.contents
    <BLANKLINE>
    ...Presenting concerns...
    ...Poor attendence...
    ...Goal...
    ...Get student to come in more often...
    ...Strengths...
    ...Good listener...
    ...Indicators...
    ...Student appears at least 4 time a week...
    ...Intervention...
    ...Call parents to arrange better attendence...
    ...Timeline...
    ...Persons responsible...
    ...Parent1 Parent1...
    ...Student1 Student1...
    ...Teacher1 Teacher1...
    ...Goal met...
    ...Yes...
    ...Follow up notes...
    ...Presenting concerns...
    ...Rude behavior...
    ...Goal...
    ...Get student to be more polite...
    ...Strengths...
    ...Good grades...
    ...Indicators...
    ...Student no longer offends classmates...
    ...Intervention...
    ...Call parents to alert them to bad manners...
    ...Timeline...
    ...Persons responsible...
    ...Teacher1 Teacher1...
    ...Goal met...
    ...No...
    ...Follow up notes...

We have a view that can be called up at any time that will send emails for
goals that have come due today (we set up our goals to be due today).  This
view will best be called automatically from a cron job making it a completely
automated system.  Note that student and parent entered in the first goal will
not receive this email.

    >>> manager.open('http://localhost/schooltool.interventions/notifyGoals.html')
    From: manager@example.com
    To: teacher1@example.com
    Subject: INTERVENTION GOAL DUE: Student1 Student1
    Please follow the link below to update the follow up notes and, if
    appropriate, the goal met status of the intervention goal for Student1 Student1.
    <BLANKLINE>
    http://localhost/schooltool.interventions/2005-2006/student1/goals/1/@@editGoal.html
    From: manager@example.com
    To: teacher1@example.com
    Subject: INTERVENTION GOAL DUE: Student1 Student1
    Please follow the link below to update the follow up notes and, if
    appropriate, the goal met status of the intervention goal for Student1 Student1.
    <BLANKLINE>
    http://localhost/schooltool.interventions/2005-2006/student1/goals/2/@@editGoal.html

    >>> print manager.contents
    <BLANKLINE>
    ...The following goals had notifications sent to the persons responsible:...
    ...Student1 Student1 goal 1...
    ...Student1 Student1 goal 2...

Now that the goals have been marked as notified, calling up the view again will
yield nothing.

    >>> manager.open('http://localhost/schooltool.interventions/notifyGoals.html')
    >>> print manager.contents
    <BLANKLINE>
    ...There are no goals that need notification...


Change of Status Messages
-------------------------

There is a need for special change of status messages that would rarely be
sent and should be organized at the bottom part of the Intervention Center.
The most extreme example of changing a student's status would be to expel
the student from school.  Messages of that nature and less extreme can be
added using the separate 'Change of Status Messages' section of the student's
Intervention Center.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()
    >>> manager.getLink('Student1').click()
    >>> manager.getLink('Intervention Center').click()

    >>> manager.getLink('New Status Message').click()
    >>> manager.getControl(name='person.teacher2').value = False
    >>> manager.getControl(name='person.teacher1').value = True
    >>> manager.getControl(name='field.body').value = 'hello'
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    From: manager@example.com
    To: teacher1@example.com
    Subject: INTERVENTION STATUS CHANGE: Student1 Student1
    SchoolTool Administrator writes:
    <BLANKLINE>
    hello
    >>> print manager.contents
    <BLANKLINE>
    ...Messages and Observations...
    ...Message from SchoolTool Administrator...
    ...Message from SchoolTool Administrator...
    ...New Message...
    ...Change of Status Messages...
    ...Change of Status Message from SchoolTool Administrator...
    ...New Status Message...

Let's make sure we can view the message that we just added.

    >>> manager.getLink('Change of Status Message from SchoolTool Administrator').click()
    >>> print manager.contents
    <BLANKLINE>
    ...Change of Status Message from: SchoolTool Administrator...
    ...To:...
    ...Teacher1 Teacher1...
    ...hello...

There is a view for viewing all change of status messages together as there
is with normal messages.

    >>> manager.getLink('Intervention Center').click()
    >>> manager.getLink('View All Status Messages').click()
    >>> print manager.contents
    <BLANKLINE>
    ...Change of Status Messages regarding Student1 Student1...
    ...Message sent by SchoolTool Administrator...
    ...To:...
    ...Teacher1 Teacher1...
    ...hello...


Section intervention view
-------------------------

The section intervention view gives quick access to various
intervention views for students in the section.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('School Years').click()
    >>> manager.getLink('2005-2006').click()
    >>> manager.getLink('Spring').click()
    >>> manager.getLink('Sections').click()
    >>> manager.getLink('section1').click()
    >>> manager.getLink('Interventions').click()

The Messages tab is the default.  The provided links allow the teacher to
preview existing and compose new messages.  Note that status messages are
ignored when displaying message count for the student.

    >>> print manager.contents
    <BLANKLINE>
    ...course1 - section1's Student Interventions...
    <p>Messages</p> ...
    <a ...Goals</a> ...
    ...Student1 Student1...
    ...View Messages (2)...
    ...Write New...
    ...Student3 Student3...
    ...View Messages (0)...
    ...Write New...

We can add a new message from here by clicking on the 'Write New' link.  We'll
do this for Student3 to help set up dashboard tests.

    >>> manager.getLink('Write New', index=1).click()
    >>> manager.getControl(name='person.teacher1').value = True
    >>> manager.getControl(name='field.body').value = 'Message for Student3'
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    From: manager@example.com
    To: teacher1@example.com
    Subject: INTERVENTION MESSAGE: Student3 Student3
    SchoolTool Administrator writes:
    <BLANKLINE>
    Message for Student3

The Goals tab provides shortcuts to viewing student goals.

    >>> manager.getLink('Goals').click()
    >>> print manager.contents
    <BLANKLINE>
    ...course1 - section1's Student Interventions...
    <a ...Messages</a> ...
    <p>Goals</p> ...
    ...Student1 Student1...
    ...View Goals (2)...
    ...Student3 Student3...
    ...View Goals (0)...


Intervention Dashboard
----------------------

We provide an Intervention tab that takes the user to a kind of dashboard with
two fieldsets.  The first serves as a launch point for the search student
intervention view where the user can find a student to which they have access.
The second fieldset functions similar to an email inbox, listing all messages
and goals that the user is responsible for, most recently created first.

We'll test the Inbox first as it resides on the Intervention tab view itself.

    >>> teacher1 = setup.logIn('teacher1', 'pwd')
    >>> ftests.addAdvisors('Student2', ['teacher1'])

    >>> teacher1.getLink('Intervention').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[2]/div/table/tbody//a", teacher1.contents)
    <a href="http://localhost/persons/student3/schoolyears/2005-2006/messages/1">Message for Student3</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/messages/3">hello</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/goals/2">Rude behavior</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/goals/1">Poor attendence</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/messages/2">hello again</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/messages/1">hi there</a>

There is a name filter that can limit the list to students whose name contains
a search string.

    >>> teacher1.getControl(name='SEARCH_NAME').value = 'student3'
    >>> teacher1.getControl(name='SEARCH_BUTTON').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[2]/div/table/tbody//a", teacher1.contents)
    <a href="http://localhost/persons/student3/schoolyears/2005-2006/messages/1">Message for Student3</a>

Hitting the 'Clear' button clears the filter and returns the original list.

    >>> teacher1.getControl(name='CLEAR_SEARCH').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[2]/div/table/tbody//a", teacher1.contents)
    <a href="http://localhost/persons/student3/schoolyears/2005-2006/messages/1">Message for Student3</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/messages/3">hello</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/goals/2">Rude behavior</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/goals/1">Poor attendence</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/messages/2">hello again</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/messages/1">hi there</a>

There is also a goals only checkbox to filter the list to only student with
goals or only the goals in your inbox.

    >>> teacher1.getControl(name='GOALS_ONLY').value = 'checked'
    >>> teacher1.getControl(name='SEARCH_BUTTON').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[2]/div/table/tbody//a", teacher1.contents)
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/goals/2">Rude behavior</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/goals/1">Poor attendence</a>

Again, hitting the 'Clear' button clears the filter and returns the original list.

    >>> teacher1.getControl(name='CLEAR_SEARCH').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[2]/div/table/tbody//a", teacher1.contents)
    <a href="http://localhost/persons/student3/schoolyears/2005-2006/messages/1">Message for Student3</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/messages/3">hello</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/goals/2">Rude behavior</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/goals/1">Poor attendence</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/messages/2">hello again</a>
    <a href="http://localhost/persons/student1/schoolyears/2005-2006/messages/1">hi there</a>

Now we'll test the lauch point that is the first fieldset.  We'll just hit the 
search student button to see that it takes us to the search student view.  It
lists all the students that the user is responsible for as there was no filter
specified.

    >>> teacher1.getControl(name='SEARCH_STUDENT_BUTTON').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[1]/div/table/tbody//a", teacher1.contents)
    <a href="http://localhost/schooltool.interventions/2005-2006/student1">Student1</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student1">Student1</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student2">Student2</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student2">Student2</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student3">Student3</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student3">Student3</a>

We'll apply the student name filter.

    >>> teacher1.getControl(name='SEARCH_STUDENT_NAME').value = 'student3'
    >>> teacher1.getControl(name='SEARCH_STUDENT_BUTTON').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[1]/div/table/tbody//a", teacher1.contents)
    <a href="http://localhost/schooltool.interventions/2005-2006/student3">Student3</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student3">Student3</a>

We'll clear the student filter and set the goals only filter.

    >>> teacher1.getControl(name='CLEAR_STUDENT_SEARCH').click()
    >>> teacher1.getControl(name='WITH_GOALS_ONLY').value = 'checked'
    >>> teacher1.getControl(name='SEARCH_STUDENT_BUTTON').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[1]/div/table/tbody//a", teacher1.contents)
    <a href="http://localhost/schooltool.interventions/2005-2006/student1">Student1</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student1">Student1</a>

Finally clearing the filter restores the list to the original.

    >>> teacher1.getControl(name='CLEAR_STUDENT_SEARCH').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[1]/div/table/tbody//a", teacher1.contents)
    <a href="http://localhost/schooltool.interventions/2005-2006/student1">Student1</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student1">Student1</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student2">Student2</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student2">Student2</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student3">Student3</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student3">Student3</a>

A final test for the launch point is to show that the filter the user chooses
there gets immediately applied to the search student view, saving the user
a mouse click.

    >>> teacher1.getLink('Intervention').click()
    >>> teacher1.getControl(name='SEARCH_STUDENT_NAME').value = 'student3'
    >>> teacher1.getControl(name='SEARCH_STUDENT_BUTTON').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[1]/div/table/tbody//a", teacher1.contents)
    <a href="http://localhost/schooltool.interventions/2005-2006/student3">Student3</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student3">Student3</a>

    >>> teacher1.getLink('Intervention').click()
    >>> teacher1.getControl(name='WITH_GOALS_ONLY').value = 'checked'
    >>> teacher1.getControl(name='SEARCH_STUDENT_BUTTON').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[1]/div/table/tbody//a", teacher1.contents)
    <a href="http://localhost/schooltool.interventions/2005-2006/student1">Student1</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student1">Student1</a>

If we are to present the user with intervention student links, we have to be
sure that when they vist one of them, it doesn't say Not Found.  That can be
prevented by auto-vivifying the intervention student object before we present
it as a link.  We'll test that each student that we present as a link can be
visited.

    >>> teacher1.getLink('Intervention').click()
    >>> teacher1.getControl(name='SEARCH_STUDENT_BUTTON').click()
    >>> teacher1.getLink('Student1').click()
    >>> teacher1.url
    'http://localhost/schooltool.interventions/2005-2006/student1'

    >>> teacher1.getLink('Intervention').click()
    >>> teacher1.getControl(name='SEARCH_STUDENT_BUTTON').click()
    >>> teacher1.getLink('Student2').click()
    >>> teacher1.url
    'http://localhost/schooltool.interventions/2005-2006/student2'

    >>> teacher1.getLink('Intervention').click()
    >>> teacher1.getControl(name='SEARCH_STUDENT_BUTTON').click()
    >>> teacher1.getLink('Student3').click()
    >>> teacher1.url
    'http://localhost/schooltool.interventions/2005-2006/student3'

We will provide a button for the user to return from the search student view
back to the inbox in case it is not obvious to use the Intervention tab.

    >>> teacher1.getLink('Intervention').click()
    >>> teacher1.getControl(name='SEARCH_STUDENT_BUTTON').click()
    >>> teacher1.getLink('Return to Inbox').click()
    >>> teacher1.url
    'http://localhost/persons/teacher1/intervention_tab'

Users that are in the admin group will see all persons when they search.

    >>> manager.getLink('Intervention').click()
    >>> manager.getControl(name='SEARCH_STUDENT_BUTTON').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[1]/div/table/tbody//a", manager.contents)
    <a href="http://localhost/schooltool.interventions/2005-2006/manager">SchoolTool</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/manager">Administrator</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/counselor">Counselor</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/counselor">Counselor</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/sperson">Search Person</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/sperson">Person Search</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/principal">Principal</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/principal">Principal</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student1">Student1</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student1">Student1</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student2">Student2</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student2">Student2</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student3">Student3</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student3">Student3</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/teacher1">Teacher1</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/teacher1">Teacher1</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/teacher2">Teacher2</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/teacher2">Teacher2</a>

We will show here how usernames can be searched as well.  The only person who's
name is different than the userid is 'sperson', so we'll prove this point using
that person.

    >>> manager.getControl(name='SEARCH_STUDENT_NAME').value = 'sperson'
    >>> manager.getControl(name='SEARCH_STUDENT_BUTTON').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[1]/div/table/tbody//a", manager.contents)
    <a href="http://localhost/schooltool.interventions/2005-2006/sperson">Search Person</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/sperson">Person Search</a>

    >>> manager.getControl(name='SEARCH_STUDENT_NAME').value = 's person'
    >>> manager.getControl(name='SEARCH_STUDENT_BUTTON').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[1]/div/table/tbody//a", manager.contents)

    >>> manager.getControl(name='SEARCH_STUDENT_NAME').value = 'search person'
    >>> manager.getControl(name='SEARCH_STUDENT_BUTTON').click()
    >>> analyze.printQuery("id('content-body')/div/form/fieldset[1]/div/table/tbody//a", manager.contents)
    <a href="http://localhost/schooltool.interventions/2005-2006/sperson">Search Person</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/sperson">Person Search</a>


At One Time Responsible
-----------------------

We have a special case in the user interface for editing goals where one of
the persons_responsible is no longer either a teacher, advisor or administrator
of the student.  The security issues regarding this scenario are tested in
security.txt, but here we need to test the way it is handled in the UI.

First of all, we already have created a goal where teacher1 is responsible.
When we call up the edit view for the goal, we note that teacher1 appears
in the staff section of the person list, not the student section.  We also
note that he is checked.

    >>> manager.open('http://localhost/schooltool.interventions/2005-2006/student1/goals/2/editGoal.html')
    >>> analyze.printQuery('//table//tr[2]//td[1]//span', manager.contents)
    <span>
      <b>Teacher2 Teacher2 (advisor)</b>
    </span>
    <span>
      <b>Counselor Counselor</b>
    </span>
    <span>
      <b>Principal Principal</b>
    </span>
    <span>
      <b>Teacher1 Teacher1</b>
    </span>
    >>> analyze.printQuery('//table//tr[2]//td[1]//input[@type="checkbox"]', manager.contents)
    <input type="checkbox" class="person_list" name="person.teacher2" />
    <input type="checkbox" class="person_list" name="person.counselor" />
    <input type="checkbox" class="person_list" name="person.principal" />
    <input type="checkbox" class="person_list" checked="checked" name="person.teacher1" />
    >>> analyze.printQuery('//table//tr[2]//td[2]//span', manager.contents)
    <span>
      <b>Student1 Student1</b>
    </span>
    <span>
      <b>Parent1 Parent1 (parent)</b>
    </span>
    >>> analyze.printQuery('//table//tr[2]//td[2]//input[@type="checkbox"]', manager.contents)
    <input type="checkbox" name="person.student1" />
    <input type="checkbox" name="person.student1:1" />

We want to remove him from the section that gave him access to the student.

    >>> manager.getLink('2005-2006').click()
    >>> manager.getLink('Spring').click()
    >>> manager.getLink('Sections').click()
    >>> manager.getLink('section1').click()
    >>> manager.getLink('edit instructors').click()
    >>> manager.getControl(name='remove_item.teacher1').value = 'checked'
    >>> manager.getControl('Remove').click()

Now, let's edit the goal and note that there is a new section in the person
list labeled 'Changed Status' and that teacher1 is listed there and is still
checked.

    >>> manager.open('http://localhost/schooltool.interventions/2005-2006/student1/goals/2/editGoal.html')
    >>> analyze.printQuery('//table//tr[2]//td[1]//span', manager.contents)
    <span>
      <b>Teacher2 Teacher2 (advisor)</b>
    </span>
    <span>
      <b>Counselor Counselor</b>
    </span>
    <span>
      <b>Principal Principal</b>
    </span>
    >>> analyze.printQuery('//table//tr[2]//td[1]//input[@type="checkbox"]', manager.contents)
    <input type="checkbox" class="person_list" name="person.teacher2" />
    <input type="checkbox" class="person_list" name="person.counselor" />
    <input type="checkbox" class="person_list" name="person.principal" />
    >>> analyze.printQuery('//table//tr[2]//td[2]//span', manager.contents)
    <span>
      <b>Student1 Student1</b>
    </span>
    <span>
      <b>Parent1 Parent1 (parent)</b>
    </span>
    <span>Changed Status</span>
    <span>
      <b>Teacher1 Teacher1</b>
    </span>
    >>> analyze.printQuery('//table//tr[2]//td[2]//input[@type="checkbox"]', manager.contents)
    <input type="checkbox" name="person.student1" />
    <input type="checkbox" name="person.student1:1" />
    <input type="checkbox" checked="checked" name="person.teacher1" />

We'll go ahead and uncheck him, or course, checking another person in order
to successfully submit.

    >>> manager.getControl(name='person.teacher1').value = False
    >>> manager.getControl(name='person.teacher2').value = True
    >>> manager.getControl('Apply').click()

Now we see that the teacher is still in the 'Changed Status' section but not
checked.  This represents the scenario where the teacher no longer can
add goals for the student, nor can he even view this goal anymore.  However,
we keep him around in the goal.at_one_time_responsible list, and thus, he
will continue to appear in the person list in the special section.  Maybe we'll
want to put him back in the persons_responsible list at a later date.

    >>> manager.open('http://localhost/schooltool.interventions/2005-2006/student1/goals/2/editGoal.html')
    >>> analyze.printQuery('//table//tr[2]//td[1]//span', manager.contents)
    <span>
      <b>Teacher2 Teacher2 (advisor)</b>
    </span>
    <span>
      <b>Counselor Counselor</b>
    </span>
    <span>
      <b>Principal Principal</b>
    </span>
    >>> analyze.printQuery('//table//tr[2]//td[1]//input[@type="checkbox"]', manager.contents)
    <input type="checkbox" class="person_list" checked="checked" name="person.teacher2" />
    <input type="checkbox" class="person_list" name="person.counselor" />
    <input type="checkbox" class="person_list" name="person.principal" />
    >>> analyze.printQuery('//table//tr[2]//td[2]//span', manager.contents)
    <span>
      <b>Student1 Student1</b>
    </span>
    <span>
      <b>Parent1 Parent1 (parent)</b>
    </span>
    <span>Changed Status</span>
    <span>
      <b>Teacher1 Teacher1</b>
    </span>
    >>> analyze.printQuery('//table//tr[2]//td[2]//input[@type="checkbox"]', manager.contents)
    <input type="checkbox" name="person.student1" />
    <input type="checkbox" name="person.student1:1" />
    <input type="checkbox" name="person.teacher1" />

Finally, we'd like to make sure that when we make teacher1 again the teacher
of one of student1's sections, he will appear back in the original section
of the person list.

    >>> manager.getLink('2005-2006').click()
    >>> manager.getLink('Spring').click()
    >>> manager.getLink('Sections').click()
    >>> manager.getLink('section1').click()
    >>> manager.getLink('edit instructors').click()
    >>> manager.getControl(name='add_item.teacher1').value = 'checked'
    >>> manager.getControl('Add').click()

So now when we go back to edit the goal, teacher1 appears back in the original
section, unchecked.  Also, the 'Changed Status' section disappears.  It's like
he was never gone.

    >>> manager.open('http://localhost/schooltool.interventions/2005-2006/student1/goals/2/editGoal.html')
    >>> analyze.printQuery('//table//tr[2]//td[1]//span', manager.contents)
    <span>
      <b>Teacher2 Teacher2 (advisor)</b>
    </span>
    <span>
      <b>Counselor Counselor</b>
    </span>
    <span>
      <b>Principal Principal</b>
    </span>
    <span>
      <b>Teacher1 Teacher1</b>
    </span>
    >>> analyze.printQuery('//table//tr[2]//td[1]//input[@type="checkbox"]', manager.contents)
    <input type="checkbox" class="person_list" checked="checked" name="person.teacher2" />
    <input type="checkbox" class="person_list" name="person.counselor" />
    <input type="checkbox" class="person_list" name="person.principal" />
    <input type="checkbox" class="person_list" name="person.teacher1" />
    >>> analyze.printQuery('//table//tr[2]//td[2]//span', manager.contents)
    <span>
      <b>Student1 Student1</b>
    </span>
    <span>
      <b>Parent1 Parent1 (parent)</b>
    </span>
    >>> analyze.printQuery('//table//tr[2]//td[2]//input[@type="checkbox"]', manager.contents)
    <input type="checkbox" name="person.student1" />
    <input type="checkbox" name="person.student1:1" />


Intervention CSV views
----------------------

We supply CSV views for extracting the messages and goals from a schooltool
instance.

    >>> manager.open('http://localhost/messages.csv')
    >>> print manager.contents
    "year","student","date","sender","recipients","body"
    "2005-2006","student1","...","manager","parent@somewhere.com, teacher1@example.com","hi\nthere"
    "2005-2006","student1","...","manager","teacher1@example.com, teacher2@example.com","hello again"
    "2005-2006","student1","...","manager","teacher1@example.com","hello"
    "2005-2006","student3","...","manager","teacher1@example.com","Message for Student3"

    >>> manager.open('http://localhost/goals.csv')
    >>> print manager.contents
    "year","student","created","creator","presenting_concerns","goal","strengths","indicators","intervention","timeline","persons_responsible","goal_met","follow_up_notes","notified"
    "2005-2006","student1","...","manager","Poor attendence","Get student to come in more often","Good listener","Student appears at least 4 time a week","Call parents to arrange better attendence","...","parent@somewhere.com, student1@example.com, teacher1@example.com","True","","True"
    "2005-2006","student1","...","manager","Rude behavior","Get student to be more polite","Good grades","Student no longer offends classmates","Call parents to alert them to bad manners","...","teacher2@example.com","False","","True"

