Skip to content

Commit

Permalink
Merge pull request #201 from UnitapApp/feature/reversed-constraint
Browse files Browse the repository at this point in the history
Feature/reversed constraint
  • Loading branch information
ShayanShiravani authored Nov 30, 2023
2 parents dc89de5 + 40649ac commit e5c27bb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions prizetap/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class Meta:
"raffleId",
"constraints",
"constraint_params",
"reversed_constraints",
"created_at",
"start_at",
"deadline",
Expand Down
21 changes: 21 additions & 0 deletions prizetap/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,27 @@ def test_get_raffle_constraints_when_is_verified(self):
self.assertEqual(data["pk"], self.meet_constraint.pk)
self.assertEqual(data["is_verified"], True)

@patch(
"authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status",
lambda a, b, c: (True, None),
)
def test_get_raffle_constraints_when_constraint_is_reversed(self):
self.client.force_authenticate(user=self.user_profile.user)
self.raffle.reversed_constraints = str(self.meet_constraint.pk)
self.raffle.save()
response = self.client.get(reverse("get-raffle-constraints", kwargs={"raffle_pk": self.raffle.pk}))
data = response.data["constraints"][0]
self.assertEqual(response.status_code, 200)
self.assertEqual(data["pk"], self.meet_constraint.pk)
self.assertEqual(data["is_verified"], False)

BrightIDSoulboundAPIInterface.get_verification_status = MagicMock(return_value=(False, None))
response = self.client.get(reverse("get-raffle-constraints", kwargs={"raffle_pk": self.raffle.pk}))
data = response.data["constraints"][0]
self.assertEqual(response.status_code, 200)
self.assertEqual(data["pk"], self.meet_constraint.pk)
self.assertEqual(data["is_verified"], True)


class RaffleEntryTestCase(RaffleTestCase):
def setUp(self):
Expand Down
9 changes: 7 additions & 2 deletions prizetap/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def get(self, request, raffle_pk):
except Exception:
param_values = {}

reversed_constraints = raffle.reversed_constraints.split(",") if raffle.reversed_constraints else []
response_constraints = []

for c in raffle.constraints.all():
Expand All @@ -155,8 +156,12 @@ def get(self, request, raffle_pk):
except KeyError:
pass
is_verified = False
if constraint.is_observed():
is_verified = True
if str(c.pk) in reversed_constraints:
if not constraint.is_observed():
is_verified = True
else:
if constraint.is_observed():
is_verified = True
response_constraints.append({**ConstraintSerializer(c).data, "is_verified": is_verified})

return Response({"success": True, "constraints": response_constraints}, status=200)
Expand Down

0 comments on commit e5c27bb

Please sign in to comment.