============
Demographics
============

We can add a person:

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

  >>> browser = Browser('manager', 'schooltool')
  >>> browser.open('http://localhost/persons/@@add.html')
  >>> browser.getControl(name='form.prefix').value = 'Mr'
  >>> browser.getControl(name='form.full_name').value = 'foobar'
  >>> browser.getControl(name='form.username').value = 'foobar'
  >>> browser.getControl(name='form.last_name').value = 'barson'
  >>> browser.getControl(name="form.password").value = "barfoo"
  >>> browser.getControl(name="form.password.confirm").value = "barfoo"
  >>> browser.getControl('Add').click()

We expect the data to be there:

  >>> browser.open('http://localhost/persons/foobar/nameinfo/@@edit.html')
  >>> browser.getControl(name='form.prefix').value
  'Mr'
  >>> browser.getControl(name='form.full_name').value
  'foobar'
  >>> browser.getControl(name='form.last_name').value
  'barson'

We expect no photo to be there yet as we didn't upload one:

  >>> browser.open('http://localhost/persons/foobar/nameinfo')
  >>> 'photo.jpg' in browser.contents
  False

Try logging in with the shiny new user:

  >>> ubrowser = Browser()
  >>> ubrowser.handleErrors = False
  >>> ubrowser.addHeader('Authorization', 'Basic foobar:barfoo')
  >>> ubrowser.open('http://localhost/')

And we can edit its name info (also adding a photo):

  >>> from StringIO import StringIO
  >>> browser.open('http://localhost/persons/foobar/nameinfo/@@edit.html')
  >>> browser.getControl(name='form.full_name').value = 'Someone Schooltool'
  >>> browser.getControl(name='form.photo').add_file(StringIO('my_photo'),
  ...     'binary/octet-stream', 'test.jpg')
  >>> browser.getControl(name='form.actions.apply').click()
  >>> browser.open('http://localhost/persons/foobar/nameinfo/@@edit.html')
  >>> browser.getControl(name='form.full_name').value
  'Someone Schooltool'

We also expect the photo to be there:

  >>> browser.open('http://localhost/persons/foobar/nameinfo')
  >>> 'photo.jpg' in browser.contents
  True

Editing the name info again without supplying a photo will not change
the photo:

  >>> browser.open('http://localhost/persons/foobar/nameinfo/@@edit.html')
  >>> browser.getControl(name='form.prefix').value = 'Mrs'
  >>> browser.getControl(name='form.actions.apply').click()
  >>> browser.open('http://localhost/persons/foobar/nameinfo')
  >>> 'photo.jpg' in browser.contents
  True

We can also go there by browsing the table:

  >>> browser.open('http://localhost/persons')
  >>> browser.getLink('Someone Schooltool').click()
  >>> 'Prefix' in browser.contents
  True
  >>> 'Full name' in browser.contents
  True
  >>> 'Someone Schooltool' in browser.contents
  True

We can also view the name info:

  >>> browser.open('http://localhost/persons/foobar/nameinfo')
  >>> 'Someone Schooltool' in browser.contents
  True

We can edit its demographics:

  >>> browser.open('http://localhost/persons/foobar/demographics/@@edit.html')
  >>> previous_school = browser.getControl(name='form.previous_school')
  >>> previous_school.value = 'Some text'
  >>> browser.getControl(name='form.actions.apply').click()

and view it:

  >>> browser.open('http://localhost/persons/foobar/demographics')
  >>> 'Some text' in browser.contents
  True

and its school data:

  >>> browser.open('http://localhost/persons/foobar/schooldata/@@edit.html')
  >>> id = browser.getControl(name='form.id')
  >>> id.value = 'ABC'
  >>> browser.getControl(name='form.actions.apply').click()
  >>> browser.open('http://localhost/persons/foobar/schooldata')
  >>> 'ABC' in browser.contents
  True

and various parent and emergency contact screens:

  >>> browser.open('http://localhost/persons/foobar/parent1/@@edit.html')
  >>> name = browser.getControl(name='form.name').value = 'Zorro'
  >>> browser.getControl(name='form.actions.apply').click()

  >>> browser.open('http://localhost/persons/foobar/parent2/@@edit.html')
  >>> browser.open('http://localhost/persons/foobar/emergency1/@@edit.html')
  >>> browser.open('http://localhost/persons/foobar/emergency2/@@edit.html')
  >>> browser.open('http://localhost/persons/foobar/emergency3/@@edit.html')

It's possible to submit screen by screen by using the Apply and Next
button:

  >>> browser.open('http://localhost/persons/foobar/@@edit.html')
  >>> browser.getControl('Prefix').value = 'Mrs'
  >>> browser.getControl('Apply and Next').click()
  >>> browser.getControl('Gender').value = ['female']
  >>> browser.getControl('Apply and Next').click()
  >>> browser.getControl('Enrollment date').value = '2006-06-08'
  >>> browser.getControl('Apply and Next').click()
  >>> browser.getControl('Relationship to student').value = ['parent']
  >>> browser.getControl('Apply and Next').click()
  >>> browser.getControl('Relationship to student').value = ['parent']
  >>> browser.getControl('Apply and Next').click()
  >>> browser.getControl('Relationship to student').value = ['other']
  >>> browser.getControl('Apply and Next').click()
  >>> browser.getControl('Relationship to student').value = ['other']
  >>> browser.getControl('Apply and Next').click()
  >>> browser.getControl('Relationship to student').value = ['other']
  >>> browser.getControl('Apply and Next').click()

at the last 'Apply and Next', we go to the person's display form for
name info::

  >>> browser.url
  'http://localhost/persons/foobar/nameinfo'
  >>> 'Mrs' in browser.contents
  True

