Skip to content

Commit

Permalink
Merge pull request #253 from johnpooch/develop
Browse files Browse the repository at this point in the history
0.5.1
  • Loading branch information
johnpooch authored May 3, 2021
2 parents 88df40b + 825dae5 commit 613d284
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def create_test_turn(self, save=True, turn_end=False, **kwargs):
def create_test_territory(self, save=True, **kwargs):
if 'variant' not in kwargs:
kwargs['variant'] = self.create_test_variant()
kwargs.setdefault('name', 'Belgium')
kwargs.setdefault('name', 'Belgium' + str(random.randint(10000, 99999)))
kwargs.setdefault('controlled_by_initial', None)
kwargs.setdefault('nationality', None)
kwargs.setdefault('type', base.TerritoryType.COASTAL)
Expand Down
1 change: 1 addition & 0 deletions service/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class Meta:
'named_coasts',
'nationality',
'neighbours',
'shared_coasts',
'supply_center',
'type',
)
Expand Down
27 changes: 27 additions & 0 deletions service/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@
from core.models.base import GameStatus


class TestTerritorySerializer(TestCase, DiplomacyTestCaseMixin):

serializer_class = serializers.TerritorySerializer

def setUp(self):
variant = self.create_test_variant()
self.territory = self.create_test_territory(variant=variant)
neighbour = self.create_test_territory(variant=variant)
self.territory.neighbours.add(neighbour)
shared_coast = self.create_test_territory(variant=variant)
self.territory.shared_coasts.add(shared_coast)
self.create_test_named_coast(parent=self.territory)

def serialize_object(self, obj):
return self.serializer_class(obj).data

def test_serialize(self):
data = self.serialize_object(self.territory)
self.assertEqual(data['id'], self.territory.id)
self.assertEqual(data['name'], self.territory.name)
self.assertEqual(data['nationality'], self.territory.nationality)
self.assertEqual(data['neighbours'], list(self.territory.neighbours.values_list('id', flat=True)))
self.assertEqual(data['shared_coasts'], list(self.territory.shared_coasts.values_list('id', flat=True)))
self.assertEqual(data['supply_center'], self.territory.supply_center)
self.assertEqual(data['type'], self.territory.type)


class TesNationStateOrdersStatusSerializer(TestCase, DiplomacyTestCaseMixin):

expected_num_queries = 4
Expand Down

0 comments on commit 613d284

Please sign in to comment.