Skip to content

Commit 622fd61

Browse files
committed
Code test
0 parents  commit 622fd61

27 files changed

Lines changed: 399 additions & 0 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vagrant

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Ostmodern Python Code Test
2+
3+
The goal of this exercise is to test that you know your way around the command line and Django tools. Whilst there is some simple HTML to write, you won't be expected to style the page.
4+
5+
The idea is to do some prototype work on a site that allows users to add their comments & reactions to an episode of a television program. They'll be able to upload an image, or write a tweet, which will be stored locally in the application. Each episode will have a stream of reactions, showing a list of items with their details.
6+
7+
A Django project has been created and some initial data models have been created.
8+
9+
## Getting started
10+
* You'll need to install [VirtualBox](https://www.virtualbox.org/) and [Vagrant](https://www.vagrantup.com/) on your development machine
11+
* Get the code from `https://github.com/ostmodern/python-code-test`
12+
* Do all your work in your own `develop` branch
13+
* Once you have downloaded the code the following commands will get the site up and running
14+
15+
```shell
16+
vagrant up
17+
vagrant ssh
18+
fab migrate
19+
fab web
20+
```
21+
* The default Django "It worked!" page should now be available at http://localhost:8888/
22+
23+
## Tasks
24+
25+
* Update the models so that `Episode`s can have `PhotoReaction`s or `TweetReaction`s
26+
* Add some sample data using the Django admin interface and save it as fixtures
27+
* Make it possible for an admin to moderate the site by deleting photos/tweets (and un­deleting them) using the Django admin interace
28+
* Make a page that displays the reactions for a particular episode in chronological order at `/episodes/:id/`
29+
* The stream should only display items that are not deleted
30+
* Make a fabric command that clears the database and loads your sample data
31+
* Create a release branch in your repo and send us the link

Vagrantfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5+
VAGRANTFILE_API_VERSION = "2"
6+
7+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8+
config.vm.box = "ubuntu/xenial64"
9+
10+
# Django runserver networking
11+
config.vm.network "forwarded_port", guest: 8888, host: 8888
12+
config.vm.network "forwarded_port", guest: 80, host: 8989
13+
14+
config.vm.provision "shell", path:"./scripts/server-setup.sh"
15+
16+
config.vm.provider :virtualbox do |vb, override|
17+
vb.memory = 512
18+
end
19+
end

fabfile.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from fabric.api import local
2+
3+
4+
def run_manage(command):
5+
local('/home/ubuntu/.virtualenvs/code-test/bin/python /vagrant/testsite/manage.py %s' % command)
6+
7+
8+
def web():
9+
run_manage('runserver 0.0.0.0:8888')
10+
11+
12+
def migrate():
13+
run_manage('migrate')
14+
15+
16+
def make_migrations():
17+
run_manage('makemigrations')
18+
19+
20+
def requirements():
21+
local('/home/ubuntu/.virtualenvs/code-test/bin/pip install -r requirements.txt ')

requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Django==1.8.15
2+
ecdsa==0.13
3+
Fabric3==1.12.post1
4+
paramiko==1.17.2
5+
Pillow==3.4.1
6+
psycopg2==2.6.2
7+
pycrypto==2.6.1
8+
six==1.10.0

scripts/server-setup-user.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
# VirtualEnv and Django setup
3+
4+
USER=ubuntu
5+
6+
# This is a distinct file as it's meant to be run as the primary user we SSH in as
7+
echo -e "\033[0;34m > Running main-user setup script, with the following parameters:\033[0m"
8+
echo -e "\033[0;34m > Main User: $USER\033[0m"
9+
10+
# Set up virtualenv directory for the user if required
11+
if [ ! -d /home/$USER/.virtualenvs ]; then
12+
echo -e "\033[0;31m > Creating .virtualenvs folder"
13+
mkdir /home/$USER/.virtualenvs
14+
fi
15+
16+
# write all the profile stuff for the user if required
17+
grep -q virtualenvs /home/$USER/.bashrc
18+
if [ $? -ne 0 ]; then
19+
echo -e "\033[0;31m > Updating profile file\033[0m"
20+
echo "source ~/.virtualenvs/code-test/bin/activate" >> /home/$USER/.bashrc
21+
echo "cd /vagrant/" >> /home/$USER/.bashrc
22+
fi
23+
24+
echo -e "\033[0;34m > Setting up virtualenv\033[0m"
25+
export WORKON_HOME=/home/$USER/.virtualenvs
26+
export PIP_VIRTUALENV_BASE=/home/$USER/.virtualenvs
27+
python3 -m venv $PIP_VIRTUALENV_BASE/code-test
28+
source $PIP_VIRTUALENV_BASE/code-test/bin/activate
29+
30+
# install requirements
31+
echo -e "\033[0;34m > Installing the pip requirements.\033[0m"
32+
$PIP_VIRTUALENV_BASE/code-test/bin/pip install -U pip
33+
$PIP_VIRTUALENV_BASE/code-test/bin/pip install wheel==0.29.0
34+
$PIP_VIRTUALENV_BASE/code-test/bin/pip install -r /vagrant/requirements.txt

scripts/server-setup.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
USER=ubuntu
3+
4+
echo -e "\033[0;34m > Provisioning Vagrant server, with the following parameters:\033[0m"
5+
echo -e "\033[0;34m > Main User: $USER\033[0m"
6+
7+
# Housekeeping
8+
echo -e "\033[0;34m > Installing system packages.\033[0m"
9+
apt-get update
10+
apt-get install -y git vim build-essential python3.5-dev python3-venv \
11+
libncurses5-dev fabric postgresql-9.5 postgresql-server-dev-9.5 \
12+
libjpeg62-dev zlib1g-dev libfreetype6-dev
13+
14+
# Postgres DB setup
15+
echo -e "\033[0;34m > Setting up DB. If it already exists this will generate warnings, but no harm will be done.\033[0m"
16+
sudo -u postgres psql -c "CREATE DATABASE codetest ENCODING='UTF8' TEMPLATE=template0;"
17+
sudo -u postgres psql -c "CREATE USER ubuntu;"
18+
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE codetest TO ubuntu;"
19+
sudo -u postgres psql -c "ALTER USER ubuntu CREATEDB;"
20+
21+
# do the rest as the user we'll be logging in as through SSH
22+
chmod +x /vagrant/scripts/server-setup-user.sh
23+
sudo -H -u $USER /vagrant/scripts/server-setup-user.sh

testsite/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text eol=lf

testsite/episodes/__init__.py

Whitespace-only changes.

testsite/episodes/admin.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.contrib import admin
2+
3+
from .models import Episode
4+
5+
admin.site.register(Episode)

0 commit comments

Comments
 (0)