Exemple #1
0
 def test_list_ratings_for_second_round_of_portfolioreview(self):
     from dynamicfixtures import (
         _prize_juror,
         _prize_piece_alice,
         _prize_piece_bob,
         _rating_piece_alice,
         _rating_piece_bob,
     )
     from ..api import RatingEndpoint
     round_two_starttime = datetime.strptime(
         settings.PORTFOLIO_REVIEW_ROUND_TWO_STARTTIME,
         settings.PORTFOLIO_REVIEW_ROUND_TIMEFORMAT,
     ).replace(tzinfo=pytz.UTC)
     subdomain = 'portfolioreview'
     _prize_piece_alice(subdomain=subdomain)
     _prize_piece_bob(subdomain=subdomain)
     rating_piece_alice = _rating_piece_alice(subdomain=subdomain)
     rating_piece_bob = _rating_piece_bob(subdomain=subdomain)
     rating_piece_alice.datetime = round_two_starttime
     rating_piece_alice.save()
     rating_piece_bob.datetime = round_two_starttime - timedelta(seconds=1)
     rating_piece_bob.save()
     prize_juror = _prize_juror(subdomain=subdomain)
     url = reverse('api:prize:rating-list', kwargs={'domain_pk': subdomain})
     view = RatingEndpoint.as_view({'get': 'list'})
     factory = APIRequestFactory()
     request = factory.get(url, {'prize_round': 2})
     force_authenticate(request, user=prize_juror.user)
     response = view(request, domain_pk=subdomain)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertIn('ratings', response.data)
     self.assertEqual(len(response.data['ratings']), 1)
     self.assertIn(str(rating_piece_alice.rating),
                   response.data['ratings'][0]['rating'])
Exemple #2
0
 def test_retrieve_rating(self):
     from dynamicfixtures import (
         _prize_juror,
         _prize_piece_alice,
         _rating_piece_alice,
     )
     from ..api import RatingEndpoint
     prize_piece_alice = _prize_piece_alice()
     rating_piece_alice = _rating_piece_alice()
     prize_juror = _prize_juror()
     piece_pk = prize_piece_alice.piece.pk
     subdomain = prize_juror.prize.whitelabel_settings.subdomain
     url = reverse('api:prize:rating-detail',
                   kwargs={
                       'pk': piece_pk,
                       'domain_pk': subdomain
                   })
     view = RatingEndpoint.as_view({'get': 'retrieve'})
     factory = APIRequestFactory()
     request = factory.get(url)
     force_authenticate(request, user=prize_juror.user)
     response = view(request, pk=piece_pk, domain_pk=subdomain)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(response.data['rating']['rating'],
                      str(rating_piece_alice.rating))
Exemple #3
0
 def test_select_piece(self):
     from dynamicfixtures import (_prize_juror, _prize_piece_alice,
                                  _rating_one_piece_alice,
                                  _rating_two_piece_alice)
     from ..api import RatingEndpoint
     from ..models import PrizePiece
     prize_piece = _prize_piece_alice()
     self.assertFalse(prize_piece.is_selected)
     piece = prize_piece.piece
     prize_juror = _prize_juror()
     _rating_one_piece_alice()
     _rating_two_piece_alice()
     subdomain = prize_juror.prize.whitelabel_settings.subdomain
     data = {}
     url = reverse('api:prize:rating-select',
                   kwargs={
                       'pk': piece.pk,
                       'domain_pk': subdomain
                   })
     view = RatingEndpoint.as_view({'post': 'select'})
     factory = APIRequestFactory()
     request = factory.post(url, data=data)
     force_authenticate(request, user=prize_juror.user)
     response = view(request, pk=piece.pk, domain_pk=subdomain)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     self.assertTrue(PrizePiece.objects.get(pk=prize_piece.pk).is_selected)
