============
Report Cards
============

The end goal of having users enter grades is for parents to receive a
report card from the school after each grading period has ended.  To facilitate
this, the admin user will set up report sheet templates at the application
level, then choose on to deploy to a given term.  This deployment will
result in a special worksheet being inserted into every section for that
term so that the teachers can enter the final grades of the grading period.
Finally, the admin user will be able to request report cards to be printed
after each gradding period has ended.

Let's start by setting up the application and logging in as manager.

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

If at this point, when we have no report sheets yet, we go to a term
and try to deploy one, we should get an error:

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('2005-2006').click()
    >>> manager.getLink('Fall').click()
    >>> manager.getLink('Deploy Report Sheet').click()
    >>> manager.printQuery('//h1/text()')
    The operation you attempted cannot be completed because there are
    currently no report sheets set up in your SchoolTool
    instance. Please have a user with administration access set up at
    least one report sheet and try the operation again.

The same should happen if we try to deploy from a school year:

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('2005-2006').click()
    >>> manager.getLink('Deploy Report Sheet').click()
    >>> manager.printQuery('//h1/text()')
    The operation you attempted cannot be completed because there are
    currently no report sheets set up in your SchoolTool
    instance. Please have a user with administration access set up at
    least one report sheet and try the operation again.

So, let's set up the report sheet templates.  This is done from the
Manage tab.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Report Sheet Templates').click()

We see that there are no report worksheets yet.

    >>> manager.printQuery('id("content-body")//a')

We'll add one.

    >>> manager.getLink('New Report Sheet').click()
    >>> manager.getControl('Title').value = 'Test1'
    >>> manager.getControl('Add').click()

Now we see that the new report worksheet appears in the list.

    >>> manager.printQuery('id("content-body")//a')
    <a href="http://localhost/schooltool.gradebook/templates/ReportWorksheet">Test1</a>

We'll click on it to view its activities.  We see that there are none.

    >>> manager.getLink('Test1').click()
    >>> manager.printQuery('id("content-body")//a')

To add a report activity to it, we'll click on the supplied link.

    >>> manager.getLink('New Report Activity').click()
    >>> manager.getControl('Title').value = 'Activity 1'
    >>> manager.getControl('Score System').displayValue = ['100 Points']
    >>> manager.getControl('Add').click()

Now we see that the new report activity appears in the list.

    >>> manager.printQuery('id("content-body")//a')
    <a href="http://localhost/schooltool.gradebook/templates/ReportWorksheet/ReportActivity">Activity 1</a>

Next, we'll click on the newly added activity link to edit its score system.
We see that it is currently set to the 100 points score system we selected
when we added it.

    >>> manager.getLink('Activity 1').click()
    >>> manager.getControl('Score System').value
    ['100 Points-']

We'll change it, apply the change, and revisit the activity to see that the
change took.

    >>> manager.getControl('Score System').value = ['letter-grade-']
    >>> manager.getControl('Apply').click()
    >>> manager.getLink('Activity 1').click()
    >>> manager.getControl('Score System').value
    ['letter-grade-']

Now we'll change it to use a dynamically generated ranged values score system.
The min and max fields don't need to be filled in as they defualt to 0 and 100.

    >>> manager.getControl('Score System').displayValue = ['-- Use range below --']
    >>> manager.getControl('Apply').click()
    >>> manager.getLink('Activity 1').click()
    >>> manager.getControl('Score System').value
    ['ranged']
    >>> manager.getControl('Minimum').value
    '0'
    >>> manager.getControl('Maximum').value
    '100'

Next we'll simply change the ranges and verify.

    >>> manager.getControl('Minimum').value = '1'
    >>> manager.getControl('Maximum').value = '5'
    >>> manager.getControl('Apply').click()
    >>> manager.getLink('Activity 1').click()
    >>> manager.getControl('Score System').value
    ['ranged']
    >>> manager.getControl('Minimum').value
    '1'
    >>> manager.getControl('Maximum').value
    '5'

Finally, we'll make sure we can change it back to an existing score system.
We'll note that, in doing so, the min and max fields are cleared out.  They
are only relavent when '-- Use range below --' is chosen as the score system.

    >>> manager.getControl('Score System').displayValue = ['100 Points']
    >>> manager.getControl('Apply').click()
    >>> manager.getLink('Activity 1').click()
    >>> manager.getControl('Score System').value
    ['100 Points-']
    >>> manager.getControl('Minimum').value
    ''
    >>> manager.getControl('Maximum').value
    ''

