Small coding tests to evaluate development skills using Python, Django and Django Rest Framework.
The test_instatest.py
file contains tests and empty functions for performing tasks in python. Each group of tests comes with instructions of what is required and some test data to use for testing.
The candidate should:
- Create a new branch
- Install
pytest
- Answer the questions
- Ensure that running
pytest
results in all tests passing in thetest_instatest.py
file - For each question, write a comment in the favourite version of the method explaining why this is the best solution.
The aim is to test the candidate's knowledge of python and its modules, and how to think about problems in different ways.
When finished, the candidate should create a PR so that their work can be reviewed.
The instatest_aws_sessions.py
file contains a class, a mock and some basic tests. The candidate should:
- Fork the project
- Read and understand the Wrapper class
- Using your test framework of choice, write some additional tests, including at least one to ensure that values written to the file cache are re-read correctly
- Refactor the Wrapper class in any way you see fit, to improve its structure, reliability, testability, maintainability, reusabilty and pythonic-ness.
The aim is to understand your ability and pragmaticness of writing, testing and maintaining python code. The only rules in addition to the above are:
- Python3 should be used
- executing
python -m instatest_aws_sessions
should not fail. - any tests should be able to be run with a single command in the root repository folder.
In the folder 'django', there is a django project which runs in a docker container. From inside the django
folder, the docker container can be built with:
docker build -t movietest .
and run with:
docker run -v ${PWD}:/opt/project -p 8000:8000 movietest python3 manage.py runserver 0.0.0.0:8000
The django project is currently not working because:
- it does not use the sqlite database correctly (instead it reads CSV files which are now missing)
- it represents a full-stack solution, but we want to convert it to an API
Modify the django project to use Django Rest Framework to convert the project into an API which provides the following endpoints:
/movies/
lists all movies in the database with the fields 'title', 'year', 'description', 'rating'/actors/
lists all actors in the database with the fields 'name', 'birthdate' and 'birthplace', and a 'films' field which is a URL/actors/<id>/films/
lists the films for actor , which matches the 'films' url link in the actors information/directors/
lists all directors in the database with the fields 'name', 'birthdate' and 'birthplace', and a 'films' field which is a URL link/directors/<id>/films/
lists the films for director , which matches the 'films' url link in the directors information
Note that the database and model are very basic, and some relationships may not be many-to-many. There is no need to fix this for this goal.
Ensure that tests are provided to show that the new endpoints are working.
User Story:
As an API user
I want to filter movies by year
So that I can find movies I want more easily
BDD Scenarios:
GIVEN I am using the movie API
WHEN I provide a 'start year' value to the `/movies/` endpoint
THEN the API only shows me movies from the 'start year' and later
GIVEN I am using the movie API
WHEN I provide a 'end year' value to the `/movies/` endpoint
THEN the API only shows me movies before and including the 'end year'
GIVEN I am using the movie API
WHEN I provide a 'start year' value and a 'end year' value to the `/movies/` endpoint
THEN the API only shows me movies between and including 'start year' and 'end year'
Implement the scenarios above, including passing tests. Include handling and tests for invalid inputs which you think are necessary.
User Story:
As an API user
I want to know the highest rated movies
So that I can choose a good movie more easily
BDD Scenarios:
Scenario:
GIVEN I am using the movie API
WHEN I access the '/movies/best/<n>' endpoint
THEN the API only shows me the movies <movielist> sorted by rating and then by metascore
EXAMPLES:
| n | movielist |
| 3 | The Dark Knight, Inception, Spider-Man: Into the Spider-Verse |
| 5 | The Dark Knight, Inception, Spider-Man: Into the Spider-Verse, Interstellar, Whiplash |
Sceario:
GIVEN I am using the movie API
WHEN I access the '/movies/best/' endpoint
THEN the API shows me the top 10 movies sorted by rating and then by metascore
Implement the scenarios above, including passing tests. Include handling and tests for invalid inputs which you think are necessary.
BONUS: Use a BDD-framework to test the BDD scenario.
User Story:
As a movie fan
I want to know which actors are born closest to me
So that I can learn some interesting information
BDD Scenario:
GIVEN I am using the movie API
WHEN I access the `/actors/birthdays/<date>/` endpoint
THEN the API shows me the actor information for <actorname>
EXAMPLES:
| date | actorname |
| 13031975 | Christina Hendricks |
| 20081979 | Oscar Isaac |
| 19091990 | Bill Skarsgård |
Implement the scenario above. Note that the date column has been poorly designed in the database, and so will require some manipulation.
The result should be provided as a GitHub pull request in a manner that identifies you. If you use any additional pip modules, they should be added to the requirements file. If you wish to provide notes, you may do so either in a markdown file or in comments, whichever you feel is more appropriate.