Skip to content

Commit

Permalink
remove targetamount field from Event, migrate it to Milestones
Browse files Browse the repository at this point in the history
[#188794734]
  • Loading branch information
uraniumanchor committed Jan 18, 2025
1 parent 8e79e7d commit 14e2868
Show file tree
Hide file tree
Showing 22 changed files with 47 additions and 67 deletions.
1 change: 0 additions & 1 deletion bundles/tracker/events/EventActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function eventFromAPIEvent({ pk, fields }: { pk: number; fields: { [field: strin
paypalEmail: fields.paypalemail,
paypalCurrency: fields.paypalcurrency,
paypalImgurl: fields.paypalimgurl,
targetAmount: CurrencyUtils.parseCurrencyForced(fields.targetamount),
allowDonations: fields.allow_donations,
minimumDonation: CurrencyUtils.parseCurrencyForced(fields.minimumdonation),
autoApproveThreshold: CurrencyUtils.parseCurrency(fields.auto_approve_threshold),
Expand Down
1 change: 0 additions & 1 deletion bundles/tracker/events/EventTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export type Event = {
paypalEmail: string;
paypalCurrency: string;
paypalImgurl: string;
targetAmount: number;
allowDonations: boolean;
minimumDonation: number;
autoApproveThreshold?: number;
Expand Down
1 change: 0 additions & 1 deletion spec/fixtures/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export function getFixtureEvent(overrides?: Partial<Event>): Event {
paypalEmail: 'paypal@example.com',
paypalCurrency: 'USB',
paypalImgurl: '',
targetAmount: 5000,
allowDonations: true,
minimumDonation: 5,
allowedPrizeCountries: [],
Expand Down
3 changes: 1 addition & 2 deletions tests/randgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ def generate_event(rand: random.Random, start_time=None):
event.datetime = start_time
event.name = random_event_name(rand)
event.short = event.name
event.targetamount = Decimal('1000.00')
event.paypalemail = 'receiver@example.com'
event.full_clean()
return event
Expand Down Expand Up @@ -655,7 +654,7 @@ def generate_milestone(
if min_amount is None:
min_amount = 1
if max_amount is None:
max_amount = event.targetamount
max_amount = 1000
if amount is None:
amount = random_amount(rand, min_amount=min_amount, max_amount=max_amount)
# TODO: this very occasionally makes a duplicate
Expand Down
2 changes: 0 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def setUp(self):
self.run1.runners.add(self.runner1)
self.event2 = models.Event.objects.create(
datetime=tomorrow_noon,
targetamount=5,
short='event2',
)
self.run5 = models.SpeedRun.objects.create(
Expand Down Expand Up @@ -499,7 +498,6 @@ def format_event(self, event):
receiver_short=event.receiver_short,
receivername=event.receivername,
short=event.short,
targetamount=event.targetamount,
timezone=str(event.timezone),
use_one_step_screening=event.use_one_step_screening,
),
Expand Down
4 changes: 2 additions & 2 deletions tests/test_bid.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ def setUp(self):
self.rand = random.Random(None)
self.event = models.Event.objects.get_or_create(
short='test',
defaults=dict(datetime=today_noon, targetamount=5),
defaults=dict(datetime=today_noon),
)[0]
self.locked_event = models.Event.objects.get_or_create(
short='locked',
locked=True,
defaults=dict(datetime=long_ago_noon, targetamount=5),
defaults=dict(datetime=long_ago_noon),
)[0]
self.run = models.SpeedRun.objects.create(
event=self.event,
Expand Down
2 changes: 0 additions & 2 deletions tests/test_consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def setUp(self):
self.donor = models.Donor.objects.create()
self.event = models.Event.objects.create(
receivername='Médecins Sans Frontières',
targetamount=1,
paypalemail='msf@example.com',
paypalcurrency='USD',
datetime=today_noon,
Expand Down Expand Up @@ -141,7 +140,6 @@ def setUp(self):
self.donor = models.Donor.objects.create()
self.event = models.Event.objects.create(
receivername='Médecins Sans Frontières',
targetamount=1,
paypalemail='msf@example.com',
paypalcurrency='USD',
datetime=today_noon,
Expand Down
2 changes: 0 additions & 2 deletions tests/test_delete_protection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def setUp(self):
short='scratch',
name='Scratch Event',
datetime=datetime.datetime(2000, 1, 1, 12, tzinfo=datetime.timezone.utc),
targetamount=1000,
)

def tearDown(self):
Expand Down Expand Up @@ -139,7 +138,6 @@ def testDeleteEvent(self):
short='delete',
name='Delete Event',
datetime=datetime.datetime(2001, 1, 1, 12),
targetamount=1000,
)
):
pass
Expand Down
4 changes: 1 addition & 3 deletions tests/test_donate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ def testAliasAnonToVisibilityAnon(self):
class TestDonateViews(TransactionTestCase):
def setUp(self):
self.normal_event = models.Event.objects.create(
targetamount=5, short='normal', name='Normal', datetime=today_noon
short='normal', name='Normal', datetime=today_noon
)
self.upcoming_event = models.Event.objects.create(
targetamount=5,
short='upcoming',
name='Upcoming',
datetime=tomorrow_noon,
allow_donations=False,
)
self.locked_event = models.Event.objects.create(
targetamount=5,
short='locked',
name='Locked',
datetime=long_ago_noon,
Expand Down
7 changes: 3 additions & 4 deletions tests/test_donation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class TestDonation(TestCase):
def setUp(self):
self.event = models.Event.objects.create(
receivername='Médecins Sans Frontières',
targetamount=1,
datetime=datetime.datetime(2018, 1, 1),
)

Expand Down Expand Up @@ -270,7 +269,7 @@ def setUp(self):
Permission.objects.get(name='Can view donation'),
)
self.event = models.Event.objects.create(
short='ev1', name='Event 1', targetamount=5, datetime=today_noon
short='ev1', name='Event 1', datetime=today_noon
)

self.donor = models.Donor.objects.create(firstname='John', lastname='Doe')
Expand Down Expand Up @@ -462,10 +461,10 @@ def setUp(self):
'admin', 'admin@example.com', 'password'
)
self.event = models.Event.objects.create(
short='ev1', name='Event 1', targetamount=5, datetime=today_noon
short='ev1', name='Event 1', datetime=today_noon
)
self.other_event = models.Event.objects.create(
short='ev2', name='Event 2', targetamount=5, datetime=tomorrow_noon
short='ev2', name='Event 2', datetime=tomorrow_noon
)
self.regular_donor = models.Donor.objects.create(
alias='JohnDoe', visibility='ALIAS'
Expand Down
10 changes: 5 additions & 5 deletions tests/test_donor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def setUp(self):
firstname='Jane', lastname='Doe', email='janedoe@example.com'
)
self.ev1 = models.Event.objects.create(
short='ev1', name='Event 1', targetamount=5, datetime=today_noon
short='ev1', name='Event 1', datetime=today_noon
)
self.ev2 = models.Event.objects.create(
short='ev2', name='Event 2', targetamount=5, datetime=today_noon
short='ev2', name='Event 2', datetime=today_noon
)

def test_donor_cache(self):
Expand Down Expand Up @@ -290,10 +290,10 @@ class TestDonorView(TestCase):
def setUp(self):
super(TestDonorView, self).setUp()
self.event = models.Event.objects.create(
name='test', targetamount=10, datetime=today_noon, short='test'
name='test', datetime=today_noon, short='test'
)
self.other_event = models.Event.objects.create(
name='test2', targetamount=10, datetime=tomorrow_noon, short='test2'
name='test2', datetime=tomorrow_noon, short='test2'
)

def set_donor(self, firstname='John', lastname='Doe', **kwargs):
Expand Down Expand Up @@ -428,7 +428,7 @@ def setUp(self):
self.super_user = User.objects.create_superuser('admin', 'admin@example.com')
self.limited_user = User.objects.create(username='staff')
self.event = models.Event.objects.create(
short='ev1', name='Event 1', targetamount=5, datetime=today_noon
short='ev1', name='Event 1', datetime=today_noon
)

self.donor = models.Donor.objects.create(firstname='John', lastname='Doe')
Expand Down
16 changes: 4 additions & 12 deletions tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
class TestEvent(TestCase):
def setUp(self):
self.rand = make_rand()
self.event = models.Event.objects.create(
targetamount=1, datetime=today_noon, short='test'
)
self.event = models.Event.objects.create(datetime=today_noon, short='test')
self.run = models.SpeedRun.objects.create(
event=self.event,
starttime=today_noon,
Expand Down Expand Up @@ -107,7 +105,7 @@ def test_manager_current(self):
self.event.datetime = today_noon
self.event.save()
overlap_event = models.Event.objects.create(
targetamount=1, datetime=today_noon, short='test2'
datetime=today_noon, short='test2'
)
models.SpeedRun.objects.create(
event=overlap_event,
Expand Down Expand Up @@ -136,12 +134,10 @@ def test_manager_next(self):

with self.subTest('multiple events'):
prev_event = models.Event.objects.create(
targetamount=1,
datetime=today_noon - datetime.timedelta(hours=1),
short='test2',
)
next_event = models.Event.objects.create(
targetamount=1,
datetime=today_noon + datetime.timedelta(hours=1),
short='test4',
)
Expand Down Expand Up @@ -191,7 +187,7 @@ def test_prev_and_next(self):
class TestEventManager(TransactionTestCase):
def setUp(self):
self.rand = random.Random()
self.event = models.Event.objects.create(targetamount=1, datetime=today_noon)
self.event = models.Event.objects.create(datetime=today_noon)
self.completed_donations = randgen.generate_donations(
self.rand,
self.event,
Expand Down Expand Up @@ -225,7 +221,7 @@ def test_amount_annotation(self):
class TestEventViews(TransactionTestCase):
def setUp(self):
self.event = models.Event.objects.create(
targetamount=1, datetime=today_noon, short='short', name='Short'
datetime=today_noon, short='short', name='Short'
)

@override_settings(TRACKER_LOGO='example-logo.png')
Expand Down Expand Up @@ -263,7 +259,6 @@ def test_json_with_no_donations(self):
'count': 0,
'max': 0.0,
'median': 0.0,
'target': 1.0,
},
},
)
Expand All @@ -289,7 +284,6 @@ def test_json_with_only_pending_donations(self):
'count': 0,
'max': 0.0,
'median': 0.0,
'target': 1.0,
},
},
)
Expand Down Expand Up @@ -320,7 +314,6 @@ def test_json_with_cleared_donations(self):
'count': 2,
'max': 10.0,
'median': 7.5,
'target': 1.0,
},
},
)
Expand All @@ -333,7 +326,6 @@ def setUp(self):
)
timezone = zoneinfo.ZoneInfo(settings.TIME_ZONE)
self.event = models.Event.objects.create(
targetamount=5,
datetime=today_noon,
timezone=timezone,
name='test event',
Expand Down
1 change: 0 additions & 1 deletion tests/test_eventutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def setUp(self):
self.donor = Donor.objects.create()
self.event = Event.objects.create(
receivername='Médecins Sans Frontières',
targetamount=1,
paypalemail='msf@example.com',
paypalcurrency='USD',
datetime=datetime.datetime(2018, 1, 1),
Expand Down
4 changes: 3 additions & 1 deletion tests/test_headset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def setUpBeforeMigration(self, apps):
SpeedRun = apps.get_model('tracker', 'SpeedRun')
HostSlot = apps.get_model('tracker', 'HostSlot')
self.event = Event.objects.create(
short='test', name='Test Event', datetime=today_noon, targetamount=100
short='test',
name='Test Event',
datetime=today_noon,
)
self.run1 = SpeedRun.objects.create(
event=self.event, name='Test Run 1', order=1, run_time='0:05:00'
Expand Down
8 changes: 2 additions & 6 deletions tests/test_interstitial.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@

class TestInterstitial(TestCase):
def setUp(self):
self.event1 = models.Event.objects.create(
short='test1', datetime=today_noon, targetamount=5
)
self.event2 = models.Event.objects.create(
short='test2', datetime=today_noon, targetamount=5
)
self.event1 = models.Event.objects.create(short='test1', datetime=today_noon)
self.event2 = models.Event.objects.create(short='test2', datetime=today_noon)
self.run1 = models.SpeedRun.objects.create(
event=self.event1, name='Test Run 1', order=1
)
Expand Down
21 changes: 20 additions & 1 deletion tests/test_milestone.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from tracker.models import Milestone

from . import randgen
from .util import APITestCase, today_noon
from .util import APITestCase, MigrationsTestCase, today_noon, tomorrow_noon


class TestMilestone(APITestCase):
Expand Down Expand Up @@ -64,3 +64,22 @@ def test_milestone_list(self):
)
self.assertContains(resp, self.visible_milestone.name)
self.assertNotContains(resp, self.invisible_milestone.name)


class TestMilestoneTargetMigration(MigrationsTestCase):
migrate_from = (('tracker', '0052_delete_interview_text_columns'),)
migrate_to = (('tracker', '0054_delete_event_targetamount'),)

def setUpBeforeMigration(self, apps):
Event = apps.get_model('tracker', 'Event')
Event.objects.create(
name='Test', short='test', targetamount=500, datetime=today_noon
)
Event.objects.create(
name='Empty Test', short='empty', targetamount=0, datetime=tomorrow_noon
)

def test_milestone_created(self):
Milestone = self.apps.get_model('tracker', 'Milestone')
self.assertEqual(Milestone.objects.count(), 1)
self.assertEqual(Milestone.objects.first().amount, 500)
4 changes: 2 additions & 2 deletions tests/test_mod_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestWordFilter(TransactionTestCase):
def setUp(self):
self.filter = models.WordFilter.objects.create(word='hype')
self.event = models.Event.objects.create(
short='ev1', name='Event 1', targetamount=5, datetime=today_noon
short='ev1', name='Event 1', datetime=today_noon
)

def testRejectionOfWordMatch(self):
Expand Down Expand Up @@ -52,7 +52,7 @@ class TestAmountFilter(TransactionTestCase):
def setUp(self):
self.filter = models.AmountFilter.objects.create(amount=Decimal('4.20'))
self.event = models.Event.objects.create(
short='ev1', name='Event 1', targetamount=5, datetime=today_noon
short='ev1', name='Event 1', datetime=today_noon
)

def testRejectionOfAmountMatch(self):
Expand Down
7 changes: 2 additions & 5 deletions tests/test_speedrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ class TestSpeedRunBase(TransactionTestCase):
def setUp(self):
super().setUp()
if not hasattr(self, 'event'):
self.event = models.Event.objects.create(
datetime=today_noon, targetamount=5
)
self.event = models.Event.objects.create(datetime=today_noon)
self.run1 = models.SpeedRun.objects.create(
event=self.event,
name='Test Run',
Expand Down Expand Up @@ -189,7 +187,7 @@ def test_tags(self):

class TestMoveSpeedRun(TransactionTestCase):
def setUp(self):
self.event1 = models.Event.objects.create(datetime=today_noon, targetamount=5)
self.event1 = models.Event.objects.create(datetime=today_noon)
self.run1 = models.SpeedRun.objects.create(
name='Test Run 1', run_time='0:45:00', setup_time='0:05:00', order=1
)
Expand Down Expand Up @@ -385,7 +383,6 @@ class TestSpeedRunAdmin(TransactionTestCase):
def setUp(self):
self.event1 = models.Event.objects.create(
datetime=today_noon,
targetamount=5,
timezone=zoneinfo.ZoneInfo(
getattr(settings, 'TIME_ZONE', 'America/Denver')
),
Expand Down
Loading

0 comments on commit 14e2868

Please sign in to comment.