Later we will want to test the handling of deployment of multiple templates
to a term, so here we'll set up a second template.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Report Sheet Templates').click()
    >>> manager.getLink('New Report Sheet').click()
    >>> manager.getControl('Title').value = 'Test2'
    >>> manager.getControl('Add').click()
    >>> manager.getLink('Test2').click()
    >>> manager.getLink('New Report Activity').click()
    >>> manager.getControl('Title').value = 'Activity 2'
    >>> manager.getControl('Add').click()


Report Worksheet Deployment
---------------------------

Now that we've set up report sheet templates, we want to choose one of them
to deploy to all sections in a given term.  We'll need to set up one of our
terms with some sections.  Of course, we'll need a teacher and some students
in order to do that.

    >>> from schooltool.basicperson.browser.ftests.setup import addPerson
    >>> addPerson('Teacher1', 'One', 'teacher1', 'pwd')
    >>> addPerson('Student1', 'One', 'student1', 'pwd')
    >>> addPerson('Student2', 'Two', 'student2', 'pwd')
    >>> setup.addCourse('CompSci I', '2005-2006')
    >>> setup.addSection('CompSci I', '2005-2006', 'Spring',
    ...                  title='Morning CompSci I',
    ...                  instructors=['Teacher1'],
    ...                  members=['Student1','Student2'])
    >>> setup.addSection('CompSci I', '2005-2006', 'Spring',
    ...                  title='Afternoon CompSci I',
    ...                  instructors=['Teacher1'],
    ...                  members=['Student1','Student2'])

We'll navigate to the 'Spring' term where we just created the two sections,
and we'll click on the 'Deploy Report Sheet' link.

    >>> manager.getLink('2005-2006').click()
    >>> manager.getLink('Spring').click()
    >>> manager.printQuery('//h1/text()')
    Spring
    >>> manager.getLink('Deploy Report Sheet').click()

Hitting the 'Cancel' button brings us back to the term view.

    >>> manager.getControl('Cancel').click()
    >>> manager.printQuery('//h1/text()')
    Spring

Now we'll go back to the view and this time hit the 'Deploy' button.  This will
also bring us back to the term view.  First we'll deploy the first template,
then the second.

    >>> manager.getLink('Deploy Report Sheet').click()
    >>> manager.getControl('Template').displayValue = ['Test1']
    >>> manager.getControl('Deploy').click()
    >>> manager.printQuery('//h1/text()')
    Spring
    >>> manager.getLink('Deploy Report Sheet').click()
    >>> manager.getControl('Template').displayValue = ['Test2']
    >>> manager.getControl('Deploy').click()

To make sure the deployment worked, we'll navigate to each section and make sure
the worksheets and activities are there.  We'll start with the first section.
In addition to testing for the presence of the worksheets and activities, we'll
make sure that there is no checkbox available to delete any of them.  Also,
the activities will be spans instead of links so that they can't be edited.

    >>> manager.getLink('Sections').click()
    >>> manager.getLink('Morning CompSci I').click()
    >>> manager.getLink('Gradebook', index=1).click()
    >>> manager.getLink('Worksheets').click()

    >>> manager.printQuery('id("content-body")//a')
    <a href="http://localhost/schoolyears/2005-2006/spring/sections/1/activities/2005-2006_spring/manage.html">Test1</a>
    <a href="http://localhost/schoolyears/2005-2006/spring/sections/1/activities/2005-2006_spring-2/manage.html">Test2</a>

    >>> manager.getLink('Test1').click()
    >>> manager.printQuery('id("content-body")//span')
    <span>Activity 1</span>

    >>> 'checkbox' not in manager.queryHTML('id("content-body")')[0]
    True

    >>> '<a>' not in manager.queryHTML('id("content-body")')[0]
    True

    >>> manager.getLink('Worksheets').click()
    >>> manager.getLink('Test2').click()
    >>> manager.printQuery('id("content-body")//span')
    <span>Activity 2</span>

    >>> 'checkbox' not in manager.queryHTML('id("content-body")')[0]
    True

    >>> '<a>' not in manager.queryHTML('id("content-body")')[0]
    True

