Basic Person
============

A manager logs in

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

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

Create a Basic Person, a teacher.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()
    >>> manager.getLink('New Person').click()
    >>> manager.getControl('First name').value = "John"
    >>> manager.getControl('Last name').value = "Petterson"
    >>> manager.getControl('Gender').value = ['male']
    >>> manager.getControl('Birth date').value = '1980-01-01'
    >>> manager.getControl('Username').value = "john"
    >>> manager.getControl('Password').value = "pwd"
    >>> manager.getControl('Confirm').value = "pwd"
    >>> manager.getControl('Add').click()

    >>> manager.getLink('edit groups').click()
    >>> manager.getControl('Teachers').click()
    >>> manager.getControl('Add').click()

Go to the person list:

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()

Both of our users are in there:

    >>> manager.getLink('John')
    <Link text='John' url='http://localhost/persons/john'>

    >>> manager.getLink('Administrator', index=1)
    <Link text='Administrator' url='http://localhost/persons/manager'>

You can filter the list:

    >>> manager.getControl(name='SEARCH_TITLE').value = "John"
    >>> manager.getControl('Find Now').click()

And now we only have John in there:

    >>> manager.getLink('John')
    <Link text='John' url='http://localhost/persons/john'>

    >>> manager.getLink('Administrator', index=1)
    Traceback (most recent call last):
    ...
    LinkNotFoundError

