External Activities
-------------------

External activities allow to get grades for a worksheet activity from
another schooltool module.

Import helper to print the gradebook:

    >>> from schooltool.gradebook.browser.ftests import printGradebook

Log in as manager:

    >>> manager = Browser('manager', 'schooltool')

Now, set up a school year (2005-2006) with two terms (Fall and
Spring):

    >>> from schooltool.app.browser.ftests import setup
    >>> setup.setUpBasicSchool()

Set up one course:

    >>> setup.addCourse('Physics I', '2005-2006')

Set up persons:

    >>> from schooltool.basicperson.browser.ftests.setup import addPerson
    >>> addPerson('Paul', 'Cardune', 'paul', 'pwd', browser=manager)
    >>> addPerson('Tom', 'Hoffman', 'tom', 'pwd', browser=manager)
    >>> addPerson('Claudia', 'Richter', 'claudia', 'pwd', browser=manager)
    >>> addPerson('Stephan', 'Richter', 'stephan', 'pwd', browser=manager)

Set up a section with instructor and students for the Fall:

    >>> setup.addSection('Physics I', '2005-2006', 'Fall',
    ...                  instructors=['Stephan'],
    ...                  members=['Tom', 'Claudia', 'Paul'])

Log in as teacher:

    >>> stephan = Browser('stephan', 'pwd')

Add a couple of activities to the default worksheet:

    >>> stephan.getLink('Gradebook').click()
    >>> stephan.getLink('New Activity').click()
    >>> stephan.getControl('Title').value = 'HW 1'
    >>> stephan.getControl('Description').value = 'Homework 1'
    >>> stephan.getControl('Category').displayValue = ['Assignment']
    >>> stephan.getControl('Maximum').value = '50'
    >>> stephan.getControl('Add').click()

    >>> stephan.getLink('New Activity').click()
    >>> stephan.getControl('Title').value = 'Quiz'
    >>> stephan.getControl('Description').value = 'Week 1 Pop Quiz'
    >>> stephan.getControl('Category').displayValue = ['Exam']
    >>> stephan.getControl('Add').click()

Add some grades:

    >>> stephan.getControl(name='Activity_paul').value = '40'
    >>> stephan.getControl(name='Activity_tom').value = '48'
    >>> stephan.getControl(name='Activity_claudia').value = '45'

    >>> stephan.getControl(name='Activity-2_paul').value = '90'
    >>> stephan.getControl(name='Activity-2_tom').value = '88'
    >>> stephan.getControl(name='Activity-2_claudia').value = '29'

    >>> stephan.getControl('Save').click()

We have two regular activities. One assignment:

    >>> stephan.getLink('Manage Worksheet').click()
    >>> stephan.getLink('HW 1').click()
    >>> stephan.getControl('Category').displayValue
    ['Assignment']
    >>> stephan.getControl('Cancel').click()

And one exam:

    >>> stephan.getLink('Quiz').click()
    >>> stephan.getControl('Category').displayValue
    ['Exam']
    >>> stephan.getControl('Cancel').click()

And our grades are:

    >>> stephan.getLink('Return to Gradebook').click()
    >>> printGradebook(stephan.contents)
    +----------+
    | *Sheet1* |
    +----------+
    +------------------+-------+-------+---------+---------+
    | Name             | Total | Ave.  | HW1     | Quiz    |
    +------------------+-------+-------+---------+---------+
    | Cardune, Paul    | 130.0 | 86.7% | [40___] | [90___] |
    | Hoffman, Tom     | 136.0 | 90.7% | [48___] | [88___] |
    | Richter, Claudia | 74.0  | 49.3% | [45___] | [29___] |
    +------------------+-------+-------+---------+---------+

We should have a 'New External Activity' button to add external
activities:

    >>> stephan.printQuery('id("content-nav-group")/div/a/text()')
    Worksheets
    New Activity
    New External Activity
    New Linked Column
    Manage Worksheet
    Weight Categories
    Preferences
    Export XLS
    Download PDF

Let's add a new external activity as an assignment. For this test we
have registered two external utilities stubs titled "Hardware" and
"HTML" (see schooltool.gradebook.tests.stubs). We'll also test the
Cancel button in that form:

    >>> stephan.getLink('New External Activity').click()
    >>> stephan.printQuery('//h3/text()')
    Add an External Activity
    >>> stephan.printQuery('id("form-widgets-external_activity")/option[@value!=""]/text()')
    Sample Source - HTML
    Sample Source - Hardware
    >>> stephan.getControl('Cancel').click()

    >>> stephan.getLink('New External Activity').click()
    >>> stephan.printQuery('//h3/text()')
    Add an External Activity
    >>> stephan.getControl('External Activity').displayValue = ['Sample Source - Hardware']
    >>> stephan.getControl('Category').displayValue = ['Assignment']
    >>> stephan.getControl('Points').value = '15'
    >>> stephan.getControl('Add').click()

