Functional test for timetable schemas
=====================================


Overview
--------

0. Create a SchoolTool instance.
1. Add a timetable schema named 'weekly' with the advanced add view.
2. Add another timetable schema -- one called 'Another Schema'.
3. Choose the second schema as the default one.
4. Add a third timetable schema ('other') -- but this time use the simple add
   view.
5. Create a term '2005-summer' from 2005-06-01 to 2005-08-31.
6. Mark 2005-07-07 as a special day -- change class start and end times.
7. Switch the default schema to 'other'.
8. Mark 2005-07-07 as an emergency day -- move it to 2005-09-01.
9. Verify that 2005-09-01 remembers class times specified in step 6.


Setup
-----

Let's create a SchoolTool instance:

  >>> print http("""
  ... POST /@@contents.html HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... Content-Length: ...
  ... Content-Type: application/x-www-form-urlencoded
  ... 
  ... type_name=BrowserAdd__schooltool.app.SchoolToolApplication&\
  ... new_value=frogpond""")
  HTTP/1.1 303 See Other
  ...
  Location: http://localhost/@@contents.html
  ...

The schema container is empty initially:

  >>> print http(r"""
  ... GET /frogpond/ttschemas HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... """, handle_errors=False)
  HTTP/1.1 200 Ok
  ...
      <p>There are none.</p>
  ...


Advanced timetable schema add view
----------------------------------

Let's go to the advanced 'New Timetable Schema' view:

  >>> print http(r"""
  ... GET /frogpond/ttschemas/complexadd.html HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... """)
  HTTP/1.1 200 Ok
  ...
      <input class="textType" id="field.title" name="field.title" size="20" type="text" value="default"  />
  ...

When we enter a schema name and press the 'Add day' button, we get an
extra day:

  >>> print http("""
  ... POST /frogpond/ttschemas/complexadd.html HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... Content-Length: ...
  ... Content-Type: application/x-www-form-urlencoded
  ... 
  ... field.name=weekly&day1=Day+1&day1.period1=Period+1&ADD_DAY=Add+day&\
  ... time1.period=Period+1&time1.day0=&time1.day1=&time1.day2=&\
  ... time1.day3=&time1.day4=&time1.day5=&time1.day6=&field.duration=""")
  HTTP/1.1 200 Ok
  ...
        <th class="day">
          <input class="text" type="text" name="day2"
                 value="Day 2" tabindex="4" />
        </th>
        <th class="day" width="1%">
          <input class="button-ok" type="submit" value="C"
                 title="Copy periods from previous day"
                 name="COPY_DAY_1" tabindex="5" />
        </th>
        <th class="day" width="1%">
          <input class="button-cancel" type="submit" value="X"
                 title="Remove this day" name="DELETE_DAY_2"
                 tabindex="6" />
        </th>
  ...

When we click 'Add Period', we get an extra period!

  >>> print http("""
  ... POST /frogpond/ttschemas/complexadd.html HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... Content-Length: ...
  ... Content-Type: application/x-www-form-urlencoded
  ... 
  ... field.name=weekly&day1=Monday&day2=Tuesday&day3=Wednesday&\
  ... day4=Thursday&day5=Friday&day1.period1=Period+1&\
  ... day2.period1=Period+1&day3.period1=Period+1&day4.period1=Period+1&\
  ... day5.period1=Period+1&ADD_PERIOD=Add+period&time1.period=Period+1&\
  ... time1.day0=&time1.day1=&time1.day2=&time1.day3=&time1.day4=&\
  ... time1.day5=&time1.day6=&field.duration=""")
  HTTP/1.1 200 Ok
  ...
      <tr>
        <td class="period" width="20%" colspan="2">
          <input type="text" class="text" name="day1.period2"
                 value="Period 2" tabindex="17" />
        </td>
  <BLANKLINE>
        <td class="period" width="20%" colspan="3">
          <input type="text" class="text" name="day2.period2"
                 value="" tabindex="19" />
        </td>
  <BLANKLINE>
        <td class="period" width="20%" colspan="3">
          <input type="text" class="text" name="day3.period2"
                 value="" tabindex="21" />
        </td>
  <BLANKLINE>
        <td class="period" width="20%" colspan="3">
          <input type="text" class="text" name="day4.period2"
                 value="" tabindex="23" />
        </td>
  <BLANKLINE>
        <td class="period" width="20%" colspan="3">
          <input type="text" class="text" name="day5.period2"
                 value="" tabindex="25" />
        </td>
      </tr>
  ...


