def test_update_post_several_times_updates_edited_property(self, mock): # PREPARE DATA post = Post.objects.create_announcement_post( user_from=self.user, title=' '.join(faker.words()), description=faker.text(), ) post.action_update(self.user) edit_action = post.action_object_actions.filter( verb=settings.FORUM_ACTION_EDIT_POST).first() edit_action.timestamp = decrease_date( seconds=settings.FORUM_NEW_POST_DELAY * 3) edit_action.save() # DO ACTION post.action_update(self.super_user) datetime_updated = decrease_date( seconds=settings.FORUM_NEW_POST_DELAY * 2) last_edit_action = post.action_object_actions.filter( verb=settings.FORUM_ACTION_EDIT_POST).first() last_edit_action.timestamp = datetime_updated last_edit_action.save() # ASSERTS self.assertEqual(last_edit_action.timestamp.time(), post.edited.timestamp.time())
def create_initial_reminder(instance): if instance.start_at < timezone.now(): return scheduled_time = decrease_date(days=1, date=instance.start_at) ReminderOneDayBeforeTask().s(qa_session=instance.pk).apply_async( eta=scheduled_time) scheduled_time2 = decrease_date(seconds=3600, date=instance.start_at) ReminderOneHourBeforeTask().s(qa_session=instance.pk).apply_async( eta=scheduled_time2) scheduled_time5 = increase_date(seconds=3600, date=instance.end_at) SummaryOneHourAfterTask().s(qa_session=instance.pk).apply_async( eta=scheduled_time5)
def setUp(self): self.create_user() self.create_superuser() FakeConsultantFactory.create( user=self.user, ) self.sprint_automated = FakeSprintAutomatedFactory.create( status=settings.PROJECT_CH_PROJECT_STATUS_DRAFT, start=decrease_date(days=1), created_by=self.user)
def test_update_post_before_post_delay_is_not_edited(self, mock): # PREPARE DATA post = Post.objects.create_announcement_post( user_from=self.user, title=' '.join(faker.words()), description=faker.text(), ) # DO ACTION post.action_update(self.user) edit_action = post.action_object_actions.filter( verb=settings.FORUM_ACTION_EDIT_POST).first() is_not_edited_timelapse = settings.FORUM_NEW_POST_DELAY - 10 edit_action.timestamp = decrease_date(seconds=is_not_edited_timelapse) edit_action.save() # ASSERTIONS self.assertIsNone(post.edited)
def send_weekly(self, user): results = { 'circles': [], 'short_name': user.short_name, 'disable_notification_url': '', 'public_url': settings.FRONTEND_CIRCLES_PAGE, } circles = following(user, Circle) start_at = decrease_date(days=7) end_at = timezone.now() has_data_to_send = False for circle in circles: posts = Post.objects.filter_by_circle(circle).filter( created__gte=start_at, created__lte=end_at).count() replies = Answer.objects.filter_by_circle(circle).filter( created__gte=start_at, created__lte=end_at).count() if posts or replies: has_data_to_send = True circle_data = { 'name': circle.name, 'image': circle.image, 'new_topics': posts, 'new_replies': replies } results['circles'].append(circle_data) results[ 'new_announcements'] = Post.objects.filter_by__type_announcement( ).filter(created__gte=start_at, created__lte=end_at).count() if results['new_announcements']: has_data_to_send = True results['new_questions'] = Post.objects.filter_by__type_project( ).filter(created__gte=start_at, created__lte=end_at).count() user_answers = Answer.objects.filter( created_by=user, post___type=settings.FORUM_CH_PROJECT).filter( created__gte=start_at, created__lte=end_at) results['your_answers'] = user_answers.count() results['your_rating'] = user_answers.aggregate( avg=Avg('ratings__rating'))['avg'] if results['new_questions']: has_data_to_send = True if has_data_to_send: handlers.mail_handler.send_mail('ecosystem_weekly_summary', recipients=[user.email], **results)
def test_update_post_1_hour_after_created(self, mock): # PREPARE DATA post = Post.objects.create_announcement_post( user_from=self.user, title=' '.join(faker.words()), description=faker.text(), ) # DO ACTION post.action_update(self.user) datetime_updated = decrease_date(seconds=3600) edit_action = post.action_object_actions.filter( verb=settings.FORUM_ACTION_EDIT_POST).first() edit_action.timestamp = datetime_updated edit_action.save() # ASSERTS self.assertIsNotNone(post.edited) self.assertEqual(edit_action.timestamp, datetime_updated)
def test_pending_guest_application_consultant(self, mock_request, mock_recaptcha, mock_email): # PREPARE DATA mock_request.register_uri('POST', get_root_payments_url() + settings.EXO_CERTIFICATION_PAYMENTS_API_URL, json=get_payment_mock()) url = reverse('api:exo-certification:applications-list') payload = self.generate_data() coupon = FakeCouponFactory.create( expiry_date=decrease_date(days=2, date=timezone.now().today()), certification=self.cohort_lvl_2.certification, ) payload['coupon'] = coupon.code # DO ACTION response = self.client.post(url, data=payload) # ASSERTS self.assertTrue(status.is_client_error(response.status_code)) data = response.json() self.assertIsNotNone(data.get('coupon'))
def test_valid_dates(self): self.project.start = timezone.now() self.project.end = decrease_date(days=10) with self.assertRaises(ValidationError): self.project.full_clean()