The other section should also have the same worksheet deployed.

    >>> manager.getLink('2005-2006').click()
    >>> manager.getLink('Spring').click()
    >>> manager.getLink('Sections').click()
    >>> manager.getLink('Afternoon CompSci I').click()
    >>> manager.getLink('Gradebook', index=1).click()
    >>> manager.getLink('Worksheets').click()

    >>> manager.printQuery('id("content-body")//a')
    <a href="http://localhost/schoolyears/2005-2006/spring/sections/2/activities/2005-2006_spring/manage.html">Test1</a>
    <a href="http://localhost/schoolyears/2005-2006/spring/sections/2/activities/2005-2006_spring-2/manage.html">Test2</a>

    >>> manager.getLink('Test1').click()
    >>> manager.printQuery('id("content-body")//span')
    <span>Activity 1</span>

    >>> 'checkbox' not in manager.queryHTML('id("content-body")')[0]
    True

    >>> '<a>' not in manager.queryHTML('id("content-body")')[0]
    True

    >>> manager.getLink('Worksheets').click()
    >>> manager.getLink('Test2').click()
    >>> manager.printQuery('id("content-body")//span')
    <span>Activity 2</span>

    >>> 'checkbox' not in manager.queryHTML('id("content-body")')[0]
    True

    >>> '<a>' not in manager.queryHTML('id("content-body")')[0]
    True

For data integrity's sake, we have to have a subscriber to a new section event
to automatically add the same worksheets to it that are already deployed to the
other sections.  We'll add a third section to test this.

    >>> setup.addSection('CompSci I', '2005-2006', 'Spring',
    ...                  title='Evening CompSci I',
    ...                  instructors=['Teacher1'],
    ...                  members=['Student1','Student2'])

    >>> manager.getLink('2005-2006').click()
    >>> manager.getLink('Spring').click()
    >>> manager.getLink('Sections').click()
    >>> manager.getLink('Evening CompSci I').click()
    >>> manager.getLink('Gradebook', index=1).click()
    >>> manager.getLink('Worksheets').click()

    >>> manager.printQuery('id("content-body")//a')
    <a href="http://localhost/schoolyears/2005-2006/spring/sections/3/activities/2005-2006_spring/manage.html">Test1</a>
    <a href="http://localhost/schoolyears/2005-2006/spring/sections/3/activities/2005-2006_spring-2/manage.html">Test2</a>

    >>> manager.getLink('Test1').click()
    >>> manager.printQuery('id("content-body")//span')
    <span>Activity 1</span>

    >>> manager.getLink('Worksheets').click()
    >>> manager.getLink('Test2').click()
    >>> manager.printQuery('id("content-body")//span')
    <span>Activity 2</span>


Report Card Layout
------------------

Now that we have some templates deployed, we can move on to setting up the
layout of the report cards that will be printed after each marking period.
The layout view supports setting up which activities appear in the grid
and which appear in the outline portion of the report card.

Typically, at the end of each marking period, an admin user will request
a run of the report cards for the student body.  The result of that run will
come from the grid columns and outline activities that are set up in the
layout and the existence of grades for those activities entered by the
teachers.

We will need to set up at least one section in the Fall term and deploy yet a
third template to it.

    >>> setup.addSection('CompSci I', '2005-2006', 'Fall',
    ...                  title='Evening CompSci I',
    ...                  instructors=['Teacher1'],
    ...                  members=['Student1','Student2'])

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Report Sheet Templates').click()
    >>> manager.getLink('New Report Sheet').click()
    >>> manager.getControl('Title').value = 'Test3'
    >>> manager.getControl('Add').click()
    >>> manager.getLink('Test3').click()
    >>> manager.getLink('New Report Activity').click()
    >>> manager.getControl('Title').value = 'Activity 3'
    >>> manager.getControl('Add').click()

    >>> manager.getLink('2005-2006').click()
    >>> manager.getLink('Fall').click()
    >>> manager.printQuery('//h1/text()')
    Fall
    >>> manager.getLink('Deploy Report Sheet').click()
    >>> manager.getControl('Template').displayValue = ['Test3']
    >>> manager.getControl('Deploy').click()