Finally we post the completed form:

  >>> print http(r"""
  ... POST /frogpond/ttschemas/complexadd.html HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... Content-Length: ...
  ... Content-Type: application/x-www-form-urlencoded
  ... 
  ... field.title=weekly&day1=Monday&day2=Tuesday&day3=Wednesday&day4=Thursday&day5=Friday&day1.period1=Period+1&day2.period1=Period+1&day3.period1=Period+1&day4.period1=Period+1&day5.period1=Period+1&day1.period2=Period+2&day2.period2=Period+2&day3.period2=Period+2&day4.period2=Period+2&day5.period2=Period+2&day1.period3=Period+3&day2.period3=Period+3&day3.period3=Period+3&day4.period3=Period+3&day5.period3=Period+3&day1.period4=Period+4&day2.period4=Period+4&day3.period4=Period+4&day4.period4=Period+4&day5.period4=Period+4&model=WeeklyTimetableModel&time1.period=Period+1&time1.day0=09%3A00-09%3A45&time1.day1=09%3A00-09%3A45&time1.day2=09%3A00-09%3A45&time1.day3=09%3A00-09%3A45&time1.day4=09%3A00-09%3A45&time1.day5=09%3A00-09%3A45&time1.day6=09%3A00-09%3A45&time2.period=Period+2&time2.day0=10%3A00-10%3A45&time2.day1=10%3A00-10%3A45&time2.day2=10%3A00-10%3A45&time2.day3=10%3A00-10%3A45&time2.day4=10%3A00-10%3A45&time2.day5=10%3A00-10%3A45&time2.day6=10%3A00-10%3A45&time3.period=Period+3&time3.day0=11%3A00-11%3A45&time3.day1=11%3A00-11%3A45&time3.day2=11%3A00-11%3A45&time3.day3=11%3A00-11%3A45&time3.day4=11%3A00-11%3A45&time3.day5=11%3A00-11%3A45&time3.day6=11%3A00-11%3A45&time4.period=Period+4&time4.day0=12%3A00-12%3A45&time4.day1=12%3A00-12%3A45&time4.day2=12%3A00-12%3A45&time4.day3=12%3A00-12%3A45&time4.day4=12%3A00-12%3A45&time4.day5=12%3A00-12%3A45&time4.day6=12%3A00-12%3A45&field.duration=45&CREATE=Create+timetable+schema""", handle_errors=False)
  HTTP/1.1 303 See Other
  Content-Length: ...
  Content-Type: text/plain
  Location: http://localhost/frogpond/ttschemas
  <BLANKLINE>
  http://localhost/frogpond/ttschemas

Now we see the newly created timetable schema in the list, it should
be the default one:

  >>> print http(r"""
  ... GET /frogpond/ttschemas HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... """, handle_errors=False)
  HTTP/1.1 200 Ok
  ...
          <a href="http://localhost/frogpond/ttschemas/weekly">weekly</a>
  ...
        <label for="ttschema">Default Timetable Schema:</label>
        <form method="post" action=".">
          <select name="ttschema" size="1" id="ttschema">
            <option value="">Not Selected</option>
            <option selected="selected" value="weekly">weekly</option>
          </select>
          <input type="submit" class="button-ok"
                 name="UPDATE_SUBMIT" value="Change"
                 title="Shortcut: Alt-A" accesskey="A" />
        </form>
      </div>
  ...


The unauthenticated user can also, surprisingly, see what is the
default schema:

  >>> print http(r"""
  ... GET /frogpond/ttschemas HTTP/1.1
  ... """, handle_errors=False)
  HTTP/1.1 200 Ok
  ...
          <a href="http://localhost/frogpond/ttschemas/weekly">weekly</a>
  ...
          <div class="row">
            <label for="ttschema">Default Timetable Schema:</label>
            <a href="http://localhost/frogpond/ttschemas/weekly">weekly</a>
          </div>
  ...