Exemple #4
0
 def test_list_ratings_when_some(self):
     from dynamicfixtures import (
         _prize_juror,
         _prize_piece_alice,
         _prize_piece_bob,
         _rating_piece_alice,
         _rating_piece_bob,
     )
     from ..api import RatingEndpoint
     _prize_piece_alice()
     _prize_piece_bob()
     rating_piece_alice = _rating_piece_alice()
     rating_piece_bob = _rating_piece_bob()
     prize_juror = _prize_juror()
     subdomain = prize_juror.prize.whitelabel_settings.subdomain
     url = reverse('api:prize:rating-list', kwargs={'domain_pk': subdomain})
     view = RatingEndpoint.as_view({'get': 'list'})
     factory = APIRequestFactory()
     request = factory.get(url)
     force_authenticate(request, user=prize_juror.user)
     response = view(request, domain_pk=subdomain)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertIn('ratings', response.data)
     self.assertEqual(len(response.data['ratings']), 2)
     ratings = [rating['rating'] for rating in response.data['ratings']]
     self.assertIn(str(rating_piece_alice.rating), ratings)
     self.assertIn(str(rating_piece_bob.rating), ratings)
Exemple #5
0
 def test_retrieve_rating_for_round_two(self):
     from dynamicfixtures import (
         _prize_juror,
         _prize_piece_alice,
         _rating_one_piece_alice,
         _rating_two_piece_alice,
     )
     from ..api import RatingEndpoint
     round_two_starttime = datetime.strptime(
         settings.PORTFOLIO_REVIEW_ROUND_TWO_STARTTIME,
         settings.PORTFOLIO_REVIEW_ROUND_TIMEFORMAT,
     ).replace(tzinfo=pytz.UTC)
     subdomain = 'portfolioreview'
     prize_piece_alice = _prize_piece_alice()
     rating_one = _rating_one_piece_alice(subdomain=subdomain)
     rating_one.datetime = round_two_starttime
     rating_one.save()
     rating_two = _rating_two_piece_alice(subdomain=subdomain)
     rating_two.datetime = round_two_starttime - timedelta(seconds=1)
     rating_two.save()
     prize_juror = _prize_juror(subdomain=subdomain)
     piece_pk = prize_piece_alice.piece.pk
     url = reverse('api:prize:rating-detail',
                   kwargs={
                       'pk': piece_pk,
                       'domain_pk': subdomain
                   })
     view = RatingEndpoint.as_view({'get': 'retrieve'})
     factory = APIRequestFactory()
     request = factory.get(url, {'prize_round': 2})
     force_authenticate(request, user=prize_juror.user)
     response = view(request, pk=piece_pk, domain_pk=subdomain)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(response.data['rating']['rating'],
                      str(rating_one.rating))
Exemple #6
0
 def test_list_pieces_when_some(self):
     from dynamicfixtures import (
         _djroot_user,
         _prize_juror,
         _prize_piece_alice,
         _prize_piece_bob,
         _rating_piece_alice,
         _rating_piece_bob,
         _alice_bitcoin_wallet,
         _bob_bitcoin_wallet,
     )
     from ..api import PrizePieceEndpoint
     _djroot_user()
     _prize_piece_alice()
     _prize_piece_bob()
     _rating_piece_alice()
     _rating_piece_bob()
     prize_juror = _prize_juror()
     _alice_bitcoin_wallet()
     _bob_bitcoin_wallet()
     subdomain = prize_juror.prize.whitelabel_settings.subdomain
     url = reverse('api:prize:prize-pieces-list',
                   kwargs={'domain_pk': subdomain})
     view = PrizePieceEndpoint.as_view({'get': 'list'})
     factory = APIRequestFactory()
     request = factory.get(url)
     force_authenticate(request, user=prize_juror.user)
     response = view(request, domain_pk=subdomain)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(response.data['count'], 2)
Exemple #7
0
 def test_list_ratings_when_none(self):
     from dynamicfixtures import _prize_juror
     from ..api import RatingEndpoint
     prize_juror = _prize_juror()
     subdomain = prize_juror.prize.whitelabel_settings.subdomain
     url = reverse('api:prize:rating-list', kwargs={'domain_pk': subdomain})
     view = RatingEndpoint.as_view({'get': 'list'})
     factory = APIRequestFactory()
     request = factory.get(url)
     force_authenticate(request, user=prize_juror.user)
     response = view(request, domain_pk=subdomain)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertIn('ratings', response.data)
     self.assertEqual(len(response.data['ratings']), 0)
