Exemplo n.º 1
0
    def setUp(self):
        super(ClanInfoTests, self).setUp()
        create_test_map()

        CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0)

        self.account = self.accounts_factory.create_account()
        self.clan_info = ClanInfo(account=self.account)
Exemplo n.º 2
0
    def setUp(self):
        super(ClanInfoTests, self).setUp()
        create_test_map()

        CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0)

        result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111')
        self.account = AccountPrototype.get_by_id(account_id)
        self.clan_info = ClanInfo(account=self.account)
Exemplo n.º 3
0
class ClanInfoTests(TestCase, ClansTestsMixin):
    def setUp(self):
        super(ClanInfoTests, self).setUp()
        create_test_map()

        CategoryPrototype.create(caption='category-1',
                                 slug=clans_settings.FORUM_CATEGORY_SLUG,
                                 order=0)

        self.account = self.accounts_factory.create_account()
        self.clan_info = ClanInfo(account=self.account)

    @mock.patch(
        'the_tale.accounts.prototypes.AccountPrototype.is_authenticated',
        lambda *argv: False)
    def test_membership__anonymous(self):
        self.assertEqual(self.clan_info.membership, None)

    def test_membership__no_membership(self):
        self.assertEqual(self.clan_info.membership, None)

    def test_membership__has_membership(self):
        self.create_clan(self.account, 0)
        self.assertEqual(self.clan_info.membership.account_id, self.account.id)

    def test_is_member_of__no_clan(self):
        self.assertFalse(self.clan_info.is_member_of(None))

    def test_is_member_of__no_membership(self):
        clan_2 = self.create_clan(self.accounts_factory.create_account(), 0)
        self.assertFalse(self.clan_info.is_member_of(clan_2))

    def test_is_member_of__is_member(self):
        self.assertTrue(
            self.clan_info.is_member_of(self.create_clan(self.account, 0)))

    @mock.patch('the_tale.accounts.clans.logic.ClanInfo.is_member_of',
                lambda info, clan: False)
    def test_is_owner_of___is_member_false(self):
        self.assertFalse(
            self.clan_info.is_owner_of(self.create_clan(self.account, 0)))

    def test_is_owner_of__is_member_true__wrong_clan(self):
        account_2 = self.accounts_factory.create_account()

        self.create_clan(self.account, 0)

        self.assertFalse(
            self.clan_info.is_owner_of(self.create_clan(account_2, 1)))

    def test_is_owner_of__is_owner(self):
        self.assertTrue(
            self.clan_info.is_owner_of(self.create_clan(self.account, 0)))

    @mock.patch('the_tale.accounts.clans.prototypes.MembershipPrototype.role',
                MEMBER_ROLE.MEMBER)
    def test_is_owner_of__not_leader(self):
        self.assertFalse(
            self.clan_info.is_owner_of(self.create_clan(self.account, 0)))

    def test_can_invite__not_member(self):
        self.assertFalse(self.clan_info.can_invite)

    @mock.patch('the_tale.accounts.clans.prototypes.MembershipPrototype.role',
                MEMBER_ROLE.MEMBER)
    def test_can_invite__no_rights(self):
        self.create_clan(self.account, 0)
        self.assertFalse(self.clan_info.can_invite)

    def test_can_invite__has_rights(self):
        self.create_clan(self.account, 0)
        self.assertTrue(self.clan_info.can_invite)

    def test_can_remove__not_member(self):
        self.assertFalse(self.clan_info.can_remove)

    @mock.patch('the_tale.accounts.clans.prototypes.MembershipPrototype.role',
                MEMBER_ROLE.MEMBER)
    def test_can_remove__no_rights(self):
        self.create_clan(self.account, 0)
        self.assertFalse(self.clan_info.can_remove)

    def test_can_remove__has_rights(self):
        self.create_clan(self.account, 0)
        self.assertTrue(self.clan_info.can_remove)
