Skip to content

Commit b13f882

Browse files
authored
Merge pull request #8 from erik-sn/master
Complete Endpoints for Tournament/Match/MoranProcess & Database Storage
2 parents 9687aa2 + ba7210e commit b13f882

22 files changed

+1361
-21
lines changed

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: python
2+
python:
3+
- 3.5
4+
- 3.6
5+
install:
6+
- pip install -r requirements.txt
7+
- pip install coverage
8+
- pip install codecov
9+
script:
10+
- coverage run --source='api' manage.py test --settings=api.config.test_settings
11+
- coverage report -m --omit="*/test*"
12+
after_success:
13+
- codecov

README.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ project folder to start the web and database servers:
2727

2828
.. code::
2929
30+
docker volume create --name=postgres
3031
docker-compose up
3132
3233
This will take several minutes the first time you run it as it needs to download and install all the necessary
@@ -55,15 +56,13 @@ from there rather than the command line from now on.
5556
Running Tests
5657
-------------
5758

58-
Make sure you have created a .env file as above. To run all tests:
59-
6059
.. code::
6160
6261
python manage.py test --settings=api.config.test_settings
6362
6463
With coverage:
6564

66-
.. code:
65+
.. code::
6766
6867
coverage run --source='api' manage.py test --settings=api.config.test_settings
6968
coverage html --omit="*/test*"

api/config/admin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from rest_framework import permissions
2+
3+
4+
class AnonymousExceptDelete(permissions.BasePermission):
5+
6+
def has_permission(self, request, view):
7+
# allow all POST requests
8+
if request.method == 'DELETE':
9+
return request.user.is_staff
10+
return True

api/config/settings.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,11 @@ def show_debug_toolbar(request):
119119
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
120120
STATIC_URL = '/static/'
121121

122-
# REST_FRAMEWORK = {
123-
# # Use Django's standard `django.contrib.auth` permissions,
124-
# # or allow read-only access for unauthenticated users.
125-
# 'DEFAULT_PERMISSION_CLASSES': [
126-
# 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
127-
# ]
128-
# }
122+
REST_FRAMEWORK = {
123+
'DEFAULT_PERMISSION_CLASSES': [
124+
'api.config.admin.AnonymousExceptDelete'
125+
]
126+
}
129127

130128

131129
# Cross Origin Resource Sharing https://github.com/ottoyiu/django-cors-headers

