Getting started¶
This section is intended for developers new to the database who want to get up and running with a test instance quickly.
Before you start¶
You should have done the following things before starting to work on the database:
- Get a machine running Unix-like OS or Mac OS X. (It makes life easier in the long run when dealing with Python.)
- Install Python and virtualenv.
- Work through the Django tutorial.
Running a test instance with fake data¶
Clone the repository and cd
to it. The remaining instructions assume
the repository root is the current working directory.
Create a virtualenv:
$ virtualenv -p $(which python2.7) env
$ echo "env" >>.git/info/exclude # To avoid any accidental commits
$ . env/bin/activate
Install the requirements:
$ pip install -r requirements.txt -r dev-requirements.txt
Note
The requirements.txt
file lists the Python packages required for
deployment. The dev-requirements.txt
file lists the Python packages used
only by developers. For example, the “ipython” package, which is used to
improve the shell_plus
command, is in the dev-requirements.txt
file
since it is not required when deploying the database.
Perform the initial database migration and populate the database with some fake data:
$ ./edpcmentoring/manage.py migrate
$ ./edpcmentoring/manage.py runscript loadtestfixtures
Start a local development server:
$ ./edpcmentoring/manage.py runserver_plus
Open http://127.0.0.1:8000 in your web browser. The admin interface is at http://127.0.0.1:8000/admin.
Installing on UIS MWS3 (https://panel.mws3.csx.cam.ac.uk/)¶
You will need:
- To register and create an MWS3 server (see link above)
- The root password for MySQL server (available once you MWS3 has been setup)
ssh onto your MWS3 server (via putty, or a linux/unix console), then:
$ cd /var/www/default/admindir
$ git clone https://github.com/cuedpc/edpcmentoring.git
$ python edpcmentoring/deploy/setup_mws.py
You will be asked for
- The server’s MySQL root password.
- A short name which will be prefixed by ‘pc_‘ and used as the database name
- A password the Django applicatoin will use to connect to the MySQL server
- A unique passphrase / secret key for your application
- Whether you wish to load the sample test data into the application
Once complete you should be able to visit the mws3’s host name and, if you have loaded the test data, login as test000X.
Note
The local config is held in edpcmentoring/edpcmentoring/edpcmentoring/settings_local.py, and DEBUG is set to True - not advised for production systems.
Notes on the test database¶
- There is one superuser:
test0001
. - The users
test0001
andtest0002
can log into the admin interface. - Users
test0001
totest0099
are members of CUED but not all are active. - Users
test0100
totest0199
exist in the database but are not CUED members.
Development¶
This section contains some important information if you’re thinking of developing a feature for the database.
Tests¶
The test suite for the mentoring database is run via the tox
test-runner. If
you’re intending to develop a feature for the database, it is important that you
write tests. By default, tox
will run tests using whichever Python version
correspond to the installed python
and python3
binaries.
Install tox
via pip:
$ pip install --user tox
You can now run the tests via the tox
command:
$ tox
Any positional arguments are passed to the underlying invocation of manage.py
test
and so you can specify a particular application to test by giving it’s
directory. For example:
$ tox edpcmentoring/cuedmembers
Code coverage¶
The tests are run under the coverage
code-coverage utility and files which
do not have 100% test coverage are printed out after the tests are run.
Additionally, a HTML report is generated in htmlcov/
which is useful for
determining which lines are untested.
Although 100% code coverage is probably infeasible in general, we aim for as close as possible in the database. Pull requests which increase test code coverage are welcome.