Lets add one more schema:

  >>> print http(r"""
  ... POST /frogpond/ttschemas/complexadd.html HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... Content-Length: ...
  ... Content-Type: application/x-www-form-urlencoded
  ... 
  ... field.title=Another Schema&day1=Monday&day2=Tuesday&day3=Wednesday&day4=Thursday&day5=Friday&day1.period1=Period+1&day2.period1=Period+1&day3.period1=Period+1&day4.period1=Period+1&day5.period1=Period+1&day1.period2=Period+2&day2.period2=Period+2&day3.period2=Period+2&day4.period2=Period+2&day5.period2=Period+2&day1.period3=Period+3&day2.period3=Period+3&day3.period3=Period+3&day4.period3=Period+3&day5.period3=Period+3&day1.period4=Period+4&day2.period4=Period+4&day3.period4=Period+4&day4.period4=Period+4&day5.period4=Period+4&model=WeeklyTimetableModel&time1.period=Period+1&time1.day0=09%3A00-09%3A45&time1.day1=09%3A00-09%3A45&time1.day2=09%3A00-09%3A45&time1.day3=09%3A00-09%3A45&time1.day4=09%3A00-09%3A45&time1.day5=09%3A00-09%3A45&time1.day6=09%3A00-09%3A45&time2.period=Period+2&time2.day0=10%3A00-10%3A45&time2.day1=10%3A00-10%3A45&time2.day2=10%3A00-10%3A45&time2.day3=10%3A00-10%3A45&time2.day4=10%3A00-10%3A45&time2.day5=10%3A00-10%3A45&time2.day6=10%3A00-10%3A45&time3.period=Period+3&time3.day0=11%3A00-11%3A45&time3.day1=11%3A00-11%3A45&time3.day2=11%3A00-11%3A45&time3.day3=11%3A00-11%3A45&time3.day4=11%3A00-11%3A45&time3.day5=11%3A00-11%3A45&time3.day6=11%3A00-11%3A45&time4.period=Period+4&time4.day0=12%3A00-12%3A45&time4.day1=12%3A00-12%3A45&time4.day2=12%3A00-12%3A45&time4.day3=12%3A00-12%3A45&time4.day4=12%3A00-12%3A45&time4.day5=12%3A00-12%3A45&time4.day6=12%3A00-12%3A45&field.duration=45&CREATE=Create+timetable+schema""", handle_errors=False)
  HTTP/1.1 303 See Other
  Content-Length: ...
  Content-Type: text/plain
  Location: http://localhost/frogpond/ttschemas
  <BLANKLINE>
  http://localhost/frogpond/ttschemas

It should appear on the list:

  >>> print http(r"""
  ... GET /frogpond/ttschemas HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... """, handle_errors=False)
  HTTP/1.1 200 Ok
  ...
          <a href="http://localhost/frogpond/ttschemas/another-schema">Another Schema</a>
  ...
          <a href="http://localhost/frogpond/ttschemas/weekly">weekly</a>
  ...

We can change the default ttschema if we want to:

  >>> print http(r"""
  ... POST /frogpond/ttschemas HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... Content-Length: ...
  ... Content-Type: application/x-www-form-urlencoded
  ... 
  ... ttschema=another-schema&UPDATE_SUBMIT=Change""")
  HTTP/1.1 200 Ok
  ...
            <option selected="selected" value="another-schema">Another Schema</option>
  ...


Simple timetable add view
-------------------------

