示例#1
0
    def __init__(self):
        register_user('forum_user', '*****@*****.**', '111111')
        register_user('forum_user_2', '*****@*****.**', '111111')

        self.account_1 = AccountPrototype.get_by_nick('forum_user')
        self.account_2 = AccountPrototype.get_by_nick('forum_user_2')

        # cat1
        # |-subcat1
        # | |-thread1
        # | | |-post1
        # | |-thread2
        # |-subcat2
        # cat2
        # | subcat3
        # | |- thread3
        # cat3

        self.cat_1 = CategoryPrototype.create(caption='cat1-caption', slug='cat1-slug', order=0)
        # to test, that subcat.id not correlate with order
        self.subcat_2 = SubCategoryPrototype.create(category=self.cat_1, caption='subcat2-caption', order=1, closed=True)
        self.subcat_1 = SubCategoryPrototype.create(category=self.cat_1, caption='subcat1-caption', order=0)
        self.cat_2 = CategoryPrototype.create(caption='cat2-caption', slug='cat2-slug', order=0)
        self.subcat_3 = SubCategoryPrototype.create(category=self.cat_2, caption='subcat3-caption', order=0)
        self.cat_3 = CategoryPrototype.create(caption='cat3-caption', slug='cat3-slug', order=0)

        self.thread_1 = ThreadPrototype.create(self.subcat_1, 'thread1-caption', self.account_1, 'thread1-text')
        self.thread_2 = ThreadPrototype.create(self.subcat_1, 'thread2-caption', self.account_1, 'thread2-text')
        self.thread_3 = ThreadPrototype.create(self.subcat_3, 'thread3-caption', self.account_1, 'thread3-text')

        self.post_1 = PostPrototype.create(self.thread_1, self.account_1, 'post1-text')

        # create test clan and clean it's forum artifacts
        self.clan_category = CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0)
        self.clan_1 = ClanPrototype.create(self.account_1, abbr=u'abbr1', name=u'name1', motto=u'motto', description=u'description')
示例#2
0
    def test_last_forum_posts_with_permissions(self):

        register_user('granted_user', '*****@*****.**', '111111')
        register_user('wrong_user', '*****@*****.**', '111111')

        granted_account = AccountPrototype.get_by_nick('granted_user')
        wrong_account = AccountPrototype.get_by_nick('wrong_user')

        restricted_subcategory = SubCategoryPrototype.create(
            category=self.category,
            caption='subcat2-caption',
            order=1,
            restricted=True)

        PermissionPrototype.create(granted_account, restricted_subcategory)

        restricted_thread = ThreadPrototype.create(
            restricted_subcategory, 'thread-restricted-caption', self.account,
            'thread-text')

        self.assertEqual(
            set(t.id for t in ThreadPrototype.get_last_threads(account=None,
                                                               limit=3)),
            set([self.thread.id]))

        self.assertEqual(
            set(t.id for t in ThreadPrototype.get_last_threads(
                account=granted_account, limit=3)),
            set([self.thread.id, restricted_thread.id]))

        self.assertEqual(
            set(t.id for t in ThreadPrototype.get_last_threads(
                account=wrong_account, limit=3)), set([self.thread.id]))
示例#3
0
    def test_subcategories_visible_to_account_with_permissions(self):
        register_user('test_user', '*****@*****.**', '111111')
        register_user('granted_user', '*****@*****.**', '111111')
        register_user('wrong_user', '*****@*****.**', '111111')

        granted_account = AccountPrototype.get_by_nick('granted_user')
        wrong_account = AccountPrototype.get_by_nick('wrong_user')

        category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        subcategory_1 = SubCategoryPrototype.create(category=category, caption='subcat-1-caption', order=2)

        SubCategoryPrototype.create(category=category, caption='subcat-2-caption', order=1, restricted=True)

        restricted_subcategory = SubCategoryPrototype.create(category=category, caption='subcat-restricted-caption', order=0, restricted=True)

        PermissionPrototype.create(granted_account, restricted_subcategory)

        self.assertEqual([s.id for s in SubCategoryPrototype.subcategories_visible_to_account(account=None)],
                         [subcategory_1.id])

        self.assertEqual([s.id for s in SubCategoryPrototype.subcategories_visible_to_account(account=granted_account)],
                         [restricted_subcategory.id, subcategory_1.id])

        self.assertEqual([s.id for s in SubCategoryPrototype.subcategories_visible_to_account(account=wrong_account)],
                         [subcategory_1.id])
