Skip to content

Commit

Permalink
Merge pull request #247 from johnpooch/john-improve-serializer-perfor…
Browse files Browse the repository at this point in the history
…mance

Improve serializer performance
  • Loading branch information
johnpooch authored Apr 29, 2021
2 parents 0f34926 + 1e0a32c commit 3d686ac
Showing 1 changed file with 1 addition and 99 deletions.
100 changes: 1 addition & 99 deletions service/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest import mock, skip
from unittest import mock
from unittest.mock import patch

from django.urls import reverse
Expand Down Expand Up @@ -1660,101 +1660,3 @@ def test_not_found(self):
url = self.get_url(pk=self.turn.id)
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)


class TestGameStateViewOptimization(BaseTestCase):

expected_num_queries = 14

def setUp(self):
self.user = factories.UserFactory()
self.client.force_authenticate(user=self.user)
self.variant = self.create_test_variant(name='test')
self.game = self.create_test_game(
variant=self.variant,
status=GameStatus.ACTIVE,
created_by=self.user,
)
self.nation = self.create_test_nation(
variant=self.variant,
)
self.territory = self.create_test_territory(
variant=self.variant,
)
self.piece = self.create_test_piece(
game=self.game,
nation=self.nation,
)
self.url = reverse('game-state', args=[self.game.slug])

def create_turn(self):
turn = self.create_test_turn(
game=self.game,
phase=Phase.ORDER,
season=Season.SPRING,
)
self.create_test_order(
turn=turn,
nation=self.nation,
source=self.territory,
)
self.create_test_order(
turn=turn,
nation=self.nation,
source=self.territory,
)
self.create_test_piece_state(
turn=turn,
piece=self.piece,
territory=self.territory,
)
self.create_test_piece_state(
turn=turn,
piece=self.piece,
territory=self.territory,
must_retreat=True,
)
self.create_test_territory_state(
territory=self.territory,
turn=turn,
)
self.create_test_territory_state(
territory=self.territory,
turn=turn,
)
self.create_test_nation_state(
nation=self.nation,
turn=turn,
user=self.user,
)
self.create_test_nation_state(
nation=self.nation,
turn=turn,
user=self.user,
)
self.create_test_draw(
turn=turn,
proposed_by=self.nation,
proposed_by_user=self.user,
)
self.create_test_draw(
turn=turn,
proposed_by=self.nation,
proposed_by_user=self.user,
)

@skip
def test_get_game_state(self):
self.create_turn()
with self.assertNumQueries(self.expected_num_queries):
response = self.client.get(self.url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)

@skip
def test_get_game_state_multiple_turns(self):
self.create_turn()
self.create_turn()
self.create_turn()
with self.assertNumQueries(self.expected_num_queries):
response = self.client.get(self.url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)

0 comments on commit 3d686ac

Please sign in to comment.