api/config/test_settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
if 'test' in sys.argv or 'test_coverage' in sys.argv:
12+
1213
# use an in memory sqlite3 backend for performance
1314
DATABASES = {
1415
'default': {

api/config/urls.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
from django.conf import settings
22
from django.conf.urls import url, include
33
from rest_framework.routers import DefaultRouter
4-
from api.core.views import StrategyViewSet
4+
from api.core.views import (
5+
MatchViewSet,
6+
MoranViewSet,
7+
StrategyViewSet,
8+
TournamentViewSet,
9+
)
510

611

712
urlpatterns = [
@@ -17,7 +22,10 @@
1722
router = DefaultRouter()
1823

1924
routes = {
20-
'strategies': StrategyViewSet
25+
'matches': MatchViewSet,
26+
'moran': MoranViewSet,
27+
'strategies': StrategyViewSet,
28+
'tournaments': TournamentViewSet,
2129
}
2230

2331
for route, viewset in routes.items():

api/core/migrations/0001_initial.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11 on 2017-04-23 18:12
3+
from __future__ import unicode_literals
4+
5+
import django.contrib.postgres.fields.jsonb
6+
from django.db import migrations, models
7+
import django.db.models.deletion
8+
9+
10+
class Migration(migrations.Migration):
11+
12+
initial = True
13+
14+
dependencies = [
15+
]
16+
17+
operations = [
18+
migrations.CreateModel(
19+
name='Game',
20+
fields=[
21+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
22+
('created', models.DateTimeField(auto_now_add=True)),
23+
('last_updated', models.DateTimeField(auto_now=True)),
24+
('status', models.IntegerField(choices=[(0, 'PENDING'), (1, 'RUNNING'), (2, 'SUCCESS'), (3, 'FAILED')], default=0)),
25+
('results', django.contrib.postgres.fields.jsonb.JSONField()),
26+
],
27+
options={
28+
'managed': False,
29+
},
30+
),
31+
migrations.CreateModel(
32+
name='InternalStrategy',
33+
fields=[
34+
('id', models.TextField(primary_key=True, serialize=False)),
35+
('created', models.DateTimeField(auto_now_add=True)),
36+
('last_updated', models.DateTimeField(auto_now=True)),
37+
],
38+
),
39+
migrations.CreateModel(
40+
name='Match',
41+
fields=[
42+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
43+
('created', models.DateTimeField(auto_now_add=True)),
44+
('last_updated', models.DateTimeField(auto_now=True)),
45+
('status', models.IntegerField(choices=[(0, 'PENDING'), (1, 'RUNNING'), (2, 'SUCCESS'), (3, 'FAILED')], default=0)),
46+
('results', django.contrib.postgres.fields.jsonb.JSONField(null=True)),
47+
],
48+
),
49+
migrations.CreateModel(
50+
name='MatchDefinition',
51+
fields=[
52+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
53+
('created', models.DateTimeField(auto_now_add=True)),
54+
('last_updated', models.DateTimeField(auto_now=True)),
55+
('turns', models.IntegerField()),
56+
('noise', models.FloatField()),
57+
('player_list', models.ManyToManyField(to='core.InternalStrategy')),
58+
],
59+
),
60+
migrations.CreateModel(
61+
name='MoranDefinition',
62+
fields=[
63+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
64+
('created', models.DateTimeField(auto_now_add=True)),
65+
('last_updated', models.DateTimeField(auto_now=True)),
66+
('turns', models.IntegerField()),
67+
('noise', models.FloatField()),
68+
('mode', models.CharField(max_length=2)),
69+
('player_list', models.ManyToManyField(to='core.InternalStrategy')),
70+
],
71+
),
72+
migrations.CreateModel(
73+
name='Result',
74+
fields=[
75+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
76+
('created', models.DateTimeField(auto_now_add=True)),
77+
('last_updated', models.DateTimeField(auto_now=True)),
78+
('type', models.CharField(max_length=255)),
79+
('result', django.contrib.postgres.fields.jsonb.JSONField()),
80+
],
81+
),
82+
migrations.CreateModel(
83+
name='Tournament',
84+
fields=[
85+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
86+
('created', models.DateTimeField(auto_now_add=True)),
87+
('last_updated', models.DateTimeField(auto_now=True)),
88+
('status', models.IntegerField(choices=[(0, 'PENDING'), (1, 'RUNNING'), (2, 'SUCCESS'), (3, 'FAILED')], default=0)),
89+
('results', django.contrib.postgres.fields.jsonb.JSONField()),
90+
],
91+
),
92+
migrations.CreateModel(
93+
name='TournamentDefinition',
94+
fields=[
95+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
96+
('name', models.CharField(max_length=255)),
97+
('created', models.DateTimeField(auto_now_add=True)),
98+
('last_updated', models.DateTimeField(auto_now=True)),
99+
('turns', models.IntegerField()),
100+
('repetitions', models.IntegerField()),
101+
('noise', models.FloatField()),
102+
('with_morality', models.BooleanField()),
103+
('player_list', models.ManyToManyField(to='core.InternalStrategy')),
104+
],
105+
),
106+
migrations.AddField(
107+
model_name='tournament',
108+
name='definition',
109+
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.TournamentDefinition'),
110+
),
111+
migrations.AddField(
112+
model_name='match',
113+
name='definition',
114+
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.MatchDefinition'),
115+
),
116+
]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11 on 2017-04-23 18:37
3+
from __future__ import unicode_literals
4+
5+
import django.contrib.postgres.fields.jsonb
6+
from django.db import migrations
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('core', '0001_initial'),
13+
]
14+
15+
operations = [
16+
migrations.AlterField(
17+
model_name='tournament',
18+
name='results',
19+
field=django.contrib.postgres.fields.jsonb.JSONField(null=True),
20+
),
21+
]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11 on 2017-04-23 18:50
3+
from __future__ import unicode_literals
4+
5+
import django.contrib.postgres.fields.jsonb
6+
from django.db import migrations, models
7+
import django.db.models.deletion
8+
9+
10+
class Migration(migrations.Migration):
11+
12+
dependencies = [
13+
('core', '0002_auto_20170423_1837'),
14+
]
15+
16+
operations = [
17+
migrations.CreateModel(
18+
name='MoranProcess',
19+
fields=[
20+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
21+
('created', models.DateTimeField(auto_now_add=True)),
22+
('last_updated', models.DateTimeField(auto_now=True)),
23+
('status', models.IntegerField(choices=[(0, 'PENDING'), (1, 'RUNNING'), (2, 'SUCCESS'), (3, 'FAILED')], default=0)),
24+
('results', django.contrib.postgres.fields.jsonb.JSONField(null=True)),
25+
('definition', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.MoranDefinition')),
26+
],
27+
),
28+
]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11 on 2017-04-24 23:02
3+
from __future__ import unicode_literals
4+
5+
import django.contrib.postgres.fields.jsonb
6+
from django.db import migrations
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('core', '0003_moranprocess'),
13+
]
14+
15+
operations = [
16+
migrations.DeleteModel(
17+
name='Result',
18+
),
19+
migrations.AlterModelOptions(
20+
name='matchdefinition',
21+
options={'managed': True},
22+
),
23+
migrations.AlterField(
24+
model_name='match',
25+
name='results',
26+
field=django.contrib.postgres.fields.jsonb.JSONField(),
27+
),
28+
migrations.AlterField(
29+
model_name='moranprocess',
30+
name='results',
31+
field=django.contrib.postgres.fields.jsonb.JSONField(),
32+
),
33+
migrations.AlterField(
34+
model_name='tournament',
35+
name='results',
36+
field=django.contrib.postgres.fields.jsonb.JSONField(),
37+
),
38+
]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11 on 2017-04-24 23:12
3+
from __future__ import unicode_literals
4+
5+
import django.contrib.postgres.fields.jsonb
6+
from django.db import migrations
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('core', '0004_auto_20170424_2302'),
13+
]
14+
15+
operations = [
16+
migrations.AlterField(
17+
model_name='match',
18+
name='results',
19+
field=django.contrib.postgres.fields.jsonb.JSONField(null=True),
20+
),
21+
migrations.AlterField(
22+
model_name='moranprocess',
23+
name='results',
24+
field=django.contrib.postgres.fields.jsonb.JSONField(null=True),
25+
),
26+
migrations.AlterField(
27+
model_name='tournament',
28+
name='results',
29+
field=django.contrib.postgres.fields.jsonb.JSONField(null=True),
30+
),
31+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11 on 2017-04-25 02:14
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('core', '0005_auto_20170424_2312'),
12+
]
13+
14+
operations = [
15+
migrations.RemoveField(
16+
model_name='tournamentdefinition',
17+
name='name',
18+
),
19+
]

api/core/migrations/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)