Homework 2ΒΆ

Due by noon on Thursday, Jan 23rd. Reminder, per the syllabus you may use The Google, friends, family, etc. to complete the homework.

  1. Do all of the below on a new branch, ‘hw2’. (See Basic Instructions for Git and Github for info on how to create a new branch.)

  2. Fix any HW1 problems; see my solution here

    1. All lines in the header must end in rn.
    2. ChangeLog must be updated.
  3. Refactor ‘server.py’ to be testable, and run some tests.

    a. Change server.py to have two functions, main() and handle_connection(conn). The ‘main’ function should have all of the current code (through the ‘accept’ statement in the loop) in it, while the actual connection handling (all the c.send stuff, and c.close) should be done in ‘handle_connection(conn)’.

    At the end of server.py, then put:

    if __name__ == '__main__':

    ‘python server.py’ should then still run the server, but ‘python -c “import server”’ should do nothing.

    1. Make sure your code passes the test in test_server.py.

    Merge in my ‘hw2’ code, to your hw2 branch:

    git pull https://github.com/ctb/cse491-serverz.git hw2

    This will give you a new file, ‘test_server.py’.

    Next, make sure you’re in an activated virtualenv, and run ‘pip install nose’.

    Finally, run ‘nosetests’:

    nosetests -s

    and (when you are done fixing your code :) you should see no errors.

    For more information on nose, read this introduction.

  1. Update your server.py code to grab the request data (use ‘c.recv(1000)’), extract the ‘path’ component, and return different HTML content for the following request URLs:


    Extend the tests to test each one of these; you should end up with at least four test functions in ‘test_server’, one for each of the request URLs.

  2. Modify ‘/’ to return HTML that contains links to /content, /file, and /image. Make sure the tests still pass (i.e. fix ‘em).

  3. Mofify the handle_connection function to handle POST requests separately from GET; use the script ‘send-post-request’ to test this. For now, just return ‘hello world’ or some such.

    Write a test for this behavior, too.

    Note, to use ‘send-post-request’, you’ll need to run

    pip install requests

    inside your virtualenv.

  4. Update ChangeLog with whatever it is you’ve changed; commit, push everything to your repository as part of the ‘hw2’ branch on your github repo. See Basic Instructions for Git and Github; you should be doing something like:

    git push origin hw2:hw2
  5. On github, set up a pull request between your two branches, ‘master’ and ‘hw2’ (FROM hw2 INTO base master). Make sure your diff in the pull request contains all of the changes you wanted to have.



Previous topic

Day 5: Tuesday, January 21st, 2014

Next topic

Day 4: Thursday, January 16th, 2014

This Page

Edit this document!

This file can be edited directly through the Web. Anyone can update and fix errors in this document with few clicks -- no downloads needed.

  1. Go to Homework 2 on GitHub.
  2. Edit files using GitHub's text editor in your web browser (see the 'Edit' tab on the top right of the file)
  3. Fill in the Commit message text box at the bottom of the page describing why you made the changes. Press the Propose file change button next to it when done.
  4. Then click Send a pull request.
  5. Your changes are now queued for review under the project's Pull requests tab on GitHub!

For an introduction to the documentation format please see the reST primer.