From f70b1a7ce58f06c9143eac56e0cfc82effb2e627 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Sun, 17 Feb 2019 14:30:29 +0100 Subject: [PATCH] fixed RQ issue - bg tasks now working on linux notebook --- rowers/braintreestuff.py | 14 +++- rowers/tasks.py | 4 +- rowers/tests/test_permissions.py | 101 ++++++++++++++++++++++++++ rowers/tests/testdata/testdata.csv.gz | Bin 12525 -> 12525 bytes rowers/utils.py | 5 +- rowsandall_app/settings.py | 6 ++ 6 files changed, 124 insertions(+), 6 deletions(-) diff --git a/rowers/braintreestuff.py b/rowers/braintreestuff.py index 4de44b42..68dead51 100644 --- a/rowers/braintreestuff.py +++ b/rowers/braintreestuff.py @@ -171,9 +171,17 @@ def update_subscription(rower,data,method='up'): ) if rower.paidplan != 'coach': - coachees = Rower.objects.filter(coach__in=[rower]).distinct() - for coachee in coachees: - coachee.coaches.remove(rower) + try: + coachgroup = coach.mycoachgroup + except CoachingGroup.DoesNotExist: + coachgroup = CoachingGroup() + coachgroup.save() + rower.mycoachgroup = coachgroup + rower.save() + + athletes = Rower.objects.filter(coachinggroups__in=[rower.mycoachgroup]).distinct() + for athlete in athletes: + athlete.coachinggroups.remove(rower.mycoachgroup) if method == 'up': transactions = result.subscription.transactions diff --git a/rowers/tasks.py b/rowers/tasks.py index 21531d98..fefe1b29 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -1705,7 +1705,7 @@ def handle_sendemail_coachrequest(email,name,code,coachname, fullemail = email subject = 'Invitation to add {n} to your athletes'.format(n=name) - + from_email = 'Rowsandall ' siteurl = SITE_URL if debug: siteurl = SITE_URL_DEV @@ -1731,7 +1731,7 @@ def handle_sendemail_coacheerequest(email,name,code,coachname, fullemail = email subject = '{n} asks coach access to your data on rowsandall.com'.format(n=coachname) - + from_email = 'Rowsandall ' siteurl = SITE_URL if debug: siteurl = SITE_URL_DEV diff --git a/rowers/tests/test_permissions.py b/rowers/tests/test_permissions.py index 72c43ff1..af9101ae 100644 --- a/rowers/tests/test_permissions.py +++ b/rowers/tests/test_permissions.py @@ -999,6 +999,107 @@ class PermissionsViewTests(TestCase): status_code=302,target_status_code=200) +@override_settings(TESTING=True) +class PermissionsCoachingTests(TestCase): + def setUp(self): + self.c = Client() + ## Users - Pro, Basic, Coach & Self Coach + + self.ucoach = UserFactory(username='coachuser') + self.rcoach = Rower.objects.create(user=self.ucoach, + birthdate=faker.profile()['birthdate'], + gdproptin=True,gdproptindate=timezone.now(), + rowerplan='coach') + + self.ucoach_workouts = WorkoutFactory.create_batch(5, user=self.rcoach) + self.coachinggroup = CoachingGroup.objects.create() + self.rcoach.mycoachgroup = self.coachinggroup + self.rcoach.save() + self.factory = RequestFactory() + self.password = faker.word() + self.ucoach.set_password(self.password) + self.ucoach.save() + + self.uplan = UserFactory(username='planuser') + self.rplan = Rower.objects.create(user=self.uplan, + birthdate=faker.profile()['birthdate'], + gdproptin=True,gdproptindate=timezone.now(), + rowerplan='plan') + + self.uplan_workouts = WorkoutFactory.create_batch(5, user=self.rplan) + self.factory = RequestFactory() + self.password = faker.word() + self.uplan.set_password(self.password) + self.uplan.save() + + self.upro = UserFactory(username='prouser') + self.rpro = Rower.objects.create(user=self.upro, + birthdate=faker.profile()['birthdate'], + gdproptin=True,gdproptindate=timezone.now(), + rowerplan='pro') + + self.upro_workouts = WorkoutFactory.create_batch(5, user=self.rpro) + self.factory = RequestFactory() + self.password = faker.word() + self.upro.set_password(self.password) + self.upro.save() + + self.uplan2 = UserFactory(username='planuser2') + self.rplan2 = Rower.objects.create(user=self.uplan2, + birthdate=faker.profile()['birthdate'], + gdproptin=True,gdproptindate=timezone.now(), + rowerplan='plan') + + self.uplan2_workouts = WorkoutFactory.create_batch(5, user=self.rplan2) + self.factory = RequestFactory() + self.password = faker.word() + self.uplan2.set_password(self.password) + self.uplan2.save() + + self.upro2 = UserFactory(username='prouser2') + self.rpro2 = Rower.objects.create(user=self.upro2, + birthdate=faker.profile()['birthdate'], + gdproptin=True,gdproptindate=timezone.now(), + rowerplan='pro') + + self.upro2_workouts = WorkoutFactory.create_batch(5, user=self.rpro2) + self.factory = RequestFactory() + self.password = faker.word() + self.upro2.set_password(self.password) + self.upro2.save() + + self.ubasic = UserFactory(username='basicuser') + self.rbasic = Rower.objects.create(user=self.ubasic, + birthdate=faker.profile()['birthdate'], + gdproptin=True,gdproptindate=timezone.now(), + rowerplan='basic') + + self.ubasic_workouts = WorkoutFactory.create_batch(5, user=self.rbasic) + self.factory = RequestFactory() + self.password = faker.word() + self.ubasic.set_password(self.password) + self.ubasic.save() + + + + ## TeamPro, TeamCoach, TeamSelfCoach + + self.teampro = Team.objects.create( + name=faker.word()+'1', + notes=faker.text(), + manager=self.upro2) + + self.teamplan = Team.objects.create( + name=faker.word()+'2', + notes=faker.text(), + manager=self.uplan2) + + self.teamcoach = Team.objects.create( + name=faker.word()+'3', + notes=faker.text(), + manager=self.ucoach) + + # coach related ## coach disappears from list when downgrading diff --git a/rowers/tests/testdata/testdata.csv.gz b/rowers/tests/testdata/testdata.csv.gz index ce0b4dd78ecdd2dd12ad16a99b77568039f6de05..aa231cedb35e3f7e218f7559f7e3834af3d3c80c 100644 GIT binary patch delta 15 WcmaEx_%@MEzMF%i&SE3ma{~Y~hy~#Q delta 15 WcmaEx_%@MEzMF%?#b6`ba{~Y}1O=Y} diff --git a/rowers/utils.py b/rowers/utils.py index 3cc90707..11905555 100644 --- a/rowers/utils.py +++ b/rowers/utils.py @@ -298,11 +298,14 @@ def myqueue(queue,function,*args,**kwargs): if settings.TESTING: return MockJob() - if settings.DEBUG: + if settings.CELERY: kwargs['debug'] = True job = function.delay(*args,**kwargs) else: + if settings.DEBUG: + kwargs['debug'] = True + job_id = str(uuid.uuid4()) kwargs['job_id'] = job_id kwargs['jobkey'] = job_id diff --git a/rowsandall_app/settings.py b/rowsandall_app/settings.py index 9b66387d..145a972b 100644 --- a/rowsandall_app/settings.py +++ b/rowsandall_app/settings.py @@ -467,3 +467,9 @@ try: OPAQUE_SECRET_KEY = CFG['opaque_secret_key'] except KeyError: OPAQUE_SECRET_KEY = 0xa193443a + +# Celery or RQ +try: + CELERY = CFG['use_celery'] +except KeyError: + CELERY = False