Exemple #1
0
    def test_actors_after_user_update(self):
        old_actors_timestamps = list(Actor.objects.all().values_list(
            'created_at', flat=True))

        noun = names.generator.get_test_name('new-new-name')

        data = linguistics_helpers.get_word_post_data(noun, prefix='name')
        data.update({
            'caption': 'new-caption',
            'rationale': 'new-rationale',
            'chronicle_on_accepted': 'chronicle-on-accepted-2',
            'place': self.place2.id
        })

        form = PlaceRenaming.UserForm(data)

        self.assertTrue(form.is_valid())
        self.bill.update(form)

        new_actors_timestamps = list(Actor.objects.all().values_list(
            'created_at', flat=True))

        self.assertFalse(
            set(old_actors_timestamps) & set(new_actors_timestamps))
        self.assertTrue(new_actors_timestamps)
Exemple #2
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)
        ])
Exemple #3
0
    def test_forum_vote_might(self):
        old_might = calculate_might(self.account)
        bill_data = PlaceRenaming(
            place_id=self.place_1.id,
            name_forms=names.generator().get_test_name('bill_place'))
        bill = BillPrototype.create(
            self.account_2,
            'caption',
            'rationale',
            bill_data,
            chronicle_on_accepted='chronicle-on-accepted')
        bill.state = BILL_STATE.REJECTED
        bill.save()

        Post.objects.all().delete()
        Thread.objects.all().delete()
        Vote.objects.all().delete()

        self.assertEqual(calculate_might(self.account_2), old_might)
        self.assertEqual(calculate_might(self.account), 0)

        VotePrototype.create(self.account, bill, VOTE_TYPE.FOR)
        self.assertTrue(calculate_might(self.account) > 0)

        Vote.objects.all().delete()
        VotePrototype.create(self.account, bill, VOTE_TYPE.AGAINST)
        self.assertTrue(calculate_might(self.account) > 0)

        Vote.objects.all().delete()
        VotePrototype.create(self.account, bill, VOTE_TYPE.REFRAINED)
        self.assertEqual(calculate_might(self.account), 0)
Exemple #4
0
    def setUp(self):
        super(TestPrototypeApply, self).setUp()

        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1'))
        self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted')

        self.bill.approved_by_moderator = True
        self.bill.save()
Exemple #5
0
    def setUp(self):
        super(TestPrototypeEnd, self).setUp()

        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1'))
        self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted')

        self.bill.state = relations.BILL_STATE.ACCEPTED

        TimePrototype.get_current_time().increment_turn()
Exemple #6
0
    def setUp(self):
        super(TestActorPrototype, self).setUp()

        self.bill_data = PlaceRenaming(
            place_id=self.place1.id,
            name_forms=names.generator().get_test_name('new_name_1'))
        self.bill = BillPrototype.create(
            self.account1,
            'bill-1-caption',
            self.bill_data,
            chronicle_on_accepted='chronicle-on-accepted')
Exemple #7
0
 def create_bill(self, account=None):
     if account is None:
         account = self.account1
     bill_data = PlaceRenaming(
         place_id=self.place1.id,
         name_forms=names.generator.get_test_name('new_name_1'))
     return BillPrototype.create(
         account,
         'bill-1-caption',
         'bill-1-rationale',
         bill_data,
         chronicle_on_accepted='chronicle-on-accepted')
Exemple #8
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)
Exemple #9
0
    def test_voted_bill_might(self):
        old_might = calculate_might(self.account)
        bill_data = PlaceRenaming(place_id=self.place_1.id, name_forms=names.generator.get_test_name('bill_place'))
        bill = BillPrototype.create(self.account, 'caption', 'rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted')
        bill.state = BILL_STATE.VOTING
        bill.save()

        Post.objects.all().delete()
        Thread.objects.all().delete()
        Vote.objects.all().delete()

        self.assertEqual(calculate_might(self.account), old_might)
        self.assertEqual(calculate_might(self.account_2), 0)
    def test_update(self):
        VotePrototype.create(self.account2, self.bill, VOTE_TYPE.FOR)
        VotePrototype.create(self.account3, self.bill, VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account4, self.bill, VOTE_TYPE.REFRAINED)
        self.bill.recalculate_votes()
        self.bill.approved_by_moderator = True
        self.bill.save()

        old_updated_at = self.bill.updated_at

        self.assertEqual(self.bill.votes_for, 2)
        self.assertEqual(self.bill.votes_against, 1)
        self.assertEqual(self.bill.votes_refrained, 1)
        self.assertEqual(Vote.objects.all().count(), 4)
        self.assertEqual(self.bill.caption, 'bill-1-caption')
        self.assertEqual(self.bill.rationale, 'bill-1-rationale')
        self.assertEqual(self.bill.approved_by_moderator, True)
        self.assertEqual(self.bill.data.base_name, u'new_name_1-нс,ед,им')
        self.assertEqual(self.bill.data.place_id, self.place1.id)
        self.assertEqual(Post.objects.all().count(), 1)

        new_name = names.generator.get_test_name('new-new-name')

        data = linguistics_helpers.get_word_post_data(new_name, prefix='name')
        data.update({'caption': 'new-caption',
                     'rationale': 'new-rationale',
                     'chronicle_on_accepted': 'chronicle-on-accepted-2',
                     'place': self.place2.id})

        form = PlaceRenaming.UserForm(data)

        self.assertTrue(form.is_valid())

        self.bill.update(form)

        self.bill = BillPrototype.get_by_id(self.bill.id)

        self.assertTrue(old_updated_at < self.bill.updated_at)
        self.assertTrue(self.bill.state.is_VOTING)
        self.assertEqual(self.bill.votes_for, 1)
        self.assertEqual(self.bill.votes_against, 0)
        self.assertEqual(self.bill.votes_refrained, 0)
        self.assertEqual(Vote.objects.all().count(), 1)
        self.assertEqual(self.bill.caption, 'new-caption')
        self.assertEqual(self.bill.rationale, 'new-rationale')
        self.assertEqual(self.bill.chronicle_on_accepted, 'chronicle-on-accepted-2')
        self.assertEqual(self.bill.approved_by_moderator, False)
        self.assertEqual(self.bill.data.base_name, u'new-new-name-нс,ед,им')
        self.assertEqual(self.bill.data.place_id, self.place2.id)
        self.assertEqual(Post.objects.all().count(), 2)
        self.assertEqual(Thread.objects.get(id=self.bill.forum_thread_id).caption, 'new-caption')
Exemple #11
0
    def create_bill(self, index, owner, state):
        from the_tale.game.bills.bills import PlaceRenaming
        from the_tale.game.bills.prototypes import BillPrototype

        bill_data = PlaceRenaming(place_id=self.place1.id,
                                  name_forms=names.generator().get_test_name(
                                      'new_name_%d' % index))
        bill = BillPrototype.create(
            owner,
            'bill-%d-caption' % index,
            bill_data,
            chronicle_on_accepted='chronicle-on-accepted')
        bill.state = state
        bill.save()
    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)
 def create_place_renaming_bill(self, index):
     self.bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator.get_test_name('new_name_%d' % index))
     return BillPrototype.create(self.account1, 'bill-%d-caption' % index, 'bill-%d-rationale' % index, self.bill_data, chronicle_on_accepted='chronicle-on-accepted')