Skip to content

Commit

Permalink
#99 added unit test mentioned in ��8bb3e38 and fixed corressponding b…
Browse files Browse the repository at this point in the history
…ehavior for getting stadium stand statistics
  • Loading branch information
StegSchreck committed Dec 12, 2016
1 parent 3167bb8 commit 2b01024
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
26 changes: 20 additions & 6 deletions core/tests/unit/views/test_ofm_stadium_detail_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class OFMStadiumDetailsViewTestCase(TestCase):
def setUp(self):
MatchdayFactory.create()
MatchdayFactory.create(number=1)
user1 = OFMUser.objects.create_user(
self.user1 = OFMUser.objects.create_user(
username='alice',
email='[email protected]',
password='alice',
Expand All @@ -23,7 +23,7 @@ def setUp(self):
ofm_username='bob',
ofm_password='bob'
)
match = MatchFactory.create(user=user1)
match = MatchFactory.create(user=self.user1)
self.stadium_stat = MatchStadiumStatisticsFactory.create(match=match)
StadiumStandStatisticsFactory.create(stadium_statistics=self.stadium_stat, sector='N')
StadiumStandStatisticsFactory.create(stadium_statistics=self.stadium_stat, sector='S')
Expand All @@ -35,10 +35,10 @@ def test_user_can_see_his_data(self):
response = self.client.get('/ofm/stadium/' + str(self.stadium_stat.id))
self.assertEqual(response.status_code, 200)
self.assertTrue('stadium_stat' in response.context_data)
self.assertTrue('north_stand' in response.context_data)
self.assertTrue('south_stand' in response.context_data)
self.assertTrue('west_stand' in response.context_data)
self.assertTrue('east_stand' in response.context_data)
self.assertTrue(response.context_data['north_stand'] is not None)
self.assertTrue(response.context_data['south_stand'] is not None)
self.assertTrue(response.context_data['west_stand'] is not None)
self.assertTrue(response.context_data['east_stand'] is not None)

def test_user_cannot_see_other_users_data(self):
self.client.login(username='bob', password='bob')
Expand All @@ -49,3 +49,17 @@ def test_user_cannot_see_other_users_data(self):
self.assertFalse('south_stand' in response.context_data)
self.assertFalse('west_stand' in response.context_data)
self.assertFalse('east_stand' in response.context_data)

def test_stadium_data_if_one_stand_not_used(self):
MatchdayFactory.create(number=2)
match = MatchFactory.create(user=self.user1)
stadium_stat_2 = MatchStadiumStatisticsFactory.create(match=match)
StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='N')
StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='S')
StadiumStandStatisticsFactory.create(stadium_statistics=stadium_stat_2, sector='W')
response = self.client.get('/ofm/stadium/' + str(stadium_stat_2.id))
self.assertEqual(response.status_code, 200)
self.assertTrue(response.context_data['north_stand'] is not None)
self.assertTrue(response.context_data['south_stand'] is not None)
self.assertTrue(response.context_data['west_stand'] is not None)
self.assertTrue(response.context_data['east_stand'] is None)
13 changes: 7 additions & 6 deletions core/views/ofm/stadium_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ def get_context_data(self, **kwargs):
context = super(StadiumDetailView, self).get_context_data(**kwargs)

if self.get_object():
context['north_stand'] = self._get_stand_sector('N')
context['south_stand'] = self._get_stand_sector('S')
context['west_stand'] = self._get_stand_sector('W')
context['east_stand'] = self._get_stand_sector('O')
context['north_stand'] = self._get_stand_by_sector('N')
context['south_stand'] = self._get_stand_by_sector('S')
context['west_stand'] = self._get_stand_by_sector('W')
context['east_stand'] = self._get_stand_by_sector('O')

return context

Expand All @@ -168,8 +168,9 @@ def get_object(self, **kwargs):
matches = Match.objects.filter(user=self.request.user, stadium_statistics=stadium_stat)
return stadium_stat if matches.count() > 0 else None

def _get_stand_sector(self, sector):
return StadiumStandStatistics.objects.get(stadium_statistics=self.get_object(), sector=sector)
def _get_stand_by_sector(self, sector):
stand_statistics = StadiumStandStatistics.objects.filter(stadium_statistics=self.get_object(), sector=sector)
return stand_statistics[0] if stand_statistics.count() > 0 else None


@method_decorator(login_required, name='dispatch')
Expand Down

0 comments on commit 2b01024

Please sign in to comment.