Django application implementing a basic REST API for battleship.
1.Features
4.Usage
7.License
A RESTful API for a one player game of battleship. It includes the ability to randomize the starting location of oponents ships.
- Python 3.5.2
- Django.
- Pip for managing Python Packages.
- Coverage.py for checking test coverage of code.
- virtualenv to separte our development environment and Python version from other projects.
We need python version 3.x.x
Once we have installed pip, we can install the requirements by typing:
pip install -r requirements.txt
A more detail guide of how to setup virtualenv for our enviroment can be found in the following link:
https://packaging.python.org/guides/installing-using-pip-and-virtualenv/
The API endpoints response are in JSON format.
API end point | GET method | POST method |
---|---|---|
/battleship/api/v1/games/ | N/A | Creates a new game |
/battleship/api/v1/games/int:game_id/ships | N/A | Randomly places five ships of different types in a 10x10 board |
/battleship/api/v1/games/int:game_id | Return information about the game | N/A |
/battleship/api/v1/games/int:game_id/shot?row=1&column=1 | Launches a torpedo at location row, column | N/A |
This project uses a sqlite3 database. You will need to create and migrate the schema using django's migration tool.
python manage.py makemigrations
python manage.py migrate
The database has been setup.
The current settings are set for port 8000 on localhost. You can start the server by typing:
python manage.py runserver
Having succesfully activated the virtual environment, the user can navigate to the battleship directory where manage.py is found. The following command will run all tests cases in the tests directory.
python manage.py test --verbosity 1
We can use coverage.py to check how much of our code has been tested by our unit tests. First we need to run our tests using coverage by typing the following on the prompt:
coverage run --source='.' manage.py test battleship_api
To read the report of the break down of our unit test coverage we can do so by typing the following commands:
coverage report