Exemplo n.º 4
0
class ClanInfoTests(TestCase, ClansTestsMixin):

    def setUp(self):
        super(ClanInfoTests, self).setUp()
        create_test_map()

        CategoryPrototype.create(caption='category-1', slug=clans_settings.FORUM_CATEGORY_SLUG, order=0)

        result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111')
        self.account = AccountPrototype.get_by_id(account_id)
        self.clan_info = ClanInfo(account=self.account)


    @mock.patch('the_tale.accounts.prototypes.AccountPrototype.is_authenticated', lambda *argv: False)
    def test_can_create_clan__anonymous(self):
        self.assertFalse(self.clan_info.can_create_clan)

    def test_can_create_clan__already_member(self):
        self.create_clan(self.account, 0)
        self.assertFalse(self.clan_info.can_create_clan)

    def test_can_create_clan__is_fast(self):
        self.account.is_fast = True
        self.assertFalse(self.clan_info.can_create_clan)

    def test_can_create_clan__can(self):
        self.account.set_might(clans_settings.OWNER_MIGHT_REQUIRED)
        self.assertTrue(self.clan_info.can_create_clan)

    def test_can_create_clan__no_might(self):
        self.assertFalse(self.clan_info.can_create_clan)

    def test_can_create_clan__right_purchased(self):
        self.account.permanent_purchases.insert(PERMANENT_PURCHASE_TYPE.CLAN_OWNERSHIP_RIGHT)
        self.assertTrue(self.account.might < clans_settings.OWNER_MIGHT_REQUIRED)
        self.assertTrue(self.clan_info.can_create_clan)


    @mock.patch('the_tale.accounts.prototypes.AccountPrototype.is_authenticated', lambda *argv: False)
    def test_membership__anonymous(self):
        self.assertEqual(self.clan_info.membership, None)

    def test_membership__no_membership(self):
        self.assertEqual(self.clan_info.membership, None)

    def test_membership__has_membership(self):
        self.create_clan(self.account, 0)
        self.assertEqual(self.clan_info.membership.account_id, self.account.id)

    def test_is_member_of__no_clan(self):
        self.assertFalse(self.clan_info.is_member_of(None))

    def test_is_member_of__no_membership(self):
        result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111')
        clan_2 = self.create_clan(AccountPrototype.get_by_id(account_id), 0)
        self.assertFalse(self.clan_info.is_member_of(clan_2))

    def test_is_member_of__is_member(self):
        self.assertTrue(self.clan_info.is_member_of(self.create_clan(self.account, 0)))

    @mock.patch('the_tale.accounts.clans.logic.ClanInfo.is_member_of', lambda info, clan: False)
    def test_is_owner_of___is_member_false(self):
        self.assertFalse(self.clan_info.is_owner_of(self.create_clan(self.account, 0)))

    def test_is_owner_of__is_member_true__wrong_clan(self):
        result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111')
        account_2 = AccountPrototype.get_by_id(account_id)

        self.create_clan(self.account, 0)

        self.assertFalse(self.clan_info.is_owner_of(self.create_clan(account_2, 1)))

    def test_is_owner_of__is_owner(self):
        self.assertTrue(self.clan_info.is_owner_of(self.create_clan(self.account, 0)))

    @mock.patch('the_tale.accounts.clans.prototypes.MembershipPrototype.role', MEMBER_ROLE.MEMBER)
    def test_is_owner_of__not_leader(self):
        self.assertFalse(self.clan_info.is_owner_of(self.create_clan(self.account, 0)))

    def test_can_invite__not_member(self):
        self.assertFalse(self.clan_info.can_invite)

    @mock.patch('the_tale.accounts.clans.prototypes.MembershipPrototype.role', MEMBER_ROLE.MEMBER)
    def test_can_invite__no_rights(self):
        self.create_clan(self.account, 0)
        self.assertFalse(self.clan_info.can_invite)

    def test_can_invite__has_rights(self):
        self.create_clan(self.account, 0)
        self.assertTrue(self.clan_info.can_invite)

    def test_can_remove__not_member(self):
        self.assertFalse(self.clan_info.can_remove)

    @mock.patch('the_tale.accounts.clans.prototypes.MembershipPrototype.role', MEMBER_ROLE.MEMBER)
    def test_can_remove__no_rights(self):
        self.create_clan(self.account, 0)
        self.assertFalse(self.clan_info.can_remove)

    def test_can_remove__has_rights(self):
        self.create_clan(self.account, 0)
        self.assertTrue(self.clan_info.can_remove)
Exemplo n.º 5
0
def account_sidebar(user_account,
                    page_account,
                    page_caption,
                    page_type,
                    can_moderate=False):
    from the_tale.forum.models import Thread
    from the_tale.game.bills.prototypes import BillPrototype
    from the_tale.linguistics.prototypes import ContributionPrototype
    from the_tale.linguistics.relations import CONTRIBUTION_TYPE
    from the_tale.accounts.friends.prototypes import FriendshipPrototype
    from the_tale.accounts.clans.logic import ClanInfo
    from the_tale.blogs.models import Post as BlogPost, POST_STATE as BLOG_POST_STATE

    bills_count = BillPrototype.accepted_bills_count(page_account.id)

    threads_count = Thread.objects.filter(author=page_account._model).count()

    threads_with_posts = Thread.objects.filter(
        post__author=page_account._model).distinct().count()

    templates_count = ContributionPrototype._db_filter(
        account_id=page_account.id, type=CONTRIBUTION_TYPE.TEMPLATE).count()

    words_count = ContributionPrototype._db_filter(
        account_id=page_account.id, type=CONTRIBUTION_TYPE.WORD).count()

    folclor_posts_count = BlogPost.objects.filter(
        author=page_account._model, state=BLOG_POST_STATE.ACCEPTED).count()

    friendship = FriendshipPrototype.get_for_bidirectional(
        user_account, page_account)

    return jinja2.Markup(
        jinja2.render('accounts/sidebar.html',
                      context={
                          'user_account':
                          user_account,
                          'page_account':
                          page_account,
                          'page_caption':
                          page_caption,
                          'master_clan_info':
                          ClanInfo(page_account),
                          'own_clan_info':
                          ClanInfo(user_account),
                          'friendship':
                          friendship,
                          'bills_count':
                          bills_count,
                          'templates_count':
                          templates_count,
                          'words_count':
                          words_count,
                          'folclor_posts_count':
                          folclor_posts_count,
                          'threads_count':
                          threads_count,
                          'threads_with_posts':
                          threads_with_posts,
                          'can_moderate':
                          can_moderate,
                          'page_type':
                          page_type,
                          'commission':
                          conf.accounts_settings.MONEY_SEND_COMMISSION
                      }))