示例#4
0
    def setUp(self):
        super(TestModeration, self).setUp()
        create_test_map()
        register_user('main_user', '*****@*****.**', '111111')
        register_user('moderator', '*****@*****.**', '111111')
        register_user('second_user', '*****@*****.**', '111111')

        self.main_account = AccountPrototype.get_by_nick('main_user')
        self.moderator = AccountPrototype.get_by_nick('moderator')
        self.second_account = AccountPrototype.get_by_nick('second_user')

        group = sync_group(forum_settings.MODERATOR_GROUP_NAME, ['forum.moderate_post', 'forum.moderate_thread'])

        group.user_set.add(self.moderator._model)

        self.client = client.Client()

        self.category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        self.subcategory = SubCategoryPrototype.create(category=self.category, caption='subcat-caption', order=0)
        self.subcategory2 = SubCategoryPrototype.create(category=self.category, caption='subcat2-caption', order=1, closed=True)
        self.thread = ThreadPrototype.create(self.subcategory, 'thread-caption', self.main_account, 'thread-text')
        self.post = PostPrototype.create(self.thread, self.main_account, 'post-text')
        self.post2 = PostPrototype.create(self.thread, self.main_account, 'post2-text')
        self.post5 = PostPrototype.create(self.thread, self.main_account, 'post5-text', technical=True)

        self.thread2 = ThreadPrototype.create(self.subcategory, 'thread2-caption', self.main_account, 'thread2-text')
        self.post3 = PostPrototype.create(self.thread2, self.main_account, 'post3-text')
        self.post4 = PostPrototype.create(self.thread2, self.second_account, 'post4-text')

        self.thread3 = ThreadPrototype.create(self.subcategory, 'thread3-caption', self.second_account, 'thread3-text')
示例#5
0
    def setUp(self):
        super(SendMailTests, self).setUp()

        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_nick('user_1')

        register_user('user_2', '*****@*****.**', '111111')
        self.account_2 = AccountPrototype.get_by_nick('user_2')