Now the choices for our columns will be selectable over (term, worksheet,
activity).  Lets call up the column layout view and inspect the choices
we have.

    >>> manager.getLink('2005-2006').click()
    >>> manager.getLink('Report Card Layout').click()

The view starts off with no columns set up.  The 'New Column' select control is
the only list box present.

    >>> manager.printQuery("id('content-body')/form/fieldset[1]//table//tr[2]/td[2]//option")
    <option selected="selected" value="">Choose a column to add</option>
    <option value="fall|2005-2006_fall|ReportActivity">Fall - Test3 - Activity 3</option>
    <option value="spring|2005-2006_spring|ReportActivity">Spring - Test1 - Activity 1</option>
    <option value="spring|2005-2006_spring-2|ReportActivity">Spring - Test2 - Activity 2</option>
    <option value="absent">Absent</option>
    <option value="tardy">Tardy</option>

We'll add a first column to the layout.

    >>> manager.getControl('New Column').displayValue = ['Fall - Test3 - Activity 3']
    >>> manager.getControl(name='ADD_COLUMN').click()

Now the view has the first column and the select control below it to add
another column.

    >>> manager.printQuery("id('content-body')/form/fieldset[1]//table//tr[2]/td[2]//option")
    <option selected="selected" value="fall|2005-2006_fall|ReportActivity">Fall - Test3 - Activity 3</option>
    <option value="spring|2005-2006_spring|ReportActivity">Spring - Test1 - Activity 1</option>
    <option value="spring|2005-2006_spring-2|ReportActivity">Spring - Test2 - Activity 2</option>
    <option value="absent">Absent</option>
    <option value="tardy">Tardy</option>

    >>> manager.printQuery("id('content-body')/form/fieldset[1]//table//tr[3]/td[2]//option")
    <option selected="selected" value="">Choose a column to add</option>
    <option value="fall|2005-2006_fall|ReportActivity">Fall - Test3 - Activity 3</option>
    <option value="spring|2005-2006_spring|ReportActivity">Spring - Test1 - Activity 1</option>
    <option value="spring|2005-2006_spring-2|ReportActivity">Spring - Test2 - Activity 2</option>
    <option value="absent">Absent</option>
    <option value="tardy">Tardy</option>

We can change the first column to another activity.  We'll see that the change
has taken effect.

    >>> manager.getControl('Column1').displayValue = ['Spring - Test1 - Activity 1']
    >>> manager.getControl('OK').click()
    >>> manager.getLink('Report Card Layout').click()

    >>> manager.printQuery("id('content-body')/form/fieldset[1]//table//tr[2]/td[2]//option")
    <option value="fall|2005-2006_fall|ReportActivity">Fall - Test3 - Activity 3</option>
    <option selected="selected" value="spring|2005-2006_spring|ReportActivity">Spring - Test1 - Activity 1</option>
    <option value="spring|2005-2006_spring-2|ReportActivity">Spring - Test2 - Activity 2</option>
    <option value="absent">Absent</option>
    <option value="tardy">Tardy</option>

    >>> manager.printQuery("id('content-body')/form/fieldset[1]//table//tr[3]/td[2]//option")
    <option selected="selected" value="">Choose a column to add</option>
    <option value="fall|2005-2006_fall|ReportActivity">Fall - Test3 - Activity 3</option>
    <option value="spring|2005-2006_spring|ReportActivity">Spring - Test1 - Activity 1</option>
    <option value="spring|2005-2006_spring-2|ReportActivity">Spring - Test2 - Activity 2</option>
    <option value="absent">Absent</option>
    <option value="tardy">Tardy</option>

If we want, we can delete the column.  We'll see that the view no longer has
any columns.

    >>> manager.getControl(name='delete_Column1').click()

    >>> manager.printQuery("id('content-body')/form/fieldset[1]//table//tr[2]/td[2]//option")
    <option selected="selected" value="">Choose a column to add</option>
    <option value="fall|2005-2006_fall|ReportActivity">Fall - Test3 - Activity 3</option>
    <option value="spring|2005-2006_spring|ReportActivity">Spring - Test1 - Activity 1</option>
    <option value="spring|2005-2006_spring-2|ReportActivity">Spring - Test2 - Activity 2</option>
    <option value="absent">Absent</option>
    <option value="tardy">Tardy</option>

