def test_draft_study_group_actions_disabled(self, handle_new_facilitator): user = create_user('*****@*****.**', 'bob', 'test', 'password', False) confirm_user_email(user) c = Client() c.login(username='******', password='******') with freeze_time('2018-07-20'): resp = c.post('/api/learning-circle/', data=json.dumps(self.STUDY_GROUP_DATA), content_type='application/json') self.assertEqual(resp.json()['status'], 'created') study_groups = StudyGroup.objects.filter(facilitator=user) self.assertEqual(study_groups.count(), 1) self.assertEqual(study_groups.first().meeting_set.count(), 6) # can add a meeting self.assertEqual(study_groups.first().pk, StudyGroup.objects.last().pk) url_base = '/en/studygroup/{0}'.format(study_groups.first().pk) resp = c.get(url_base + '/meeting/create/') self.assertEqual(resp.status_code, 200) meeting_data = { "meeting_date": "2018-03-17", "meeting_time": "04:00 PM", "study_group": study_groups.first().pk, } resp = c.post(url_base + '/meeting/create/', data=meeting_data) self.assertRedirects(resp, url_base + '/') self.assertEqual(StudyGroup.objects.last().meeting_set.count(), 7) expected_redirect_url = '/en/studygroup/{0}/'.format( study_groups.first().pk) # cannot send a message resp = c.get('/en/studygroup/{0}/message/compose/'.format( study_groups.first().pk)) self.assertRedirects(resp, expected_redirect_url) mail_data = { u'study_group': study_groups.first().pk, u'email_subject': 'does not matter', u'email_body': 'does not matter', } mail.outbox = [] resp = c.post(url_base + '/message/compose/', mail_data) self.assertRedirects(resp, expected_redirect_url) self.assertEqual(len(mail.outbox), 0) # cannot add a learner resp = c.get('/en/studygroup/{0}/member/add/'.format( study_groups.first().pk)) self.assertRedirects(resp, expected_redirect_url) learner_data = { "email": "*****@*****.**", "name": "no name", "study_group": "515", } resp = c.post(url_base + '/member/add/', data=learner_data) self.assertRedirects(resp, expected_redirect_url) self.assertEqual(StudyGroup.objects.last().application_set.count(), 0)
def test_publish_learning_circle(self): user_data = { "email": "*****@*****.**", "first_name": "Ted", "last_name": "Danson", "password": "******" } facilitator = create_user(user_data["email"], user_data["first_name"], user_data["last_name"], user_data["password"]) confirm_user_email(facilitator) self.driver.get('%s%s' % (self.live_server_url, '/en/studygroup/create/')) creation_page = LearningCircleCreationPage(self.driver, self.wait) creation_page.fill_out_form_correctly() creation_page.click_publish_button() self.assertTrue( expected_conditions.visibility_of_element_located( RegistrationModalLocators.REGISTRATION_MODAL)) creation_page.click_login_link() self.assertTrue( expected_conditions.text_to_be_present_in_element( RegistrationModalLocators.REGISTRATION_MODAL_TITLE, 'Log in')) creation_page.fill_out_login_modal(user_data) self.assertTrue(expected_conditions.alert_is_present()) self.assertTrue( expected_conditions.text_to_be_present_in_element( LearningCircleCreationPageLocators.SUCCESS_ALERT, "You're logged in! You can now save or publish your learning circle." )) overlay = self.driver.find_element( *RegistrationModalLocators.MODAL_OVERLAY) self.wait.until(expected_conditions.staleness_of(overlay)) creation_page.click_publish_button() data = self.driver.get_log('browser') self.wait.until( expected_conditions.url_changes( '%s%s' % (self.live_server_url, '/en/studygroup/create/'))) published_studygroup = StudyGroup.objects.published().last() self.assertEqual(published_studygroup.facilitator, facilitator) self.assertTrue( expected_conditions.url_to_be('{}/en/studygroup/{}/'.format( self.live_server_url, published_studygroup.id)))
def test_publish_study_group(self, handle_new_facilitator): user = create_user('*****@*****.**', 'bob', 'test', 'password', False) confirm_user_email(user) c = Client() c.login(username='******', password='******') with freeze_time('2018-07-20'): resp = c.post('/api/learning-circle/', data=json.dumps(self.STUDY_GROUP_DATA), content_type='application/json') self.assertEqual(resp.json()['status'], 'created') study_groups = StudyGroup.objects.filter(facilitator=user) self.assertEqual(study_groups.count(), 1) lc = study_groups.first() self.assertEqual(lc.meeting_set.count(), 6) resp = c.post('/en/studygroup/{0}/publish/'.format(lc.pk)) self.assertRedirects(resp, '/en/studygroup/{0}/'.format(lc.pk)) study_group = StudyGroup.objects.get(pk=lc.pk) self.assertEqual(study_group.draft, False) self.assertEqual(study_group.meeting_set.count(), 6)
def test_study_group_unicode_venue_name(self, handle_new_facilitator): user = create_user('*****@*****.**', 'bob', 'test', 'password', False) confirm_user_email(user) c = Client() c.login(username='******', password='******') sgd = self.STUDY_GROUP_DATA.copy() sgd['draft'] = False sgd['venue_name'] = 'Быстрее и лучше' sgd['start_date'] = (datetime.datetime.now() + datetime.timedelta(weeks=2)).date().isoformat() resp = c.post('/api/learning-circle/', data=json.dumps(sgd), content_type='application/json') self.assertEqual(resp.json()['status'], 'created') study_groups = StudyGroup.objects.filter(facilitator=user) self.assertEqual(study_groups.count(), 1) self.assertEqual(study_groups.first().meeting_set.count(), 6) resp = c.get('/en/facilitator/') self.assertEqual(resp.status_code, 200) self.assertIn( '/en/signup/%D0%B1%D1%8B%D1%81%D1%82%D1%80%D0%B5%D0%B5-%D0%B8-%D0%BB%D1%83%D1%87%D1%88%D0%B5-', resp.content.decode("utf-8"))
def test_edit_meeting(self, current_app): # Create studygroup user = create_user('*****@*****.**', 'bob', 'test', 'password', False) confirm_user_email(user) c = Client() c.login(username='******', password='******') with freeze_time('2018-07-20'): resp = c.post('/api/learning-circle/', data=json.dumps(self.STUDY_GROUP_DATA), content_type='application/json') self.assertEqual(resp.json()['status'], 'created') study_groups = StudyGroup.objects.filter(facilitator=user) self.assertEqual(study_groups.count(), 1) lc = study_groups.first() self.assertEqual(lc.meeting_set.count(), 6) resp = c.post('/en/studygroup/{0}/publish/'.format(lc.pk)) self.assertRedirects(resp, '/en/studygroup/{0}/'.format(lc.pk)) study_group = StudyGroup.objects.get(pk=lc.pk) self.assertEqual(study_group.draft, False) self.assertEqual(study_group.meeting_set.count(), 6) self.assertEqual(study_group.reminder_set.count(), 6) # update 1st meeting with unsent reminder meeting = study_group.meeting_set.order_by('meeting_date').first() meeting_id = meeting.pk old_reminder_body = meeting.reminder_set.first().email_body update = { "meeting_date": "2018-07-26", "meeting_time": "07:00 PM", "study_group": study_group.pk, } with freeze_time('2018-07-20'): resp = c.post( '/en/studygroup/{0}/meeting/{1}/edit/'.format( study_group.pk, meeting.pk), update) self.assertRedirects(resp, '/en/studygroup/{}/'.format(study_group.pk)) meeting.refresh_from_db() self.assertEqual(meeting.meeting_date, datetime.date(2018, 7, 26)) current_app.send_task.assert_not_called( ) # no meeting change notification sent self.assertNotEqual(meeting.reminder_set.first().email_body, old_reminder_body) # reminder regenerated self.assertEqual(study_group.reminder_set.count(), 6) # send it with freeze_time('2018-07-25'): self.assertEqual( Reminder.objects.filter(study_group=study_group, sent_at__isnull=False).count(), 0) send_reminders() self.assertEqual( Reminder.objects.filter(study_group=study_group, sent_at__isnull=False).count(), 1) # and then update it afterwards to be in the future again with freeze_time('2018-07-27'): meeting.refresh_from_db() self.assertTrue(meeting.meeting_datetime() < timezone.now()) self.assertEquals(Reminder.objects.count(), 6) update['meeting_date'] = '2018-07-30' resp = c.post( '/en/studygroup/{0}/meeting/{1}/edit/'.format( study_group.pk, meeting.pk), update) self.assertRedirects(resp, '/en/studygroup/{}/'.format(study_group.pk)) meeting.refresh_from_db() self.assertFalse( current_app.send_task.called ) # meeting change notification should not be sent self.assertEquals(Reminder.objects.count(), 7) # old reminder is kept # update it before the meeting to be further in the future with freeze_time('2018-07-29'): meeting.refresh_from_db() self.assertTrue(meeting.meeting_datetime() > timezone.now()) send_reminders() update['meeting_date'] = '2019-08-02' resp = c.post( '/en/studygroup/{0}/meeting/{1}/edit/'.format( study_group.pk, meeting.pk), update) self.assertRedirects(resp, '/en/studygroup/{}/'.format(study_group.pk)) meeting.refresh_from_db() current_app.send_task.assert_called_once( ) # meeting change notification should be sent self.assertEquals(meeting.reminder_set.count(), 1) self.assertEquals(Reminder.objects.count(), 8) # old reminder should be kept
def test_update_study_group_legacy_view(self): user = create_user('*****@*****.**', 'bob', 'test', 'password', False) confirm_user_email(user) c = Client() c.login(username='******', password='******') data = self.STUDY_GROUP_DATA.copy() data['start_date'] = '12/25/2018' data['meeting_time'] = '07:00 PM' with freeze_time("2018-12-20"): resp = c.post('/en/studygroup/create/legacy/', data) sg = StudyGroup.objects.last() self.assertRedirects(resp, '/en/studygroup/{}/'.format(sg.pk)) study_groups = StudyGroup.objects.filter(facilitator=user) self.assertEquals(study_groups.count(), 1) lc = study_groups.first() self.assertEquals(study_groups.first().meeting_set.active().count(), 6) # updates allowed for drafts with freeze_time("2018-12-28"): data['start_date'] = '12/25/2018' data['meeting_time'] = '07:10 PM' edit_url = '/en/studygroup/{}/edit/legacy/'.format(lc.pk) resp = c.post(edit_url, data) self.assertRedirects(resp, '/en/studygroup/{}/'.format(lc.pk)) study_group = StudyGroup.objects.get(pk=study_groups.first().pk) self.assertEqual(study_group.start_date, datetime.date(2018, 12, 25)) self.assertEqual(study_group.meeting_time, datetime.time(19, 10)) self.assertEqual(study_group.meeting_set.active().count(), 6) resp = c.post('/en/studygroup/{0}/publish/'.format(lc.pk)) self.assertRedirects(resp, '/en/studygroup/{}/'.format(lc.pk)) study_group = StudyGroup.objects.get(pk=study_groups.first().pk) self.assertEqual(study_group.draft, False) self.assertEqual(study_group.meeting_set.active().count(), 6) # update not allowed with freeze_time("2018-12-24"): data['start_date'] = '12/24/2018' data['meeting_time'] = '07:00 PM' data['weeks'] = 4 edit_url = '/en/studygroup/{}/edit/legacy/'.format(study_group.pk) resp = c.post(edit_url, data) self.assertEqual(resp.status_code, 200) study_group = StudyGroup.objects.get(pk=study_groups.first().pk) self.assertEqual(study_group.start_date, datetime.date(2018, 12, 25)) self.assertEqual(study_group.meeting_set.active().count(), 6) # update allowed with freeze_time("2018-12-22"): data['start_date'] = '12/24/2018' data['meeting_time'] = '07:00 PM' data['weeks'] = 3 edit_url = '/en/studygroup/{}/edit/legacy/'.format(study_group.pk) resp = c.post(edit_url, data) self.assertRedirects(resp, '/en/studygroup/{}/'.format(study_group.pk)) study_group = StudyGroup.objects.get(pk=study_groups.first().pk) self.assertEqual(study_group.start_date, datetime.date(2018, 12, 24)) self.assertEqual(study_group.meeting_set.active().count(), 3) meeting_times = [(meeting.meeting_date, meeting.meeting_time) for meeting in study_group.meeting_set.active().all()] self.assertEqual(meeting_times, [ (datetime.date(2018, 12, 24), datetime.time(19, 0)), (datetime.date(2018, 12, 31), datetime.time(19, 0)), (datetime.date(2019, 1, 7), datetime.time(19, 0)), ]) # missing weeks with freeze_time("2018-12-20"): del data['weeks'] resp = c.post('/en/studygroup/create/legacy/', data) self.assertEqual(resp.status_code, 200) expected_error_message = 'Please provide the length of the learning circle in weeks' self.assertFormError(resp, 'form', 'weeks', expected_error_message)
def test_edit_meeting(self, send_meeting_change_notification): # Create studygroup # generate reminder # edit meeting # make sure reminder was deleted # send reminders # edit meeting in the past to be in the future now # test reminder in now orphaned user = create_user('*****@*****.**', 'bob', 'test', 'password', False) confirm_user_email(user) c = Client() c.login(username='******', password='******') data = self.STUDY_GROUP_DATA.copy() data['start_date'] = '12/25/2018' data['meeting_time'] = '07:00 PM' resp = c.post('/en/studygroup/create/legacy/', data) sg = StudyGroup.objects.last() self.assertRedirects(resp, '/en/studygroup/{}/'.format(sg.pk)) study_groups = StudyGroup.objects.filter(facilitator=user) self.assertEquals(study_groups.count(), 1) lc = study_groups.first() self.assertEquals(lc.meeting_set.count(), 0) resp = c.post('/en/studygroup/{0}/publish/'.format(lc.pk)) self.assertRedirects(resp, '/en/studygroup/{}/'.format(lc.pk)) study_group = StudyGroup.objects.get(pk=lc.pk) self.assertEqual(study_group.draft, False) self.assertEqual(study_group.meeting_set.count(), 6) # generate reminder for first meeting (< 4 days before 25 Dec) with freeze_time('2018-12-22'): generate_reminder(study_group) self.assertEqual( Reminder.objects.filter(study_group=study_group).count(), 1) # update meeting with unsent reminder reminder = Reminder.objects.filter(study_group=study_group).first() meeting = reminder.study_group_meeting meeting_id = meeting.pk update = { "meeting_date": "2018-12-27", "meeting_time": "07:00 PM", "study_group": study_group.pk, } resp = c.post( '/en/studygroup/{0}/meeting/{1}/edit/'.format( study_group.pk, meeting.pk), update) self.assertRedirects(resp, '/en/studygroup/{}/'.format(study_group.pk)) meeting.refresh_from_db() self.assertEqual(meeting.meeting_date, datetime.date(2018, 12, 27)) # make sure the reminder was deleted self.assertEqual( Reminder.objects.filter(study_group=study_group).count(), 0) # generate a reminder for the updated meeting with freeze_time('2018-12-24'): generate_reminder(study_group) self.assertEqual( Reminder.objects.filter(study_group=study_group).count(), 1) # send it with freeze_time('2018-12-26'): self.assertEqual( Reminder.objects.filter(study_group=study_group, sent_at__isnull=False).count(), 0) send_reminders() self.assertEqual( Reminder.objects.filter(study_group=study_group, sent_at__isnull=False).count(), 1) # and then update it afterwards to be in the future again with freeze_time('2018-12-28'): meeting.refresh_from_db() self.assertTrue(meeting.meeting_datetime() < timezone.now()) self.assertEquals(Reminder.objects.count(), 1) update['meeting_date'] = '2018-12-30' resp = c.post( '/en/studygroup/{0}/meeting/{1}/edit/'.format( study_group.pk, meeting.pk), update) self.assertRedirects(resp, '/en/studygroup/{}/'.format(study_group.pk)) meeting.refresh_from_db() self.assertFalse(send_meeting_change_notification.delay.called) # old reminder should be orphaned - not linked to this meeting self.assertEquals(meeting.reminder_set.count(), 0) generate_reminder(study_group) # now generate a reminder again meeting.refresh_from_db() self.assertEquals(meeting.reminder_set.count(), 1) self.assertEquals(Reminder.objects.count(), 2) # update it before the meeting to be further in the future with freeze_time('2018-12-29'): meeting.refresh_from_db() self.assertTrue(meeting.meeting_datetime() > timezone.now()) self.assertEqual( Reminder.objects.filter(study_group_meeting=meeting, sent_at__isnull=False).count(), 0) send_reminders() self.assertEqual( Reminder.objects.filter(study_group_meeting=meeting, sent_at__isnull=False).count(), 1) update['meeting_date'] = '2019-01-02' resp = c.post( '/en/studygroup/{0}/meeting/{1}/edit/'.format( study_group.pk, meeting.pk), update) self.assertRedirects(resp, '/en/studygroup/{}/'.format(study_group.pk)) meeting.refresh_from_db() self.assertTrue(send_meeting_change_notification.delay.called) # old reminder should be orphaned - not linked to this meeting self.assertEquals(meeting.reminder_set.count(), 0)