Skip to content

Commit

Permalink
Bulk Update and Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
shiva-menta committed Jan 24, 2024
1 parent 4ba20fb commit 77d5e8d
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
4 changes: 2 additions & 2 deletions backend/clubs/management/commands/update_club_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def handle(self, *args, **kwargs):
for club in queryset:
club.favorite_count = club.temp_favorite_count
club.membership_count = club.temp_membership_count
club.save()
Club.objects.bulk_update(queryset, ["favorite_count", "membership_count"])

self.stdout.write(
self.style.SUCCESS(
Expand All @@ -28,7 +28,7 @@ def handle(self, *args, **kwargs):
)
except Exception as e:
self.stdout.write(
self.style.SUCCESS(
self.style.ERROR(
"An error was encountered while updating"
+ "club favorite and membership counts!"
)
Expand Down
13 changes: 13 additions & 0 deletions backend/clubs/migrations/0095_merge_20240124_1227.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 3.2.18 on 2024-01-24 17:27

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("clubs", "0091_auto_20231019_1730"),
("clubs", "0094_applicationcycle_release_date"),
]

operations = []
3 changes: 0 additions & 3 deletions backend/pennclubs/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# Django Setting Environment Variable
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pennclubs.settings.base")

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

Expand Down
50 changes: 50 additions & 0 deletions backend/tests/clubs/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,3 +650,53 @@ def test_wrong_arguments(self):

with self.assertRaises(CommandError):
call_command("merge_duplicates", "--tag")


class StoredFavoritesMembershipsTestCase(TestCase):
def setUp(self):
self.club1 = Club.objects.create(code="one", name="One", active=True)
self.club2 = Club.objects.create(code="two", name="One", active=True)

self.user1 = get_user_model().objects.create_user(
"bfranklin1", "[email protected]", "test"
)
self.user2 = get_user_model().objects.create_user(
"bfranklin2", "[email protected]", "test"
)
self.user3 = get_user_model().objects.create_user(
"bfranklin3", "[email protected]", "test"
)

# Favorites
Favorite.objects.create(person=self.user1, club=self.club1)
Favorite.objects.create(person=self.user1, club=self.club2)
Favorite.objects.create(person=self.user2, club=self.club1)
Favorite.objects.create(person=self.user3, club=self.club2)

# Membership
Membership.objects.create(
club=self.club1, person=self.user1, role=Membership.ROLE_OWNER
)
Membership.objects.create(
club=self.club1, person=self.user2, role=Membership.ROLE_MEMBER
)
Membership.objects.create(
club=self.club1, person=self.user3, role=Membership.ROLE_MEMBER
)
Membership.objects.create(
club=self.club2, person=self.user2, role=Membership.ROLE_OWNER
)

def test_update_club_counts(self):
call_command("update_club_counts")

club1 = Club.objects.filter(code="one").first()
club2 = Club.objects.filter(code="two").first()

self.assertEqual(club1.favorite_count, 2)
self.assertEqual(club2.favorite_count, 2)
self.assertEqual(club1.membership_count, 3)
self.assertEqual(club2.membership_count, 1)
self.assertEqual(
Club.objects.all().order_by("-favorite_count", "name").first().code, "one"
)
2 changes: 1 addition & 1 deletion k8s/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class MyChart extends PennLabsChart {
schedule: cronTime.everyDayAt(12),
image: backendImage,
secret: fyhSecret,
cmd: ["python", "manage.py", "import_paideia_events"],
cmd: ["python", "manage.py", "update_club_counts"],
})
}
}
Expand Down

0 comments on commit 77d5e8d

Please sign in to comment.