Esempio n. 1
0
    def test_send_premium_expired_notifications(self):
        self.assertEqual(PersonalMessagePrototype._db_count(), 0)

        account_1 = self.account
        account_2 = self.accounts_factory.create_account()
        account_3 = self.accounts_factory.create_account()
        account_4 = self.accounts_factory.create_account()

        account_1.prolong_premium(
            accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days - 1)
        account_1.save()

        account_3.prolong_premium(
            accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days - 1)
        account_3.save()

        account_4.prolong_premium(
            accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days + 1)
        account_4.save()

        zero_time = datetime.datetime.fromtimestamp(0)

        self.assertEqual(account_1._model.premium_expired_notification_send_at,
                         zero_time)
        self.assertEqual(account_2._model.premium_expired_notification_send_at,
                         zero_time)
        self.assertEqual(account_3._model.premium_expired_notification_send_at,
                         zero_time)
        self.assertEqual(account_4._model.premium_expired_notification_send_at,
                         zero_time)

        AccountPrototype.send_premium_expired_notifications()

        account_1.reload()
        account_2.reload()
        account_3.reload()
        account_4.reload()

        self.assertNotEqual(
            account_1._model.premium_expired_notification_send_at, zero_time)
        self.assertEqual(account_2._model.premium_expired_notification_send_at,
                         zero_time)
        self.assertNotEqual(
            account_3._model.premium_expired_notification_send_at, zero_time)
        self.assertEqual(account_4._model.premium_expired_notification_send_at,
                         zero_time)

        current_time = datetime.datetime.now()

        self.assertTrue(
            current_time - datetime.timedelta(seconds=60) < account_1._model.
            premium_expired_notification_send_at < current_time)
        self.assertTrue(
            current_time - datetime.timedelta(seconds=60) < account_3._model.
            premium_expired_notification_send_at < current_time)

        self.assertEqual(PersonalMessagePrototype._db_count(), 2)
    def test_send_premium_expired_notifications(self):
        self.assertEqual(PersonalMessagePrototype._db_count(), 0)

        register_user("test_user_2", "*****@*****.**", "111111")
        register_user("test_user_3", "*****@*****.**", "111111")
        register_user("test_user_4", "*****@*****.**", "111111")

        account_1 = self.account
        account_2 = AccountPrototype.get_by_nick("test_user_2")
        account_3 = AccountPrototype.get_by_nick("test_user_3")
        account_4 = AccountPrototype.get_by_nick("test_user_4")

        account_1.prolong_premium(accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days - 1)
        account_1.save()

        account_3.prolong_premium(accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days - 1)
        account_3.save()

        account_4.prolong_premium(accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days + 1)
        account_4.save()

        zero_time = datetime.datetime.fromtimestamp(0)

        self.assertEqual(account_1._model.premium_expired_notification_send_at, zero_time)
        self.assertEqual(account_2._model.premium_expired_notification_send_at, zero_time)
        self.assertEqual(account_3._model.premium_expired_notification_send_at, zero_time)
        self.assertEqual(account_4._model.premium_expired_notification_send_at, zero_time)

        AccountPrototype.send_premium_expired_notifications()

        account_1.reload()
        account_2.reload()
        account_3.reload()
        account_4.reload()

        self.assertNotEqual(account_1._model.premium_expired_notification_send_at, zero_time)
        self.assertEqual(account_2._model.premium_expired_notification_send_at, zero_time)
        self.assertNotEqual(account_3._model.premium_expired_notification_send_at, zero_time)
        self.assertEqual(account_4._model.premium_expired_notification_send_at, zero_time)

        current_time = datetime.datetime.now()

        self.assertTrue(
            current_time - datetime.timedelta(seconds=60)
            < account_1._model.premium_expired_notification_send_at
            < current_time
        )
        self.assertTrue(
            current_time - datetime.timedelta(seconds=60)
            < account_3._model.premium_expired_notification_send_at
            < current_time
        )

        self.assertEqual(PersonalMessagePrototype._db_count(), 2)
Esempio n. 3
0
    def test_send_premium_expired_notifications(self):
        self.assertEqual(PersonalMessagePrototype._db_count(), 0)

        account_1 = self.account
        account_2 = self.accounts_factory.create_account()
        account_3 = self.accounts_factory.create_account()
        account_4 = self.accounts_factory.create_account()

        account_1.prolong_premium(accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days-1)
        account_1.save()

        account_3.prolong_premium(accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days-1)
        account_3.save()

        account_4.prolong_premium(accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days+1)
        account_4.save()

        zero_time = datetime.datetime.fromtimestamp(0)

        self.assertEqual(account_1._model.premium_expired_notification_send_at, zero_time)
        self.assertEqual(account_2._model.premium_expired_notification_send_at, zero_time)
        self.assertEqual(account_3._model.premium_expired_notification_send_at, zero_time)
        self.assertEqual(account_4._model.premium_expired_notification_send_at, zero_time)

        AccountPrototype.send_premium_expired_notifications()

        account_1.reload()
        account_2.reload()
        account_3.reload()
        account_4.reload()

        self.assertNotEqual(account_1._model.premium_expired_notification_send_at, zero_time)
        self.assertEqual(account_2._model.premium_expired_notification_send_at, zero_time)
        self.assertNotEqual(account_3._model.premium_expired_notification_send_at, zero_time)
        self.assertEqual(account_4._model.premium_expired_notification_send_at, zero_time)

        current_time = datetime.datetime.now()

        self.assertTrue(current_time-datetime.timedelta(seconds=60) < account_1._model.premium_expired_notification_send_at < current_time)
        self.assertTrue(current_time-datetime.timedelta(seconds=60) < account_3._model.premium_expired_notification_send_at < current_time)

        self.assertEqual(PersonalMessagePrototype._db_count(), 2)
