Skip to content

Commit 06a7009

Browse files
committed
Code test
0 parents  commit 06a7009

23 files changed

Lines changed: 432 additions & 0 deletions

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.git
2+
*.pyc

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pyc
2+
.vagrant
3+
*.log

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM alpine:3.6
2+
3+
RUN apk add --update py3-pip python3 postgresql postgresql-dev zlib-dev libjpeg-turbo-dev gcc python3-dev musl-dev make \
4+
&& pip3 install --upgrade pip
5+
RUN if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi
6+
7+
WORKDIR /srv/python-code-test
8+
ADD requirements.in /srv/python-code-test/
9+
RUN pip3 install -r requirements.in

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Ostmodern Python Code Test
2+
3+
The goal of this exercise is to test that you know your way around Django and
4+
REST APIs. Approach it the way you would an actual long-term project.
5+
6+
The idea is to build a platform on which your users can buy and sell Starships.
7+
To make this process more transparent, it has been decided to source some
8+
technical information about the Starships on sale from the [Starship
9+
API](https://swapi.co/documentation#starships).
10+
11+
A Django project some initial data models have been created already. You may need
12+
to do some additional data modelling to satify the requirements.
13+
14+
## Getting started
15+
16+
* This test works with either
17+
[Docker](https://docs.docker.com/compose/install/#install-compose) or
18+
[Vagrant](https://www.vagrantup.com/downloads.html)
19+
* Get the code from `https://github.com/ostmodern/python-code-test`
20+
* Do all your work in your own `develop` branch
21+
* Once you have downloaded the code the following commands will get the site up
22+
and running
23+
24+
```shell
25+
# For Docker
26+
docker-compose up
27+
# You can run `manage.py` commands using the `./manapy` wrapper
28+
29+
# For Vagrant
30+
vagrant up
31+
vagrant ssh
32+
# Inside the box
33+
./manage.py runserver 0.0.0.0:8008
34+
```
35+
* The default Django "It worked!" page should now be available at
36+
http://localhost:8008/
37+
38+
## Tasks
39+
40+
Your task is to build a JSON-based REST API for your frontend developers to
41+
consume. You have built a list of user stories with your colleagues, but you get
42+
to decide how to design the API. Remember that the frontend developers will need
43+
some documentation of your API to understand how to use it.
44+
45+
We do not need you to implement users or authentication, to reduce the amount of
46+
time this exercise will take to complete. You may use any external libraries you
47+
require.
48+
49+
* We need to be able to import all existing
50+
[Starships](https://swapi.co/documentation#starships) to the provided Starship
51+
Model
52+
* A potential buyer can browse all Starships
53+
* A potential buyer can browse all the listings for a given `starship_class`
54+
* A potential buyer can sort listings by price or time of listing
55+
* To list a Starship as for sale, the user should supply the Starship name and
56+
list price
57+
* A seller can deactivate and reactivate their listing
58+
59+
After you are done, create a release branch in your repo and send us the link.

Vagrantfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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: 8008, host: 8008
12+
13+
config.vm.provision "shell", path:"./scripts/setup-server.sh"
14+
15+
config.vm.provider :virtualbox do |vb, override|
16+
vb.memory = 512
17+
end
18+
end

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: "3"
2+
services:
3+
code-test:
4+
build:
5+
context: .
6+
command: "scripts/runserver"
7+
volumes:
8+
- .:/srv/python-code-test
9+
ports:
10+
- "8008:8008"
11+
links:
12+
- postgresql
13+
postgresql:
14+
image: postgres:9.6
15+
environment:
16+
POSTGRES_USER: postgres
17+
POSTGRES_PASSWORD: postgres
18+
POSTGRES_DB: postgres

manage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testsite.settings")
7+
try:
8+
from django.core.management import execute_from_command_line
9+
except ImportError:
10+
# The above import may fail for some other reason. Ensure that the
11+
# issue is really that Django is missing to avoid masking other
12+
# exceptions on Python 2.
13+
try:
14+
import django
15+
except ImportError:
16+
raise ImportError(
17+
"Couldn't import Django. Are you sure it's installed and "
18+
"available on your PYTHONPATH environment variable? Did you "
19+
"forget to activate a virtual environment?"
20+
)
21+
raise
22+
execute_from_command_line(sys.argv)

manapy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
docker-compose run --rm code-test ./manage.py $*

requirements.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
django>=1.11,<2.0
2+
Pillow>=3.4.1,<3.5
3+
psycopg2>=2.6.2,<2.7

scripts/runserver

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
until PGPASSWORD=postgres psql --host postgresql --username postgres -c '\l' > /dev/null; do
4+
echo "Postgres is unavailable - sleeping"
5+
sleep 1
6+
done
7+
8+
export PYTHONUNBUFFERED=0
9+
./manage.py migrate
10+
./manage.py runserver 0.0.0.0:8008

0 commit comments

Comments
 (0)