Пример #1
0
 def test_count_points_invalid(self):
     request = factory.get('/api/teams/{0}/matches/points/'.format(
         self.dev_team.id))
     force_authenticate(request, user=self.admin_user)
     view = MatchViewSet.as_view({'get': 'points'})
     response = view(request, parent_lookup_team=str(self.dev_team.id))
     response.render()
     self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE,
                      'expected HTTP 406 - Not acceptable')
Пример #2
0
 def test_allow_delete_match(self):
     request = factory.delete('/api/teams/{0}/matches/{1}/'.format(
         self.dev_team.id, 9))
     force_authenticate(request, user=self.user)
     view = MatchViewSet.as_view({'delete': 'retrieve'})
     response = view(request,
                     parent_lookup_team=str(self.dev_team.id),
                     pk=9)
     response.render()
     self.assertEqual(response.status_code, status.HTTP_200_OK,
                      'expected HTTP 200')
Пример #3
0
 def test_get_list(self):
     matches = Match.objects.by_team(self.dev_team.id)
     request = factory.get('/api/teams/{0}/matches/'.format(
         self.dev_team.id))
     force_authenticate(request, user=self.admin_user)
     view = MatchViewSet.as_view({'get': 'list'})
     response = view(request, parent_lookup_team=str(self.dev_team.id))
     response.render()
     response_data = json.loads(str(response.content, encoding='utf8'))
     self.assertEqual(response.status_code, status.HTTP_200_OK,
                      'expected HTTP 200')
     self.assertEqual(response_data['count'], matches.count(),
                      'expected correct number of dev team matches')
Пример #4
0
 def test_count_points(self):
     request = factory.get(
         '/api/teams/{0}/matches/points/?red_att=8&red_def=8&blue_att=8&blue_def=8'
         .format(self.dev_team.id))
     force_authenticate(request, user=self.admin_user)
     view = MatchViewSet.as_view({'get': 'points'})
     response = view(request, parent_lookup_team=str(self.dev_team.id))
     response.render()
     response_data = json.loads(str(response.content, encoding='utf8'))
     self.assertEqual(response.status_code, status.HTTP_200_OK,
                      'expected HTTP 200')
     self.assertEqual(response_data, {
         "red": 26,
         "blue": 26
     }, 'expected correct match points')
Пример #5
0
 def test_get_item(self):
     match_id = 9
     match = Match.objects.get(pk=match_id)
     request = factory.get('/api/teams/{0}/matches/{1}/'.format(
         self.dev_team.id, match_id))
     force_authenticate(request, user=self.admin_user)
     view = MatchViewSet.as_view({'get': 'retrieve'})
     response = view(request,
                     parent_lookup_team=str(self.dev_team.id),
                     pk=str(match_id))
     response.render()
     expected_data = MatchSerializer(match).data
     self.assertEqual(response.status_code, status.HTTP_200_OK,
                      'expected HTTP 200')
     for rk, ek in zip(response.data.keys(), expected_data.keys()):
         self.assertEqual(str(response.data[rk]), str(expected_data[ek]),
                          'expected correct match data')