Next, we'll repeat the same set of tests for the outline activities.  For
starters, we see only choices for outline activities to add.

    >>> manager.printQuery("id('content-body')/form/fieldset[2]//table//tr[2]/td[2]//option")
    <option selected="selected" value="">Choose an activity to add</option>
    <option value="fall|2005-2006_fall|ReportActivity">Fall - Test3 - Activity 3</option>
    <option value="spring|2005-2006_spring|ReportActivity">Spring - Test1 - Activity 1</option>
    <option value="spring|2005-2006_spring-2|ReportActivity">Spring - Test2 - Activity 2</option>

We'll add a first activity to the layout.

    >>> manager.getControl('New Activity').displayValue = ['Fall - Test3 - Activity 3']
    >>> manager.getControl(name='ADD_ACTIVITY').click()

Now the view has the first activity and the select control below it to add
another activity.

    >>> manager.printQuery("id('content-body')/form/fieldset[2]//table//tr[2]/td[2]//option")
    <option selected="selected" value="fall|2005-2006_fall|ReportActivity">Fall - Test3 - Activity 3</option>
    <option value="spring|2005-2006_spring|ReportActivity">Spring - Test1 - Activity 1</option>
    <option value="spring|2005-2006_spring-2|ReportActivity">Spring - Test2 - Activity 2</option>

    >>> manager.printQuery("id('content-body')/form/fieldset[2]//table//tr[3]/td[2]//option")
    <option selected="selected" value="">Choose an activity to add</option>
    <option value="fall|2005-2006_fall|ReportActivity">Fall - Test3 - Activity 3</option>
    <option value="spring|2005-2006_spring|ReportActivity">Spring - Test1 - Activity 1</option>
    <option value="spring|2005-2006_spring-2|ReportActivity">Spring - Test2 - Activity 2</option>

We can change the first activity to another activity.  We'll see that the change
has taken effect.

    >>> manager.getControl('Activity1').displayValue = ['Spring - Test1 - Activity 1']
    >>> manager.getControl('OK').click()
    >>> manager.getLink('Report Card Layout').click()

    >>> manager.printQuery("id('content-body')/form/fieldset[2]//table//tr[2]/td[2]//option")
    <option value="fall|2005-2006_fall|ReportActivity">Fall - Test3 - Activity 3</option>
    <option selected="selected" value="spring|2005-2006_spring|ReportActivity">Spring - Test1 - Activity 1</option>
    <option value="spring|2005-2006_spring-2|ReportActivity">Spring - Test2 - Activity 2</option>

    >>> manager.printQuery("id('content-body')/form/fieldset[2]//table//tr[3]/td[2]//option")
    <option selected="selected" value="">Choose an activity to add</option>
    <option value="fall|2005-2006_fall|ReportActivity">Fall - Test3 - Activity 3</option>
    <option value="spring|2005-2006_spring|ReportActivity">Spring - Test1 - Activity 1</option>
    <option value="spring|2005-2006_spring-2|ReportActivity">Spring - Test2 - Activity 2</option>

If we want, we can delete the activity.  We'll see that the view no longer has
any activities.

    >>> manager.getControl(name='delete_Activity1').click()

    >>> manager.printQuery("id('content-body')/form/fieldset[2]//table//tr[2]/td[2]//option")
    <option selected="selected" value="">Choose an activity to add</option>
    <option value="fall|2005-2006_fall|ReportActivity">Fall - Test3 - Activity 3</option>
    <option value="spring|2005-2006_spring|ReportActivity">Spring - Test1 - Activity 1</option>
    <option value="spring|2005-2006_spring-2|ReportActivity">Spring - Test2 - Activity 2</option>

Now, let's delete a report activity:

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Report Sheet Templates').click()
    >>> manager.getLink('Test1').click()
    >>> manager.queryHTML('//form/div[not(@class="controls")]/a/text()')
    ['Activity 1']
    >>> manager.getControl(name='delete:list').value = ['ReportActivity']
    >>> manager.getControl('Delete').click()
    >>> manager.queryHTML('//form/div[not(@class="controls")]/a/text()')
    []
