Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes]"payment_preference" field to Member model #407

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/meshapi/migrations/0010_member_payment_preference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.db import migrations, models

class Migration(migrations.Migration):
dependencies = [
("meshapi", "0009_member_additional_phone_numbers_alter_member_phone_number"),
]

operations = [
migrations.AddField(
model_name="member",
name="payment_preference",
field=models.CharField(
choices=[
("cash", "Cash"),
("stripe", "Stripe"),
(None, "None"),
],
default=None,
help_text="Preferred payment method for this member",
null=True,
blank=True,
),
),
]
11 changes: 11 additions & 0 deletions src/meshapi/models/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@


class Member(models.Model):

class PaymentPreference(models.TextChoices):
CASH = "cash", "Cash"
STRIPE = "stripe", "Stripe"
NONE = None, "None"

name = models.CharField(help_text='Member full name in the format: "First Last"')
primary_email_address = models.EmailField(null=True, help_text="Primary email address used to contact the member")
stripe_email_address = models.EmailField(
Expand Down Expand Up @@ -41,6 +47,11 @@ class Member(models.Model):
"import process and original spreadsheet data. However this structure can be changed by admins at any "
"time and should not be relied on by automated systems. ",
)
payment_preference = models.CharField(
max_length=6,
choices=PaymentPreference.choices,
default=PaymentPreference.NONE
)

def __str__(self) -> str:
if self.name:
Expand Down
21 changes: 21 additions & 0 deletions src/meshapi/tests/test_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ def test_member_all_phone_numbers_field(self):
self.assertEqual(response_obj["additional_phone_numbers"], ["+1 456-555-6666"])
self.assertEqual(response_obj["all_phone_numbers"], ["+1 123-555-5555", "+1 456-555-6666"])

def test_member_payment_preference(self):
test_member = Member(
name="John Doe",
primary_email_address="[email protected]",
payment_preference=Member.PaymentPreference.STRIPE,
)
test_member.save()

response = self.c.get(f"/api/v1/members/{test_member.id}/")
code = 200
self.assertEqual(
code,
response.status_code,
f"status code incorrect. Should be {code}, but got {response.status_code}",
)

response_obj = json.loads(response.content)
self.assertEqual(response_obj["name"], "John Doe")
self.assertEqual(response_obj["primary_email_address"], "[email protected]")
self.assertEqual(response_obj["payment_preference"], Member.PaymentPreference.STRIPE.value)

def test_broken_member(self):
err_member = {
"id": "Error",
Expand Down
Loading