Esempio n. 4
0
    def test_send_premium_expired_notifications(self):
        with self.check_new_message(self.account.id, [logic.get_system_user_id()]):
            account_1 = self.account
            account_2 = self.accounts_factory.create_account()
            account_3 = self.accounts_factory.create_account()
            account_4 = self.accounts_factory.create_account()

            account_1.prolong_premium(accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days-1)
            account_1.save()

            account_3.prolong_premium(accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days-1)
            account_3.save()

            account_4.prolong_premium(accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days+1)
            account_4.save()

            zero_time = datetime.datetime.fromtimestamp(0)

            self.assertEqual(account_1._model.premium_expired_notification_send_at, zero_time)
            self.assertEqual(account_2._model.premium_expired_notification_send_at, zero_time)
            self.assertEqual(account_3._model.premium_expired_notification_send_at, zero_time)
            self.assertEqual(account_4._model.premium_expired_notification_send_at, zero_time)

            AccountPrototype.send_premium_expired_notifications()

            account_1.reload()
            account_2.reload()
            account_3.reload()
            account_4.reload()

            self.assertNotEqual(account_1._model.premium_expired_notification_send_at, zero_time)
            self.assertEqual(account_2._model.premium_expired_notification_send_at, zero_time)
            self.assertNotEqual(account_3._model.premium_expired_notification_send_at, zero_time)
            self.assertEqual(account_4._model.premium_expired_notification_send_at, zero_time)

            current_time = datetime.datetime.now()

            self.assertTrue(current_time-datetime.timedelta(seconds=60) < account_1._model.premium_expired_notification_send_at < current_time)
            self.assertTrue(current_time-datetime.timedelta(seconds=60) < account_3._model.premium_expired_notification_send_at < current_time)
Esempio n. 5
0
 def run_send_premium_expired_notifications(self):
     AccountPrototype.send_premium_expired_notifications()
Esempio n. 6
0
    def test_send_premium_expired_notifications(self):
        self.assertEqual(PersonalMessagePrototype._db_count(), 0)

        register_user('test_user_2', '*****@*****.**', '111111')
        register_user('test_user_3', '*****@*****.**', '111111')
        register_user('test_user_4', '*****@*****.**', '111111')

        account_1 = self.account
        account_2 = AccountPrototype.get_by_nick('test_user_2')
        account_3 = AccountPrototype.get_by_nick('test_user_3')
        account_4 = AccountPrototype.get_by_nick('test_user_4')

        account_1.prolong_premium(
            accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days - 1)
        account_1.save()

        account_3.prolong_premium(
            accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days - 1)
        account_3.save()

        account_4.prolong_premium(
            accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_IN.days + 1)
        account_4.save()

        zero_time = datetime.datetime.fromtimestamp(0)

        self.assertEqual(account_1._model.premium_expired_notification_send_at,
                         zero_time)
        self.assertEqual(account_2._model.premium_expired_notification_send_at,
                         zero_time)
        self.assertEqual(account_3._model.premium_expired_notification_send_at,
                         zero_time)
        self.assertEqual(account_4._model.premium_expired_notification_send_at,
                         zero_time)

        AccountPrototype.send_premium_expired_notifications()

        account_1.reload()
        account_2.reload()
        account_3.reload()
        account_4.reload()

        self.assertNotEqual(
            account_1._model.premium_expired_notification_send_at, zero_time)
        self.assertEqual(account_2._model.premium_expired_notification_send_at,
                         zero_time)
        self.assertNotEqual(
            account_3._model.premium_expired_notification_send_at, zero_time)
        self.assertEqual(account_4._model.premium_expired_notification_send_at,
                         zero_time)

        current_time = datetime.datetime.now()

        self.assertTrue(
            current_time - datetime.timedelta(seconds=60) < account_1._model.
            premium_expired_notification_send_at < current_time)
        self.assertTrue(
            current_time - datetime.timedelta(seconds=60) < account_3._model.
            premium_expired_notification_send_at < current_time)

        self.assertEqual(PersonalMessagePrototype._db_count(), 2)
Esempio n. 7
0
 def run_send_premium_expired_notifications(self):
     AccountPrototype.send_premium_expired_notifications()