def test_not_enough_voices_percents(self): current_time = TimePrototype.get_current_time() 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.REFRAINED) 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.assertFalse(self.bill.apply()) self.assertEqual(cmd_run_account_method.call_count, 0) self.assertTrue(self.bill.state.is_REJECTED) self.assertEqual(Post.objects.all().count(), 2) bill = BillPrototype.get_by_id(self.bill.id) self.assertTrue(bill.state.is_REJECTED) places_storage.sync(force=True) self.place1.sync_parameters() self.assertEqual(self.place1.stability, 1.0) self.assertEqual(bill.applyed_at_turn, current_time.turn_number) self.check_place(self.place1.id, self.place1.name, self.place1.utg_name.forms)
def test_not_enough_voices_percents(self): current_time = TimePrototype.get_current_time() 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.REFRAINED) 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.assertFalse(self.bill.apply()) self.assertEqual(cmd_run_account_method.call_count, 0) self.assertTrue(self.bill.state.is_REJECTED) self.assertEqual(Post.objects.all().count(), 2) bill = BillPrototype.get_by_id(self.bill.id) self.assertTrue(bill.state.is_REJECTED) places_storage.sync(force=True) self.place1.sync_parameters() self.assertEqual(self.place1.stability, 1.0) self.assertEqual(bill.applyed_at_turn, current_time.turn_number) self.check_place(self.place1.id, self.place1.name, self.place1.utg_name.forms)
def test_wrong_state(self): self.bill.state = relations.BILL_STATE.ACCEPTED self.bill.save() self.assertRaises(exceptions.ApplyBillInWrongStateError, self.bill.apply) places_storage.sync(force=True) self.check_place(self.place1.id, self.place1.name, self.place1.utg_name.forms)
def test_not_approved(self): self.bill.approved_by_moderator = False self.bill.save() self.assertRaises(exceptions.ApplyUnapprovedBillError, self.bill.apply) places_storage.sync(force=True) self.assertEqual(self.bill.applyed_at_turn, None) self.check_place(self.place1.id, self.place1.name, self.place1.utg_name.forms)
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)
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)
def test_wrong_time(self): self.assertRaises(exceptions.ApplyBillBeforeVoteWasEndedError, self.bill.apply) places_storage.sync(force=True) self.check_place(self.place1.id, self.place1.name, self.place1.utg_name.forms)