COMP249 Assignment: Psst Microblog Web Application
This semester we will be writing a simple micro-blogging application called Psst that allows users to post short messages. Unlike the competition, which limit messages to 140 characters, Psst allows a full 150 characters in each message. We hope that this will give us the edge in this very competitive market.
To give you an idea of what the application does, there is a demonstration version at http://comp249.stevecassidy.net/.
Since this is your first significant web application, we've cut down the features a bit to make it manageable. However we maintain the core of the application and what you write could be extended to something like a real product. Your application will support logging in users, posting messages, posting replies and viewing messages in various ways. We don't require you to be able to register new users or handle user profile changes etc.
You are given a 'starter kit' which contains the bare outline of the application. From this starting point, you will implement the full site in phases according to a detailed set of functional requirements. At the end of each phase, a set of automated tests will be used to see if you have met the criteria for that phase. Some of the marks for this assignment will be based on your passing these automated tests.
While this task may seem quite daunting, it should be achievable if you work through the examples we have provided and work on the problem bit by bit. We have run similar tasks in the past in COMP249 and most students have succeeded in getting a working system going.
Level 1
The first phase of the project involves writing a basic web application that can serve two pages.
Requirements
Level 2
In this phase you will interface to a backend database and provide views that list all posts and those for a given user.
Requirements
Level 3
The next phase of development adds the ability to login to the application and post messages.
Requirements
Going Further
The final phase of development is more open ended. You are free to add new features to the application as you see fit. In doing so you should try to follow the same development process and properly document the functional and unit tests that will give you assurance that you have achieved your desired functionality. Functional tests can be optionally implemented using WebTest but should at least be expressed as a user story ('As a user, when I...').
Starter Kit
The starter kit is a zip file containing a set of Python files to get you started on this project. These files provide a framework for you to work within, you will need to add more code of your own and possibly more modules (Python files, templates) to complete the implementation.
You can download the starter pack here: comp249-2017-psst-starter. It is also available as a Bitbucket project comp249-2017-psst-starter, if you are a git user you could fork the repository from there - please be sure to keep your own version private if you keep your work on Bitbucket (or Github).
The contents of the starter pack are as follows:
• database.py - python page templating module
• main.py - main application script with a simple example
• interface.py - stubs for the level 2 required functions
• users.py - stubs for the level 3 required functions
• level1_functional.py - functional tests for Level 1
• level2_functional.py - functional tests for Level 2
• level2_unit.py - unit tests for Level 2
• level3_functional.py - functional tests for Level 3
• level3_unit.py - unit tests for Level 3
• static - directory containing a sample CSS file
The database.py module contains code to create an interface to the database, you should use it to create a database connection rather than using raw SQLite calls. It ensures that you are using the right database file and contains code to generate test data for you to use in development. An example of how you would use this is as follows:
from database import COMP249Db
db = COMP249Db()
cursor = db.cursor()
cursor.execute("SELECT nick FROM users")
for row in cursor:
print(row)
The database contains the following tables:
• users: fields nick (user nickname), password, avatar (URL of an avatar image)
• sessions: fields sessionid, usernick, where usernick is a reference to the nick field in the users table
• posts: fields id, timestamp, usernick, content
There are also two other tables votes and follows that are not used in the core requirements but that you can use if you wish to implement further features.
Each user is identified by a nickname that is stored in the nick field in the users table. This field is used as a foreign key in other tables to refer to the user. To select data from both tables you will need to do a query with a join.
The posts table deserves further comment. The id field is an auto-incremented integer id for each post, you don't need to give this a value, it will automatically get a new unique value when you insert a row. The timestamp field will also default to the current time and date in the format '2015-02-20 01:45:06' if you don't provide a value when you add a row. So, to add a row to the posts table you just need:
sql = "INSERT INTO posts (usernick, content) VALUES (?, ?)"
cursor.execute(sql, ['steve', 'this is my post'])
db.commit()
The code as provided includes a sample Bottle application which you can run. It doesn't do much other than generate a static page that links to a copy of these notes. This is your starting point for development and you should write your code so that main.py is the main application (when I run your code, this is what I'll look for).
You can run the functional and unit tests (level1_functional.py level2_unit.py) to check that you have met the requirements at each level. To do this, open the file in PyCharm and click 'Run', choose to run as "Python unit-test". Alternately, run them from the command line eg. python level1_functional.py.
Note that if you follow the written requirements set out in the pages linked above, you should pass the functional tests. A reasonable way to work would be to read and implement each functional requirement in turn and then run the functional tests when you are done as a check.