Exemple #8
0
 def test_list_pieces_for_second_round_of_portfolioreview(self):
     from dynamicfixtures import (
         _djroot_user,
         _prize_juror,
         _prize_piece_alice,
         _prize_piece_bob,
         _rating_piece_alice,
         _rating_piece_bob,
         _alice_bitcoin_wallet,
         _bob_bitcoin_wallet,
     )
     from ..api import PrizePieceEndpoint
     _djroot_user()
     _alice_bitcoin_wallet()
     _bob_bitcoin_wallet()
     subdomain = 'portfolioreview'
     prize_piece_alice = _prize_piece_alice(subdomain=subdomain)
     prize_piece_alice.round = 2
     prize_piece_alice.save()
     _prize_piece_bob(subdomain=subdomain)
     round_two_starttime = datetime.strptime(
         settings.PORTFOLIO_REVIEW_ROUND_TWO_STARTTIME,
         settings.PORTFOLIO_REVIEW_ROUND_TIMEFORMAT,
     ).replace(tzinfo=pytz.UTC)
     rating_piece_alice = _rating_piece_alice(subdomain=subdomain)
     rating_piece_bob = _rating_piece_bob(subdomain=subdomain)
     rating_piece_alice.datetime = round_two_starttime
     rating_piece_alice.save()
     rating_piece_bob.datetime = round_two_starttime - timedelta(seconds=1)
     rating_piece_bob.save()
     prize_juror = _prize_juror(subdomain=subdomain)
     prize = prize_juror.prize
     prize.active_round = 2
     prize.save()
     url = reverse('api:prize:prize-pieces-list',
                   kwargs={'domain_pk': subdomain})
     view = PrizePieceEndpoint.as_view({'get': 'list'})
     factory = APIRequestFactory()
     request = factory.get(url)
     force_authenticate(request, user=prize_juror.user)
     response = view(request, domain_pk=subdomain)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(response.data['count'], 1)
     self.assertIsNotNone(response.data['pieces'][0]['ratings'])
Exemple #9
0
 def test_create_rating(self):
     from dynamicfixtures import _prize_juror, _prize_piece_alice
     from ..api import RatingEndpoint
     from ..models import Rating
     self.assertFalse(Rating.objects.exists())
     prize_piece_alice = _prize_piece_alice()
     prize_juror = _prize_juror()
     subdomain = prize_juror.prize.whitelabel_settings.subdomain
     data = {
         'note': 8,
         'piece_id': prize_piece_alice.piece.pk,
     }
     url = reverse('api:prize:rating-list', kwargs={'domain_pk': subdomain})
     view = RatingEndpoint.as_view({'post': 'create'})
     factory = APIRequestFactory()
     request = factory.post(url, data=data)
     force_authenticate(request, user=prize_juror.user)
     response = view(request, domain_pk=subdomain)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     self.assertEqual(response.data['rating']['rating'], '8.0')
     self.assertTrue(Rating.objects.exists())
     self.assertEqual(Rating.objects.get().rating, float(data['note']))
Exemple #10
0
 def test_update_prize_with_new_round(self):
     from ..api import PrizeEndpoint
     from ..models import Prize, PrizeUser
     from dynamicfixtures import (
         _alice, _prize_with_whitelabel, _prize_judge, _prize_juror)
     alice = _alice()
     prize = _prize_with_whitelabel(subdomain='yellow')
     prize.rounds = 3
     prize.save()
     judge = _prize_judge(subdomain='yellow')
     juror = _prize_juror(subdomain='yellow')
     data = {
         'active_round': 2,
         'name': 'yellow',
         'rounds': 3,
         'active': False,
         'subdomain': 'yellow',
         'num_submissions': None,
     }
     url = reverse('api:prize:prize-detail',
                   kwargs={'pk': prize.pk})
     view = PrizeEndpoint.as_view({'put': 'update'})
     factory = APIRequestFactory()
     request = factory.put(url, data=data, format='json')
     force_authenticate(request, user=alice)
     self.assertEqual(prize.active_round, 1)
     self.assertTrue(judge.is_judge)
     self.assertTrue(juror.is_jury)
     response = view(request, pk=prize.pk)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(response.data['active_round'], 2)
     self.assertEqual(Prize.objects.get(pk=prize.pk).active_round, 2)
     judge = PrizeUser.objects.get(pk=judge.pk)
     self.assertFalse(judge.is_judge)
     self.assertFalse(judge.is_jury)
     juror = PrizeUser.objects.get(pk=juror.pk)
     self.assertFalse(juror.is_jury)
     self.assertFalse(juror.is_judge)