Exemplo n.º 1
0
    def test_achievements(self):
        VotePrototype.create(self.account2, self.bill,
                             relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)
        VotePrototype.create(self.account4, self.bill,
                             relations.VOTE_TYPE.REFRAINED)

        ##################################
        # set name forms
        data = linguistics_helpers.get_word_post_data(
            self.bill.data.name_forms, prefix='name')
        data.update({'approved': True})
        form = PlaceRenaming.ModeratorForm(data)

        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)
        ##################################

        with mock.patch(
                'the_tale.accounts.achievements.storage.AchievementsStorage.verify_achievements'
        ) as verify_achievements:
            self.assertTrue(self.bill.apply())

        self.assertEqual(verify_achievements.call_args_list, [
            mock.call(account_id=self.account1.id,
                      type=ACHIEVEMENT_TYPE.POLITICS_ACCEPTED_BILLS,
                      old_value=0,
                      new_value=1)
        ])
Exemplo n.º 2
0
    def test_approved(self):
        current_time = TimePrototype.get_current_time()
        current_time.increment_turn()
        current_time.increment_turn()
        current_time.increment_turn()

        VotePrototype.create(self.account2, self.bill,
                             relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)
        VotePrototype.create(self.account4, self.bill,
                             relations.VOTE_TYPE.REFRAINED)

        ##################################
        # set name forms
        data = linguistics_helpers.get_word_post_data(
            self.bill.data.name_forms, prefix='name')
        data.update({'approved': True})
        form = PlaceRenaming.ModeratorForm(data)

        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)
        ##################################

        self.assertEqual(Post.objects.all().count(), 1)

        with mock.patch(
                'the_tale.accounts.workers.accounts_manager.Worker.cmd_run_account_method'
        ) as cmd_run_account_method:
            self.assertTrue(self.bill.apply())

        self.assertEqual(cmd_run_account_method.call_args_list, [
            mock.call(account_id=self.bill.owner.id,
                      method_name=accounts_prototypes.AccountPrototype.
                      update_actual_bills.__name__,
                      data={})
        ])

        self.assertTrue(self.bill.state.is_ACCEPTED)

        self.assertEqual(Post.objects.all().count(), 2)

        bill = BillPrototype.get_by_id(self.bill.id)
        self.assertTrue(bill.state.is_ACCEPTED)

        places_storage.sync(force=True)

        self.place1.sync_parameters()
        self.assertTrue(self.place1.stability < 1.0)

        self.assertEqual(bill.applyed_at_turn, current_time.turn_number)

        self.check_place(self.place1.id, u'new_name_1-нс,ед,им',
                         self.bill.data.name_forms.forms)
Exemplo n.º 3
0
    def test_update_by_moderator(self):

        self.assertEqual(self.bill.approved_by_moderator, False)


        noun = names.generator.get_test_name('new-name')
        data = linguistics_helpers.get_word_post_data(noun, prefix='name')
        data.update({'approved': True})

        form = PlaceRenaming.ModeratorForm(data)

        self.assertTrue(form.is_valid())

        self.bill.update_by_moderator(form)

        self.bill = BillPrototype.get_by_id(self.bill.id)
        self.assertTrue(self.bill.state.is_VOTING)
        self.assertEqual(self.bill.approved_by_moderator, True)

        self.assertEqual(self.bill.data.name_forms.forms, noun.forms)