We can also add people as CSV data:

  >>> browser.open('http://localhost/persons/@@person-csvimport.html')
  >>> csv = browser.getControl(name='csvtext')
  >>> csv.value = 'delta, Delta\nomega, Omega'
  >>> browser.getControl(name="UPDATE_SUBMIT").click()

We can browse to the nameinfo of the newly added persons:

  >>> browser.open('http://localhost/persons/delta/nameinfo')
  >>> browser.open('http://localhost/persons/omega/nameinfo')

We can also see the persons added so far in tabular display:

  >>> browser.open('http://localhost/persons')
  >>> 'delta' in browser.contents
  True
  >>> 'omega' in browser.contents
  True
  >>> 'foobar' in browser.contents
  True

We can search for the persons:

  >>> browser.open('http://localhost/persons/@@search.html')
  >>> sb = browser.getControl(name="form.fulltext")
  >>> sb.value = 'delt'
  >>> browser.getControl(name="form.actions.submit").click()

Check that the persons appeared on the output of the search:

  >>> 'delta' in browser.contents
  True

Check that the search didn't return un-matching cases:

  >>> 'foobar' in browser.contents
  False

We can also search on parents:

  >>> browser.open('http://localhost/persons/@@search.html')
  >>> browser.getControl(name='form.parentName').value = 'Zorro'
  >>> browser.getControl(name='form.actions.submit').click()

Check that we found foobar, whose parent is Zorro:

  >>> 'foobar' in browser.contents
  True

But not delta or omega:

  >>> 'delta' in browser.contents
  False
  >>> 'omega' in browser.contents
  False

We can also do the same for the student id ABC:

  >>> browser.open('http://localhost/persons/@@search.html')
  >>> id = browser.getControl(name='form.studentId')
  >>> id.value = 'ABC'
  >>> browser.getControl(name='form.actions.submit').click()

Check that we found foobar, whose student id is ABC:

  >>> 'foobar' in browser.contents
  True

But not delta or omega:

  >>> 'delta' in browser.contents
  False
  >>> 'omega' in browser.contents
  False

There's a quick search form in the table view:

  >>> browser.open('http://localhost/persons')
  >>> sb = browser.getControl(name="form.fulltext")
  >>> sb.value = 'del*'
  >>> browser.getControl(name="form.actions.submit").click()
  >>> 'delta' in browser.contents
  True
  >>> 'foobar' in browser.contents
  False

The form is not reset so your query stays visible:

  >>> sb.value
  'del*'

Allow normal users to view the table of persons:

  >>> browser.open('http://localhost/access_control.html')
  >>> browser.getControl('The list of people with accounts in the system is visible to the general public').click()
  >>> browser.getControl('Apply').click()

Try seeing the table of persons with a normal user:

  >>> ubrowser.open('http://localhost/persons')
  >>> "foobar" in ubrowser.contents
  True
  >>> "manager" in ubrowser.contents
  True
  >>> "delta" in ubrowser.contents
  True
  >>> "omega" in ubrowser.contents
  True

The user delta is not a teacher:

  >>> browser.open("http://localhost/persons/delta/")
  >>> "Teachers" in browser.contents
  False

but it can be:

  >>> browser.open('http://localhost/persons/delta/@@groups.html')
  >>> 'Teachers' in browser.contents
  True
  >>> tc = browser.getControl("Teachers").click()
  >>> browser.getControl("Add").click()

Now it should be a teacher:

  >>> browser.open("http://localhost/persons/delta/schooldata")
  >>> "Teachers" in browser.contents
  True

Let's make delta the advisor of omega:

  >>> browser.open("http://localhost/persons/omega/schooldata/")
  >>> "delta" in browser.contents
  False
  >>> browser.open("http://localhost/persons/omega/schooldata/@@edit.html")
  >>> adv = browser.getControl(name="form.advisor")
  >>> adv.value = ["delta"]
  >>> browser.getControl(name="form.actions.apply").click()
  >>> browser.open("http://localhost/persons/omega/schooldata/")
  >>> "Delta" in browser.contents
  True

Let's put omega in the omega team:

  >>> browser.open("http://localhost/schoolyears/2005-2006/groups/+/addSchoolToolGroup.html")
  >>> t = browser.getControl(name="field.title")
  >>> t.value = "Gamma"
  >>> browser.getControl("Add").click()
  >>> browser.open("http://localhost/persons/omega/schooldata/")
  >>> "Gamma" in browser.contents
  False
  >>> browser.open("http://localhost/persons/omega/schooldata/@@edit.html")
  >>> adv = browser.getControl(name="form.team")
  >>> adv.value = ["gamma"]
  >>> browser.getControl(name="form.actions.apply").click()
  >>> browser.open("http://localhost/persons/omega/schooldata/")
  >>> "Gamma" in browser.contents
  True

Let's try removing the advisor and see that nothing goes wrong:

  >>> browser.open("http://localhost/persons")
  >>> delete = browser.getControl(name="delete.delta")
  >>> delete.value = True
  >>> browser.getControl("Delete").click()
  >>> browser.getControl("Confirm").click()
  >>> browser.open("http://localhost/persons/omega/schooldata/")
  >>> "Delta" in browser.contents
  False
  >>> "Invalid teacher" in browser.contents
  True

Now let's try removing the team and see that nothing goes wrong:

  >>> browser.open("http://localhost/schoolyears/2005-2006/groups/")
  >>> delete = browser.getControl(name="delete.gamma")
  >>> delete.value = True
  >>> browser.getControl("Delete").click()
  >>> browser.getControl("Confirm").click()
  >>> browser.open("http://localhost/persons/omega/schooldata/")
  >>> "Gamma" in browser.contents
  False
  >>> "Invalid group" in browser.contents
  True
