Skip to content

Commit ba7210e

Browse files
committed
Converted "Game" variables and classes to "Contest"
To keep consistency between API & axelrod these base classes have been renamed to "Contest".
1 parent 38ccc85 commit ba7210e

File tree

8 files changed

+78
-84
lines changed

8 files changed

+78
-84
lines changed

api/config/settings.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import os
2-
import sys
32
import dj_database_url
43

5-
# handle case where we are testing with no .env file
6-
if 'test' in sys.argv or 'test_coverage' in sys.argv:
7-
SECRET_KEY = 'l#-9)38*k9h9yfkcxwii++_m@3jkm%vojnjl^gkzyzmcfr_afo'
8-
else:
9-
SECRET_KEY = os.environ['SECRET_KEY']
10-
4+
# Environment specific settings from environment variables or local .env file
5+
SECRET_KEY = os.environ['SECRET_KEY']
116
DEBUG = bool(os.environ.get('DEBUG', False))
127
DOCKER = bool(os.environ.get('DOCKER_HOST', False))
138

@@ -125,13 +120,9 @@ def show_debug_toolbar(request):
125120
STATIC_URL = '/static/'
126121

127122
REST_FRAMEWORK = {
128-
'DEFAULT_PERMISSION_CLASSES': (
129-
'api.config.admin.AnonymousExceptDelete',
130-
),
131-
'DEFAULT_RENDERER_CLASSES': (
132-
'rest_framework.renderers.JSONRenderer',
133-
'rest_framework.renderers.BrowsableAPIRenderer',
134-
),
123+
'DEFAULT_PERMISSION_CLASSES': [
124+
'api.config.admin.AnonymousExceptDelete'
125+
]
135126
}
136127

137128

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/models.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import axelrod as axl
1414

1515

16-
class Game(Model):
16+
class Contest(Model):
1717

1818
PENDING = 0
1919
RUNNING = 1
@@ -37,7 +37,7 @@ class Meta:
3737
abstract = True
3838

3939

40-
class GameDefinition(Model):
40+
class ContestDefinition(Model):
4141
created = DateTimeField(auto_now_add=True, editable=False)
4242
last_updated = DateTimeField(auto_now=True, editable=False)
4343
turns = IntegerField()
@@ -48,7 +48,7 @@ class Meta:
4848
abstract = True
4949

5050

51-
class Tournament(Game):
51+
class Tournament(Contest):
5252

5353
definition = ForeignKey('TournamentDefinition')
5454

@@ -67,13 +67,12 @@ def run(self, strategies):
6767
return results
6868

6969

70-
class TournamentDefinition(GameDefinition):
71-
name = CharField(max_length=255)
70+
class TournamentDefinition(ContestDefinition):
7271
repetitions = IntegerField()
7372
with_morality = BooleanField()
7473

7574

76-
class Match(Game):
75+
class Match(Contest):
7776

7877
definition = ForeignKey('MatchDefinition')
7978

@@ -89,13 +88,13 @@ def run(self, strategies):
8988
return match
9089

9190

92-
class MatchDefinition(GameDefinition):
91+
class MatchDefinition(ContestDefinition):
9392

9493
class Meta:
9594
managed = True
9695

9796

98-
class MoranProcess(Game):
97+
class MoranProcess(Contest):
9998

10099
definition = ForeignKey('MoranDefinition')
101100

@@ -113,14 +112,14 @@ def run(self, strategies):
113112
return mp
114113

115114

116-
class MoranDefinition(GameDefinition):
115+
class MoranDefinition(ContestDefinition):
117116
mode = CharField(max_length=2)
118117

119118

120119
class InternalStrategy(Model):
121120
"""
122121
This model is used to represent strategies in an internal
123-
database table. Games reference this in a ManyToMany
122+
database table. Contests reference this in a ManyToMany
124123
to store the strategies in their player_list field. This is
125124
necessary to facilitate normalization of the database.
126125
"""

api/core/serializers.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import json
2-
31
from rest_framework import serializers
42
from rest_framework.reverse import reverse
53

@@ -57,7 +55,7 @@ def validate_player_list(player_list):
5755