Now let's try the simple timetable schema setup view:

  >>> print http("""
  ... POST /frogpond/ttschemas/simpleadd.html HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... Content-Type: application/x-www-form-urlencoded
  ... 
  ... field.title=other&\
  ... field.period_name_1=P1&\
  ... field.period_start_1=9:00&field.period_finish_1=9:45&\
  ... field.period_name_2=P2&\
  ... field.period_start_2=10:00&field.period_finish_2=10:45&\
  ... field.period_name_3=P3&\
  ... field.period_start_3=11:00&field.period_finish_3=11:45&\
  ... CREATE=Create\
  ... """)
  HTTP/1.1 303 See Other
  Content-Length: ...
  ...
  Location: http://localhost/frogpond/ttschemas
  <BLANKLINE>
  ...

A new timetable schema appeared:

  >>> print http(r"""
  ... GET /frogpond/ttschemas HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... """)
  HTTP/1.1 200 Ok
  ...
            <a href="http://localhost/frogpond/ttschemas/other">other</a>
  ...


Special days
------------

We need a term:

    >>> print http("""
    ... POST /frogpond/terms/@@add.html HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Type: application/x-www-form-urlencoded
    ...
    ... field.title=2005+summer&\
    ... field.first=2005-06-01&\
    ... field.last=2005-08-31&\
    ... TOGGLE_5=Saturday&\
    ... TOGGLE_6=Sunday&\
    ... UPDATE_SUBMIT=Add+term
    ... """, handle_errors=False)
    HTTP/1.1 303 See Other
    Content-Length: ...
    Content-Type: text/html;charset=utf-8
    Location: http://localhost/frogpond/terms
    ...

We can shift the start and end times for periods for a certain day:

  >>> print http(r"""
  ... POST /frogpond/ttschemas/other/@@special.html HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... Content-Type: application/x-www-form-urlencoded
  ...
  ... date=2005-07-07
  ... """)
  HTTP/1.1 200 Ok
  <BLANKLINE>
  ...
     <table>
       <tr>
         <th>Period title</th>
         <th>Original start</th>
         <th>Original end</th>
         <th>New start</th>
         <th>New end</th>
       </tr>
       <tr>
         <td>P1</td>
         <td>09:00</td>
         <td>09:45</td>
         <td>
           <input type="text" name="P1_start" value="09:00" />
         </td>
         <td>
           <input type="text" name="P1_end" value="09:45" />
         </td>
       </tr>
       <tr>
         <td>P2</td>
         <td>10:00</td>
         <td>10:45</td>
         <td>
           <input type="text" name="P2_start" value="10:00" />
         </td>
         <td>
           <input type="text" name="P2_end" value="10:45" />
         </td>
       </tr>
       <tr>
         <td>P3</td>
         <td>11:00</td>
         <td>11:45</td>
         <td>
           <input type="text" name="P3_start" value="11:00" />
         </td>
         <td>
           <input type="text" name="P3_end" value="11:45" />
         </td>
       </tr>
     </table>
  ...

If we fill in this form, an exception day is posted:

  >>> print http("""
  ... POST /frogpond/ttschemas/other/@@special.html HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... Content-Type: application/x-www-form-urlencoded
  ...
  ... date=2005-07-07&\
  ... SUBMIT=next&\
  ... P1_start=8:00&\
  ... P1_end=8:30&\
  ... P2_start=8:45&\
  ... P2_end=9:15&\
  ... P3_start=9:30&\
  ... P3_end=10:15""")
  HTTP/1.1 303 See Other
  <BLANKLINE>
  ...

If we look at the form again, we see the times have changed:

  >>> print http(r"""
  ... POST /frogpond/ttschemas/other/@@special.html HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... Content-Type: application/x-www-form-urlencoded
  ...
  ... date=2005-07-07
  ... """)
  HTTP/1.1 200 Ok
  <BLANKLINE>
  ...
     <table>
       <tr>
         <th>Period title</th>
         <th>Original start</th>
         <th>Original end</th>
         <th>New start</th>
         <th>New end</th>
       </tr>
       <tr>
         <td>P1</td>
         <td>09:00</td>
         <td>09:45</td>
         <td>
           <input type="text" name="P1_start" value="08:00" />
         </td>
         <td>
           <input type="text" name="P1_end" value="08:30" />
         </td>
       </tr>
       <tr>
         <td>P2</td>
         <td>10:00</td>
         <td>10:45</td>
         <td>
           <input type="text" name="P2_start" value="08:45" />
         </td>
         <td>
           <input type="text" name="P2_end" value="09:15" />
         </td>
       </tr>
       <tr>
         <td>P3</td>
         <td>11:00</td>
         <td>11:45</td>
         <td>
           <input type="text" name="P3_start" value="09:30" />
         </td>
         <td>
           <input type="text" name="P3_end" value="10:15" />
         </td>
       </tr>
     </table>
  ...