示例#6
0
    def setUp(self):
        super(SendMailTests, self).setUp()

        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_nick('user_1')

        register_user('user_2', '*****@*****.**', '111111')
        self.account_2 = AccountPrototype.get_by_nick('user_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)
示例#8
0
    def setUp(self):
        super(SubCategoryReadInfoPrototypeTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        register_user('user_2', '*****@*****.**', '111111')

        self.account = AccountPrototype.get_by_nick('user_1')
        self.account_2 = AccountPrototype.get_by_nick('user_2')

        category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        self.subcategory = SubCategoryPrototype.create(category=category, caption='subcat-caption', order=0)
示例#9
0
    def setUp(self):
        super(TestModeration, self).setUp()
        create_test_map()
        register_user('main_user', '*****@*****.**', '111111')
        register_user('moderator', '*****@*****.**', '111111')
        register_user('second_user', '*****@*****.**', '111111')

        self.main_account = AccountPrototype.get_by_nick('main_user')
        self.moderator = AccountPrototype.get_by_nick('moderator')
        self.second_account = AccountPrototype.get_by_nick('second_user')

        group = sync_group(forum_settings.MODERATOR_GROUP_NAME,
                           ['forum.moderate_post', 'forum.moderate_thread'])

        group.user_set.add(self.moderator._model)

        self.client = client.Client()

        self.category = CategoryPrototype.create(caption='cat-caption',
                                                 slug='cat-slug',
                                                 order=0)
        self.subcategory = SubCategoryPrototype.create(
            category=self.category, caption='subcat-caption', order=0)
        self.subcategory2 = SubCategoryPrototype.create(
            category=self.category,
            caption='subcat2-caption',
            order=1,
            closed=True)
        self.thread = ThreadPrototype.create(self.subcategory,
                                             'thread-caption',
                                             self.main_account, 'thread-text')
        self.post = PostPrototype.create(self.thread, self.main_account,
                                         'post-text')
        self.post2 = PostPrototype.create(self.thread, self.main_account,
                                          'post2-text')
        self.post5 = PostPrototype.create(self.thread,
                                          self.main_account,
                                          'post5-text',
                                          technical=True)

        self.thread2 = ThreadPrototype.create(self.subcategory,
                                              'thread2-caption',
                                              self.main_account,
                                              'thread2-text')
        self.post3 = PostPrototype.create(self.thread2, self.main_account,
                                          'post3-text')
        self.post4 = PostPrototype.create(self.thread2, self.second_account,
                                          'post4-text')

        self.thread3 = ThreadPrototype.create(self.subcategory,
                                              'thread3-caption',
                                              self.second_account,
                                              'thread3-text')
示例#10
0
    def setUp(self):
        super(PrototypeTestsBase, self).setUp()
        self.place1, self.place2, self.place3 = create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        register_user('user_2', '*****@*****.**', '111111')
        register_user('user_3', '*****@*****.**', '111111')
        register_user('user_4', '*****@*****.**', '111111')

        self.account_1 = AccountPrototype.get_by_nick('user_1')
        self.account_2 = AccountPrototype.get_by_nick('user_2')
        self.account_3 = AccountPrototype.get_by_nick('user_3')
        self.account_4 = AccountPrototype.get_by_nick('user_4')
示例#11
0
    def setUp(self):
        super(PrototypeTestsBase, self).setUp()
        self.place1, self.place2, self.place3 = create_test_map()

        register_user("user_1", "*****@*****.**", "111111")
        register_user("user_2", "*****@*****.**", "111111")
        register_user("user_3", "*****@*****.**", "111111")
        register_user("user_4", "*****@*****.**", "111111")

        self.account_1 = AccountPrototype.get_by_nick("user_1")
        self.account_2 = AccountPrototype.get_by_nick("user_2")
        self.account_3 = AccountPrototype.get_by_nick("user_3")
        self.account_4 = AccountPrototype.get_by_nick("user_4")
示例#12
0
    def setUp(self):
        super(PrototypeTestsBase, self).setUp()
        self.place1, self.place2, self.place3 = create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        register_user('user_2', '*****@*****.**', '111111')
        register_user('user_3', '*****@*****.**', '111111')
        register_user('user_4', '*****@*****.**', '111111')

        self.account_1 = AccountPrototype.get_by_nick('user_1')
        self.account_2 = AccountPrototype.get_by_nick('user_2')
        self.account_3 = AccountPrototype.get_by_nick('user_3')
        self.account_4 = AccountPrototype.get_by_nick('user_4')
示例#13
0
    def setUp(self):
        super(PersonalMessagesTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_nick('user_1')

        register_user('user_2', '*****@*****.**', '111111')
        self.account_2 = AccountPrototype.get_by_nick('user_2')

        self.personal_message = PersonalMessagePrototype.create(self.account_1, self.account_2, 'test text')

        self.message = MessagePrototype.get_priority_message()
示例#14
0
    def setUp(self):
        super(PersonalMessagesTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_nick('user_1')

        register_user('user_2', '*****@*****.**', '111111')
        self.account_2 = AccountPrototype.get_by_nick('user_2')

        self.personal_message = PersonalMessagePrototype.create(
            self.account_1, self.account_2, 'test text')

        self.message = MessagePrototype.get_priority_message()
示例#15
0
    def setUp(self):
        super(SubCategoryReadInfoPrototypeTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        register_user('user_2', '*****@*****.**', '111111')

        self.account = AccountPrototype.get_by_nick('user_1')
        self.account_2 = AccountPrototype.get_by_nick('user_2')

        category = CategoryPrototype.create(caption='cat-caption',
                                            slug='cat-slug',
                                            order=0)
        self.subcategory = SubCategoryPrototype.create(
            category=category, caption='subcat-caption', order=0)
示例#16
0
    def setUp(self):
        super(PostPrototypeTests, self).setUp()

        create_test_map()

        register_user('test_user', '*****@*****.**', '111111')
        register_user('checked_user', '*****@*****.**', '111111')

        self.account = AccountPrototype.get_by_nick('test_user')
        self.checked_account = AccountPrototype.get_by_nick('checked_user')

        self.category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        self.subcategory = SubCategoryPrototype.create(category=self.category, caption='subcat-caption', order=2)

        self.thread = ThreadPrototype.create(self.subcategory, 'thread-caption', self.account, 'thread-text')
示例#17
0
    def setUp(self):
        super(ReadStateTests, self).setUp()
        create_test_map()

        register_user("user_1", "*****@*****.**", "111111")
        register_user("user_2", "*****@*****.**", "111111")

        self.account = AccountPrototype.get_by_nick("user_1")
        self.account_2 = AccountPrototype.get_by_nick("user_2")

        category = CategoryPrototype.create(caption="cat-caption", slug="cat-slug", order=0)
        self.subcategory = SubCategoryPrototype.create(category=category, caption="subcat-caption", order=0)
        self.subcategory_2 = SubCategoryPrototype.create(category=category, caption="subcat-2-caption", order=0)

        self.thread = ThreadPrototype.create(self.subcategory, "thread1-caption", self.account_2, "thread-text")
        self.thread_2 = ThreadPrototype.create(self.subcategory, "thread2-caption", self.account_2, "thread-2-text")
        self.thread_3 = ThreadPrototype.create(self.subcategory_2, "thread2-caption", self.account, "thread-2-text")
示例#18
0
    def test_subcategories_visible_to_account_with_permissions(self):
        register_user('test_user', '*****@*****.**', '111111')
        register_user('granted_user', '*****@*****.**', '111111')
        register_user('wrong_user', '*****@*****.**', '111111')

        granted_account = AccountPrototype.get_by_nick('granted_user')
        wrong_account = AccountPrototype.get_by_nick('wrong_user')

        category = CategoryPrototype.create(caption='cat-caption',
                                            slug='cat-slug',
                                            order=0)
        subcategory_1 = SubCategoryPrototype.create(category=category,
                                                    caption='subcat-1-caption',
                                                    order=2)

        SubCategoryPrototype.create(category=category,
                                    caption='subcat-2-caption',
                                    order=1,
                                    restricted=True)

        restricted_subcategory = SubCategoryPrototype.create(
            category=category,
            caption='subcat-restricted-caption',
            order=0,
            restricted=True)

        PermissionPrototype.create(granted_account, restricted_subcategory)

        self.assertEqual([
            s.id
            for s in SubCategoryPrototype.subcategories_visible_to_account(
                account=None)
        ], [subcategory_1.id])

        self.assertEqual([
            s.id
            for s in SubCategoryPrototype.subcategories_visible_to_account(
                account=granted_account)
        ], [restricted_subcategory.id, subcategory_1.id])

        self.assertEqual([
            s.id
            for s in SubCategoryPrototype.subcategories_visible_to_account(
                account=wrong_account)
        ], [subcategory_1.id])
示例#19
0
    def setUp(self):
        super(ResetPasswordTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_nick('user_1')

        self.reset_task = ResetPasswordTaskPrototype.create(self.account_1)
        self.message = MessagePrototype.get_priority_message()
示例#20
0
    def test_banned_accounts_filtration(self):
        register_user('user_5', '*****@*****.**', '111111')
        account_5 = AccountPrototype.get_by_nick('user_5')

        account_5.ban_game(1)

        RatingValuesPrototype.recalculate()
        self.assertEqual([rv.account_id for rv in RatingValues.objects.all().order_by('account__id')],
                         [self.account_1.id, self.account_2.id, self.account_3.id, self.account_4.id, ])
示例#21
0
    def setUp(self):
        super(ResetPasswordTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_nick('user_1')

        self.reset_task = ResetPasswordTaskPrototype.create(self.account_1)
        self.message = MessagePrototype.get_priority_message()
示例#22
0
    def setUp(self):
        super(SubscriptionPrototypeTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        register_user('user_2', '*****@*****.**', '111111')

        self.account = AccountPrototype.get_by_nick('user_1')
        self.account_2 = AccountPrototype.get_by_nick('user_2')

        self.category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        self.subcategory_1 = SubCategoryPrototype.create(category=self.category, caption='subcat-1-caption', order=0)
        self.subcategory_2 = SubCategoryPrototype.create(category=self.category, caption='subcat-2-caption', order=1)

        self.thread_1_1 = ThreadPrototype.create(self.subcategory_1, 'thread-1-1-caption', self.account, 'thread-1-1-text')
        self.thread_1_2 = ThreadPrototype.create(self.subcategory_1, 'thread-1-2-caption', self.account, 'thread-1-2-text')
        self.thread_1_3 = ThreadPrototype.create(self.subcategory_1, 'thread-1-3-caption', self.account_2, 'thread-1-3-text')
        self.thread_2_1 = ThreadPrototype.create(self.subcategory_2, 'thread-2-1-caption', self.account, 'thread-2-1-text')
        self.thread_2_2 = ThreadPrototype.create(self.subcategory_2, 'thread-2-2-caption', self.account, 'thread-2-2-text')
示例#23
0
    def setUp(self):
        super(PostPrototypeTests, self).setUp()

        create_test_map()

        register_user('test_user', '*****@*****.**', '111111')
        register_user('checked_user', '*****@*****.**', '111111')

        self.account = AccountPrototype.get_by_nick('test_user')
        self.checked_account = AccountPrototype.get_by_nick('checked_user')

        self.category = CategoryPrototype.create(caption='cat-caption',
                                                 slug='cat-slug',
                                                 order=0)
        self.subcategory = SubCategoryPrototype.create(
            category=self.category, caption='subcat-caption', order=2)

        self.thread = ThreadPrototype.create(self.subcategory,
                                             'thread-caption', self.account,
                                             'thread-text')
示例#24
0
    def setUp(self):
        super(NewForumThreadTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_nick('user_1')

        self.category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        self.subcategory = SubCategoryPrototype.create(category=self.category, caption='subcat-caption', order=0)
        self.thread = ThreadPrototype.create(self.subcategory, 'thread_1-caption', self.account_1, 'thread-text')

        self.message = MessagePrototype.get_priority_message()
示例#25
0
    def test_many_subscriptions(self):
        register_user('user_2', '*****@*****.**', '111111')
        account_2 = AccountPrototype.get_by_nick('user_2')

        SubscriptionPrototype.create(self.account_1, self.thread)
        SubscriptionPrototype.create(account_2, self.thread)

        self.assertEqual(len(mail.outbox), 0)
        self.message.process()
        self.assertTrue(self.message.state.is_PROCESSED)
        self.assertEqual(len(mail.outbox), 2)
        self.assertEqual(mail.outbox[0].to, [self.account_1.email])
        self.assertEqual(mail.outbox[1].to, [account_2.email])
示例#26
0
文件: logic.py 项目: angru/the-tale
def get_system_user():
    account = AccountPrototype.get_by_nick(accounts_settings.SYSTEM_USER_NICK)
    if account: return account

    register_result, account_id, bundle_id = register_user(accounts_settings.SYSTEM_USER_NICK, # pylint: disable=W0612
                                                           email=project_settings.EMAIL_NOREPLY,
                                                           password=generate_password(len_=accounts_settings.RESET_PASSWORD_LENGTH))

    account = AccountPrototype.get_by_id(account_id)
    account._model.active_end_at = datetime.datetime.fromtimestamp(0)
    account.save()

    return account
示例#27
0
    def test_many_subscriptions(self):
        register_user('user_2', '*****@*****.**', '111111')
        account_2 = AccountPrototype.get_by_nick('user_2')

        SubscriptionPrototype.create(self.account_1, subcategory=self.subcategory)
        SubscriptionPrototype.create(account_2, subcategory=self.subcategory)

        self.assertEqual(len(mail.outbox), 0)
        self.message.process()
        self.assertTrue(self.message.state.is_PROCESSED)
        self.assertEqual(len(mail.outbox), 2)
        self.assertEqual(mail.outbox[0].to, [self.account_1.email])
        self.assertEqual(mail.outbox[1].to, [account_2.email])
示例#28
0
    def setUp(self):
        super(SubscriptionPrototypeTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        register_user('user_2', '*****@*****.**', '111111')

        self.account = AccountPrototype.get_by_nick('user_1')
        self.account_2 = AccountPrototype.get_by_nick('user_2')

        self.category = CategoryPrototype.create(caption='cat-caption',
                                                 slug='cat-slug',
                                                 order=0)
        self.subcategory_1 = SubCategoryPrototype.create(
            category=self.category, caption='subcat-1-caption', order=0)
        self.subcategory_2 = SubCategoryPrototype.create(
            category=self.category, caption='subcat-2-caption', order=1)

        self.thread_1_1 = ThreadPrototype.create(self.subcategory_1,
                                                 'thread-1-1-caption',
                                                 self.account,
                                                 'thread-1-1-text')
        self.thread_1_2 = ThreadPrototype.create(self.subcategory_1,
                                                 'thread-1-2-caption',
                                                 self.account,
                                                 'thread-1-2-text')
        self.thread_1_3 = ThreadPrototype.create(self.subcategory_1,
                                                 'thread-1-3-caption',
                                                 self.account_2,
                                                 'thread-1-3-text')
        self.thread_2_1 = ThreadPrototype.create(self.subcategory_2,
                                                 'thread-2-1-caption',
                                                 self.account,
                                                 'thread-2-1-text')
        self.thread_2_2 = ThreadPrototype.create(self.subcategory_2,
                                                 'thread-2-2-caption',
                                                 self.account,
                                                 'thread-2-2-text')
示例#29
0
    def test_last_forum_posts_with_permissions(self):

        register_user('granted_user', '*****@*****.**', '111111')
        register_user('wrong_user', '*****@*****.**', '111111')


        granted_account = AccountPrototype.get_by_nick('granted_user')
        wrong_account = AccountPrototype.get_by_nick('wrong_user')

        restricted_subcategory = SubCategoryPrototype.create(category=self.category, caption='subcat2-caption', order=1, restricted=True)

        PermissionPrototype.create(granted_account, restricted_subcategory)

        restricted_thread = ThreadPrototype.create(restricted_subcategory, 'thread-restricted-caption', self.account, 'thread-text')

        self.assertEqual(set(t.id for t in ThreadPrototype.get_last_threads(account=None, limit=3)),
                         set([self.thread.id]))

        self.assertEqual(set(t.id for t in ThreadPrototype.get_last_threads(account=granted_account, limit=3)),
                         set([self.thread.id, restricted_thread.id]))

        self.assertEqual(set(t.id for t in ThreadPrototype.get_last_threads(account=wrong_account, limit=3)),
                         set([self.thread.id]))
示例#30
0
    def test_banned_accounts_filtration(self):
        register_user('user_5', '*****@*****.**', '111111')
        account_5 = AccountPrototype.get_by_nick('user_5')

        account_5.ban_game(1)

        RatingValuesPrototype.recalculate()
        self.assertEqual([
            rv.account_id
            for rv in RatingValues.objects.all().order_by('account__id')
        ], [
            self.account_1.id,
            self.account_2.id,
            self.account_3.id,
            self.account_4.id,
        ])
    def test_mail_send_for_fast_account(self):
        register_user('user_2')
        account = AccountPrototype.get_by_nick('user_2')

        task, message = self.create_task_and_message(account, 'user_2_new')

        self.assertEqual(len(mail.outbox), 0)

        message = MessagePrototype.get_priority_message()
        message.process()

        self.assertTrue(message.state.is_PROCESSED)
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to, ['*****@*****.**'])

        self.assertTrue(task.uuid in mail.outbox[0].body)
        self.assertTrue(task.uuid in mail.outbox[0].alternatives[0][0])
    def test_mail_send_for_fast_account(self):
        register_user('user_2')
        account = AccountPrototype.get_by_nick('user_2')

        task, message = self.create_task_and_message(account, 'user_2_new')

        self.assertEqual(len(mail.outbox), 0)

        message = MessagePrototype.get_priority_message()
        message.process()

        self.assertTrue(message.state.is_PROCESSED)
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to, ['*****@*****.**'])

        self.assertTrue(task.uuid in mail.outbox[0].body)
        self.assertTrue(task.uuid in mail.outbox[0].alternatives[0][0])
示例#33
0
 def test_get_new_post_delay__no_posts__old_account(self):
     register_user('new_test_user', '*****@*****.**', '111111')
     new_account = AccountPrototype.get_by_nick('new_test_user')
     new_account._model.created_at = datetime.datetime.now(
     ) - datetime.timedelta(days=30)
     self.assertFalse(PostPrototype.get_new_post_delay(new_account), 0)
    def setUp(self):
        super(ChangeEmailNotificationTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        self.account = AccountPrototype.get_by_nick('user_1')
示例#35
0
 def test_get_new_post_delay__no_posts__old_account(self):
     register_user('new_test_user', '*****@*****.**', '111111')
     new_account = AccountPrototype.get_by_nick('new_test_user')
     new_account._model.created_at = datetime.datetime.now() - datetime.timedelta(days=30)
     self.assertFalse(PostPrototype.get_new_post_delay(new_account), 0)
示例#36
0
 def test_get_new_post_delay__no_posts__new_account(self):
     register_user('new_test_user', '*****@*****.**', '111111')
     new_account = AccountPrototype.get_by_nick('new_test_user')
     self.assertTrue(PostPrototype.get_new_post_delay(new_account) > 0)
示例#37
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)
    def setUp(self):
        super(ChangeEmailNotificationTests, self).setUp()
        create_test_map()

        register_user('user_1', '*****@*****.**', '111111')
        self.account = AccountPrototype.get_by_nick('user_1')
示例#39
0
 def test_get_new_post_delay__no_posts__new_account(self):
     register_user('new_test_user', '*****@*****.**', '111111')
     new_account = AccountPrototype.get_by_nick('new_test_user')
     self.assertTrue(PostPrototype.get_new_post_delay(new_account) > 0)