5856
class Meta:
5957
model = models.TournamentDefinition
60-
fields = ('name', 'created', 'last_updated', 'turns',
58+
fields = ('created', 'last_updated', 'turns',
6159
'repetitions', 'noise', 'with_morality', 'player_list')
6260

6361

@@ -113,9 +111,9 @@ class Meta:
113111
fields = ('id', 'created', 'last_updated', 'status', 'definition', 'results')
114112

115113

116-
class GameResultSerializer:
114+
class ContestResultSerializer:
117115
"""
118-
Serialize the result of an axelrod game into a dictionary by
116+
Serialize the result of an axelrod contest into a dictionary by
119117
iterating over its __dict__ method.
120118
"""
121119

@@ -129,7 +127,7 @@ def __init__(self, result):
129127
self.data = response_object
130128

131129

132-
class MoranResultsSerializer(GameResultSerializer):
130+
class MoranResultsSerializer(ContestResultSerializer):
133131

134132
handle_locally = [
135133
'mutation_targets',
@@ -156,7 +154,7 @@ def clean_mutation_targets(result):
156154
return mutation_targets
157155

158156

159-
class MatchResultsSerializer(GameResultSerializer):
157+
class MatchResultsSerializer(ContestResultSerializer):
160158

161159
handle_locally = []
162160

@@ -177,7 +175,7 @@ def __init__(self, result):
177175
self.data['scores'] = result.scores()
178176

179177

180-
class TournamentResultsSerializer(GameResultSerializer):
178+
class TournamentResultsSerializer(ContestResultSerializer):
181179

182180
state_distribution_keys = [
183181
]

api/core/tests/test_serializers.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,19 @@ class TestTournamentDefinitionSerializer(TestCase):
7777
@classmethod
7878
def setUpClass(cls):
7979
cls.valid_post_data = {
80-
'name': 'test_tournament',
8180
'turns': 5,
8281
'repetitions': 2,
8382
'noise': 0.1,
8483
'with_morality': False,
8584
'player_list': ['test1', 'test2']
8685
}
87-
cls.missing_name = {
86+
cls.missing_noise = {
8887
'turns': 5,
8988
'repetitions': 2,
90-
'noise': 0.1,
9189
'with_morality': False,
9290
'player_list': ['test1', 'test2']
9391
}
9492
cls.invalid_field_values = {
95-
'name': 'test_tournament',
9693
'turns': 5,
9794
'repetitions': 2,
9895
'noise': 0.1,
@@ -111,9 +108,9 @@ def test_is_valid_with_all_fields(self):
111108
self.assertTrue(serializer.is_valid())
112109

113110
def test_is_invalid_with_missing_fields(self):
114-
serializer = TournamentDefinitionSerializer(data=self.missing_name)
111+
serializer = TournamentDefinitionSerializer(data=self.missing_noise)
115112
self.assertFalse(serializer.is_valid())
116-
self.assertEqual({'name': ['This field is required.']}, serializer.errors)
113+
self.assertEqual({'noise': ['This field is required.']}, serializer.errors)
117114

118115
def test_is_invalid_with_incorrect_value(self):
119116
serializer = TournamentDefinitionSerializer(data=self.invalid_field_values)

api/core/tests/test_views.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ def init_params(self):
2020
return {}
2121

2222

23-
class TestGame(object):
24-
25-
def __init__(self):
26-
pass
27-
28-
2923
class TestStrategyView(TestCase):
3024
strategies = [
3125
TestStrategy('Test One', {'stochastic': True, 'memory_depth': 1}),
@@ -65,30 +59,26 @@ def setUpClass(cls):
6559
cls.tournament1 = Tournament(id=3)
6660
cls.valid_post_data = {
6761
'id': 10,
68-
'name': 'tournament',
6962
'turns': 5,
7063
'repetitions': 2,
7164
'noise': 0.1,
7265
'with_morality': False,
7366
'player_list': ["adaptive", "allcoralld", "adaptive", "anticycler"],
7467
}
7568
cls.no_strategy_found = {
76-
'name': 'tournament',
7769
'turns': 5,
7870
'repetitions': 2,
7971
'noise': 0.1,
8072
'with_morality': False,
8173
'player_list': ["adapt", "allcoralld"],
8274
}
83-
cls.missing_name = {
75+
cls.missing_noise = {
8476
'turns': 5,
8577
'repetitions': 2,
86-
'noise': 0.1,
8778
'with_morality': False,
8879
'player_list': ["adaptive", "allcoralld", "adaptive", "anticycler"],
8980
}
9081
cls.one_strategy = {
91-
'name': 'tournament',
9282
'turns': 5,
9383
'repetitions': 2,
9484
'noise': 0.1,
@@ -123,10 +113,10 @@ def test_strategy_not_found(self):
123113

124114
def test_invalid_field(self):
125115
response = self.client.post('/tournaments/',
126-
json.dumps(self.missing_name),
116+
json.dumps(self.missing_noise),
127117
content_type='application/json')
128118
self.assertEqual(400, response.status_code)
129-
self.assertEqual({'name': ['This field is required.']}, response.data)
119+
self.assertEqual({'noise': ['This field is required.']}, response.data)
130120

131121
def test_invalid_strategy_count(self):
132122
response = self.client.post('/tournaments/',

0 commit comments

Comments
 (0)