We can click on John and edit his record (we'll change it back as well):

    >>> manager.getLink('John').click()
    >>> manager.getLink('Edit').click()
    >>> manager.getControl('First name').value = 'Johnny'
    >>> manager.getControl('Apply').click()
    >>> manager.getControl('First name').value = 'John'
    >>> manager.getControl('Apply').click()

Now there even are person export views:

    >>> manager.open('http://localhost/persons/@@person_export.xml')
    >>> print manager.contents
    <person_export xmlns:basic="http://schooltool.org/ns/model/0.1/basicperson"
                   xmlns="http://schooltool.org/ns/model/0.1">
      <groups>
        <group>
          <id>teachers</id>
          <title>Teachers</title>
          <description>Teachers.</description>
        </group>
      </groups>
      <persons>
        <person>
          <username>john</username>
          <title>Petterson, John</title>
          <basic:first_name>John</basic:first_name>
          <basic:last_name>Petterson</basic:last_name>
          <basic:gender>male</basic:gender>
          <basic:birth_date>1980-01-01</basic:birth_date>
          <groups>
            <group id="teachers" />
          </groups>
        </person>
        <person>
          <username>manager</username>
          <title>Administrator, SchoolTool</title>
          <basic:first_name>SchoolTool</basic:first_name>
          <basic:last_name>Administrator</basic:last_name>
        </person>
      </persons>
    </person_export>

    >>> manager.open('http://localhost/persons/john/@@person_export.xml')
    >>> print manager.contents
    <person_export xmlns:basic="http://schooltool.org/ns/model/0.1/basicperson"
                   xmlns="http://schooltool.org/ns/model/0.1">
      <groups>
        <group>
          <id>teachers</id>
          <title>Teachers</title>
          <description>Teachers.</description>
        </group>
      </groups>
      <persons>
        <person>
          <username>john</username>
          <title>Petterson, John</title>
          <basic:first_name>John</basic:first_name>
          <basic:last_name>Petterson</basic:last_name>
          <basic:gender>male</basic:gender>
          <basic:birth_date>1980-01-01</basic:birth_date>
          <groups>
            <group id="teachers" />
          </groups>
        </person>
      </persons>
    </person_export>

Now let's create another teacher, Bob.

    >>> manager.open('http://localhost/')
    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()
    >>> manager.getLink('New Person').click()
    >>> manager.getControl('First name').value = "Bob"
    >>> manager.getControl('Last name').value = "Roberts"
    >>> manager.getControl('Gender').value = ['male']
    >>> manager.getControl('Birth date').value = '1980-01-01'

    >>> manager.getControl('Username').value = "bob"
    >>> manager.getControl('Password').value = "pwd"
    >>> manager.getControl('Confirm').value = "pwd"
    >>> manager.getControl('Add').click()
    >>> manager.getLink('edit groups').click()
    >>> manager.getControl('Teachers').click()
    >>> manager.getControl('Add').click()
    >>> # quick css check for the neutral buttons
    >>> manager.printQuery('//input[@value="Invert Selection" or @value="OK"]/@class')
    button-neutral
    button-neutral
    button-neutral

Now, when we create a student, we will have two persons available to
choose as an advisor.  We will choose John.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()
    >>> manager.getLink('New Person').click()
    >>> manager.getControl('First name').value = "Student"
    >>> manager.getControl('Last name').value = "One"
    >>> manager.getControl('Gender').value = ['male']
    >>> manager.getControl('Birth date').value = '1980-01-01'

    >>> manager.getControl('Username').value = "student"
    >>> manager.getControl('Password').value = "pwd"
    >>> manager.getControl('Confirm').value = "pwd"
    >>> manager.getControl('Add').click()

By the way - CVS import views should still be working even when we are
using this kind of person:

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()
    >>> manager.getLink('Import Persons').click()
    >>> csvtext = "jjones, Jimmy, Jones\njbjones, Jim Bob, Jones, r2m45J\n,Howard,Jobs"
    >>> manager.getControl(name='csvtext').value = csvtext
    >>> manager.getControl(name='charset').value = ['UTF-8']
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    >>> analyze.printQuery("//div[@class='error']", manager.contents)
    <div class="error">Failed to import CSV text</div>
    <div class="error">username may not be empty</div>
    >>> analyze.printQuery("id('csvtext')", manager.contents)
    <textarea name="csvtext" id="csvtext" cols="50" rows="10">jjones, Jimmy, Jones
      jbjones, Jim Bob, Jones, r2m45J
      ,Howard,Jobs</textarea>
    >>> csvtext = "@@index.html, Steve, Smith, secret\npete, Pete, Marley\nchowa, Chowa, Doña\n\n\n"
    >>> manager.getControl(name='csvtext').value = csvtext
    >>> manager.getControl(name='charset').value = ['UTF-8']
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    >>> analyze.printQuery("//div[@class='error']", manager.contents)
    <div class="error">Failed to import CSV text</div>
    <div class="error">Names cannot begin with '+' or '@' or contain '/'</div>
    >>> analyze.printQuery("id('csvtext')", manager.contents)
    <textarea name="csvtext" id="csvtext" cols="50" rows="10">@@index.html, Steve, Smith, secret
    pete, Pete, Marley
    chowa, Chowa, Do...a
    <BLANKLINE>
    <BLANKLINE>
    </textarea>
    >>> csvtext = "steve, Steve, Smith, secret\npete/marley, Pete, Marley\nchowa, Chowa, Doña\n\n\n"
    >>> manager.getControl(name='csvtext').value = csvtext
    >>> manager.getControl(name='charset').value = ['UTF-8']
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    >>> analyze.printQuery("//div[@class='error']", manager.contents)
    <div class="error">Failed to import CSV text</div>
    <div class="error">Names cannot begin with '+' or '@' or contain '/'</div>
    >>> analyze.printQuery("id('csvtext')", manager.contents)
    <textarea name="csvtext" id="csvtext" cols="50" rows="10">steve, Steve, Smith, secret
    pete/marley, Pete, Marley
    chowa, Chowa, Do...a
    <BLANKLINE>
    <BLANKLINE>
    </textarea>
    >>> csvtext = "steve, Steve, Smith, secret\npete, Pete, Marley\nchowa, Chowa, Doña\n\n\n"
    >>> manager.getControl(name='csvtext').value = csvtext
    >>> manager.getControl(name='charset').value = ['UTF-8']
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    >>> analyze.printQuery('//div[@class="info"]', manager.contents)
    <div class="info">
      <p>CSV text imported successfully.</p>
    </div>

Now we have some additional persons in the database, let's look at one
of them:

    >>> manager.open('http://localhost/persons/steve/@@person_export.xml')
    >>> print manager.contents
    <person_export xmlns:basic="http://schooltool.org/ns/model/0.1/basicperson"
                   xmlns="http://schooltool.org/ns/model/0.1">
      <persons>
        <person>
          <username>steve</username>
          <title>Smith, Steve</title>
          <basic:first_name>Steve</basic:first_name>
          <basic:last_name>Smith</basic:last_name>
        </person>
      </persons>
    </person_export>

Let's add another person, this time setting the group and the advisor in the
add form.

    >>> manager.open('http://localhost')
    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()
    >>> manager.getLink('New Person').click()
    >>> manager.getControl('First name').value = "Student"
    >>> manager.getControl('Last name').value = "Two"
    >>> manager.getControl('Gender').value = ['male']
    >>> manager.getControl('Birth date').value = '1980-01-01'
    >>> manager.getControl('Group').value = ['students']
    >>> manager.getControl('Advisor').value = ['bob']
    >>> manager.getControl('Username').value = "student2"
    >>> manager.getControl('Password').value = "pwd"
    >>> manager.getControl('Confirm').value = "pwd"
    >>> manager.getControl('Add').click()

We can check that the group appears in the new person's groups view.

    >>> manager.getLink('Groups').click()
    >>> analyze.printQuery("id('content-body')/form/fieldset[1]//tbody//label", manager.contents)
    <label for="remove_item.students">Students</label>

We can check that the advisor appears in the new person's advisors view.

    >>> manager.getLink('Advisors').click()
    >>> analyze.printQuery("id('content-body')/form/fieldset[1]//tbody//label", manager.contents)
    <label for="remove_item.bob">Bob</label>

We can fill the New Person form with Unicode text:

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()
    >>> manager.getLink('New Person').click()
    >>> manager.getControl('First name').value = "Pedro José"
    >>> manager.getControl('Last name').value = "Martínez Pérez"
    >>> manager.getControl('Gender').value = ['male']
    >>> manager.getControl('Birth date').value = '1970-05-01'

    >>> manager.getControl('Username').value = "pedro"
    >>> manager.getControl('Password').value = "pwd"
    >>> manager.getControl('Confirm').value = "pwd"
    >>> manager.getControl('Add').click()

    >>> analyze.printQuery("//div[@class='content-nav'][10]/a",
    ...                    manager.contents)
    <a href="http://localhost/persons/pedro/contact">Contacts</a>