Emergency Days
--------------

Now let's make 2005-07-07 an emergency day:

  >>> print http(r"""
  ... POST /frogpond/terms/2005-summer/@@emergency.html HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... Content-Type: application/x-www-form-urlencoded
  ...
  ... date=2005-07-07
  ... """)
  HTTP/1.1 200 Ok
  ...
  <BLANKLINE>
  ...
  <form class="plain" method="POST"
        action="http://localhost/frogpond/terms/2005-summer/@@emergency.html">
  <BLANKLINE>
  <BLANKLINE>
  <BLANKLINE>
     <input type="hidden" name="date" value="2005-07-07" />
  <BLANKLINE>
    <p>
      Please enter the replacement date below.
    </p>
  <BLANKLINE>
    <div class="row">
      <label>Replacement</label>
      <select name="replacement">
        <option>2005-07-09</option>
        <option>2005-07-10</option>
        <option>2005-07-16</option>
        <option>2005-07-17</option>
        <option>2005-07-23</option>
        <option>2005-07-24</option>
        <option>2005-07-30</option>
        <option>2005-07-31</option>
        <option>2005-08-06</option>
        <option>2005-08-07</option>
        <option>2005-08-13</option>
        <option>2005-08-14</option>
        <option>2005-08-20</option>
        <option>2005-08-21</option>
        <option>2005-08-27</option>
        <option>2005-08-28</option>
        <option>2005-09-01</option>
        <option>2005-09-02</option>
        <option>2005-09-03</option>
      </select>
    </div>
  <BLANKLINE>
    <div class="controls">
      <input type="submit" class="button-ok" name="SUBMIT"
             value="Proceed" />
      <input type="submit" class="button-cancel" name="CANCEL"
             value="Cancel" />
    </div>
  <BLANKLINE>
  </form>
  ...

When we select both dates, the replacement day is registered:

  >>> print http("""
  ... POST /frogpond/terms/2005-summer/@@emergency.html HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... Content-Type: application/x-www-form-urlencoded
  ...
  ... date=2005-07-07&\
  ... replacement=2005-09-01
  ... """, handle_errors=False)
  HTTP/1.1 303 See Other
  <BLANKLINE>
  ...

Now all periods for this day are cancelled:

  >>> print http(r"""
  ... POST /frogpond/ttschemas/other/@@special.html HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... Content-Type: application/x-www-form-urlencoded
  ...
  ... date=2005-07-07
  ... """, handle_errors=False)
  HTTP/1.1 200 Ok
  ...
  <input type="text" name="P1_start" value="" />
  ...
  <input type="text" name="P1_end" value="" />
  ...
  <input type="text" name="P2_start" value="" />
  ...
  <input type="text" name="P2_end" value="" />
  ...
  <input type="text" name="P3_start" value="" />
  ...
  <input type="text" name="P3_end" value="" />
  ...

But the replacement day now contains periods all-right:

  >>> print http(r"""
  ... POST /frogpond/ttschemas/other/@@special.html HTTP/1.1
  ... Authorization: Basic mgr:mgrpw
  ... Content-Type: application/x-www-form-urlencoded
  ...
  ... date=2005-09-01
  ... """, handle_errors=False)
  HTTP/1.1 200 Ok
  ...
  <input type="text" name="P1_start" value="09:00" />
  ...
  <input type="text" name="P1_end" value="09:45" />
  ...
  <input type="text" name="P2_start" value="10:00" />
  ...
  <input type="text" name="P2_end" value="10:45" />
  ...
  <input type="text" name="P3_start" value="11:00" />
  ...
  <input type="text" name="P3_end" value="11:45" />
  ...