Adding an external activity gets us back to the gradebook where we can see
the external activity which has been loaded with the latest grades, but cannot
be scored:

    >>> stephan.url
    'http://localhost/schoolyears/2005-2006/fall/sections/1/activities/Worksheet/gradebook'
    >>> printGradebook(stephan.contents)
    +----------+
    | *Sheet1* |
    +----------+
    +------------------+-------+-------+---------+---------+-------+
    | Name             | Total | Ave.  | HW1     | Quiz    | Hardw |
    +------------------+-------+-------+---------+---------+-------+
    | Cardune, Paul    | 130.0 | 86.7% | [40___] | [90___] |       |
    | Hoffman, Tom     | 145.0 | 87.9% | [48___] | [88___] | 9.00  |
    | Richter, Claudia | 80.0  | 48.5% | [45___] | [29___] | 6.00  |
    +------------------+-------+-------+---------+---------+-------+

Let's edit the external activity. The form doesn't allow to edit the
score system. The edit view also shows an 'Update Grades' button to
recalculate the activity grades from the external activity. We'll also
test the Cancel button in that form:

    >>> stephan.getLink('Manage Worksheet').click()
    >>> stephan.getLink('Hardware').click()
    >>> stephan.printQuery('//h3/text()')
    Edit External Activity
    >>> stephan.printQuery('id("content-nav-group")/div/a/text()')
    Edit
    Update Grades
    >>> stephan.printQuery('//label/span[1]/text()')
    External Activity
    Title
    Label
    Due Date
    Description
    Category
    Points
    >>> stephan.printQuery('id("form-widgets-external_activity")/span/text()')
    Sample Source - Hardware
    >>> stephan.printQuery('id("form-widgets-title")/@value')
    Hardware
    >>> stephan.printQuery('id("form-widgets-description")/text()')
    Hardware description
    >>> stephan.printQuery('id("form-widgets-category")/option[@selected="selected"]/text()')
    Assignment
    >>> stephan.printQuery('id("form-widgets-points")/@value')
    15
    >>> stephan.getControl('Cancel').click()

    >>> stephan.getLink('Manage Worksheet').click()
    >>> stephan.getLink('Hardware').click()
    >>> stephan.printQuery('//h3/text()')
    Edit External Activity
    >>> stephan.getControl('Title').value = u"Hardware Assignment"
    >>> stephan.getControl('Description').value = "The Hardware assignment"
    >>> stephan.getControl('Points').value = '25'
    >>> stephan.getControl('Apply').click()

Since we changed the points of the external activity, we see a change
in the average column. But the grades for the external activity have
not been updated:

    >>> stephan.url
    'http://localhost/schoolyears/2005-2006/fall/sections/1/activities/Worksheet/gradebook'
    >>> printGradebook(stephan.contents)
    +----------+
    | *Sheet1* |
    +----------+
    +------------------+-------+-------+---------+---------+-------+
    | Name             | Total | Ave.  | HW1     | Quiz    | Hardw |
    +------------------+-------+-------+---------+---------+-------+
    | Cardune, Paul    | 130.0 | 86.7% | [40___] | [90___] |       |
    | Hoffman, Tom     | 145.0 | 82.9% | [48___] | [88___] | 9.00  |
    | Richter, Claudia | 80.0  | 45.7% | [45___] | [29___] | 6.00  |
    +------------------+-------+-------+---------+---------+-------+

Let's go back to the edit form of the external activity to update the
grades using the 'Update Grades' button:

    >>> stephan.getLink('Manage Worksheet').click()
    >>> stephan.getLink('Hardware Assignment').click()
    >>> stephan.getLink('Update Grades').click()

This takes us to the gradebook where the grades of the external
activity, the total of points and the averages should have changed:

    >>> stephan.url
    'http://localhost/schoolyears/2005-2006/fall/sections/1/activities/Worksheet/gradebook'
    >>> printGradebook(stephan.contents)
    +----------+
    | *Sheet1* |
    +----------+
    +------------------+-------+-------+---------+---------+-------+
    | Name             | Total | Ave.  | HW1     | Quiz    | Hardw |
    +------------------+-------+-------+---------+---------+-------+
    | Cardune, Paul    | 130.0 | 86.7% | [40___] | [90___] |       |
    | Hoffman, Tom     | 151.0 | 86.3% | [48___] | [88___] | 15.00 |
    | Richter, Claudia | 84.0  | 48.0% | [45___] | [29___] | 10.00 |
    +------------------+-------+-------+---------+---------+-------+

External activities should also be weightable. Let's add some
weighting to the worksheet:

    >>> stephan.getLink('Weight Categories').click()
    >>> stephan.getControl('Assignment').value = '31'
    >>> stephan.getControl('Exam').value = '69'
    >>> stephan.getControl('Update').click()

The averages have changed to reflect the weighting:

    >>> stephan.url
    'http://localhost/schoolyears/2005-2006/fall/sections/1/activities/Worksheet/gradebook'
    >>> printGradebook(stephan.contents)
    +----------+
    | *Sheet1* |
    +----------+
    +------------------+-------+-------+---------+---------+-------+
    | Name             | Total | Ave.  | HW1     | Quiz    | Hardw |
    +------------------+-------+-------+---------+---------+-------+
    | Cardune, Paul    | 130.0 | 86.9% | [40___] | [90___] |       |
    | Hoffman, Tom     | 151.0 | 86.8% | [48___] | [88___] | 15.00 |
    | Richter, Claudia | 84.0  | 42.7% | [45___] | [29___] | 10.00 |
    +------------------+-------+-------+---------+---------+-------+
