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

        old_storage_version = places_storage.resource_exchanges._version

        self.assertEqual(len(places_storage.resource_exchanges.all()), 1)

        data = self.bill.user_form_initials
        data["approved"] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.assertTrue(self.bill.apply())

        self.bill.state = relations.BILL_STATE.VOTING
        self.bill.save()

        with mock.patch("the_tale.game.bills.prototypes.BillPrototype.decline") as skipped_decline:
            self.assertTrue(self.bill.apply())

        self.assertEqual(skipped_decline.call_count, 0)

        self.assertNotEqual(old_storage_version, places_storage.resource_exchanges._version)
        self.assertEqual(len(places_storage.resource_exchanges.all()), 0)

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

        declined_bill = BillPrototype.get_by_id(self.declined_bill.id)
        self.assertTrue(declined_bill.state.is_ACCEPTED)
        self.assertTrue(declined_bill.is_declined)
        self.assertTrue(declined_bill.declined_by.id, bill.id)
Exemplo n.º 2
0
    def test_apply(self):
        self.assertEqual(Building.objects.all().count(), 0)

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

        noun = names.generator().get_test_name('r-building-name')

        data = self.bill.user_form_initials
        data.update(linguistics_helpers.get_word_post_data(noun, prefix='name'))
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.assertTrue(self.bill.apply())

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

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

        building = places_storage.buildings.all()[0]

        self.assertEqual(building.person.id, self.person_1.id)
        self.assertEqual(building.place.id, self.place1.id)
        self.assertEqual(building.utg_name, noun)
Exemplo n.º 3
0
    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 self.check_not_changed(lambda: self.place1.attrs.stability):
            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.places.sync(force=True)

            self.place1.refresh_attributes()

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

        self.check_place(self.place1.id, self.place1.name, self.place1.utg_name.forms)
Exemplo n.º 4
0
    def test_reapply(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        old_storage_version = resource_exchange_storage._version

        self.assertEqual(len(resource_exchange_storage.all()), 1)

        form = BillDecline.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertTrue(self.bill.apply())

        self.bill.state = BILL_STATE.VOTING
        self.bill.save()

        with mock.patch('the_tale.game.bills.prototypes.BillPrototype.decline') as skipped_decline:
            self.assertTrue(self.bill.apply())

        self.assertEqual(skipped_decline.call_count, 0)

        self.assertNotEqual(old_storage_version, resource_exchange_storage._version)
        self.assertEqual(len(resource_exchange_storage.all()), 0)

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

        declined_bill = BillPrototype.get_by_id(self.declined_bill.id)
        self.assertTrue(declined_bill.state.is_ACCEPTED)
        self.assertTrue(declined_bill.is_declined)
        self.assertTrue(declined_bill.declined_by.id, bill.id)
Exemplo n.º 5
0
    def test_apply(self):
        self.assertEqual(Building.objects.all().count(), 0)

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

        noun = names.generator().get_test_name('r-building-name')

        data = self.bill.user_form_initials
        data.update(linguistics_helpers.get_word_post_data(noun,
                                                           prefix='name'))
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.assertTrue(self.bill.apply())

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

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

        building = places_storage.buildings.all()[0]

        self.assertEqual(building.person.id, self.person_1.id)
        self.assertEqual(building.place.id, self.place1.id)
        self.assertEqual(building.x, self.accepted_position_1[0])
        self.assertEqual(building.y, self.accepted_position_1[1])
        self.assertEqual(building.utg_name, noun)
Exemplo n.º 6
0
    def test_apply_without_person(self):
        self.assertEqual(Building.objects.all().count(), 0)

        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

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

        data = linguistics_helpers.get_word_post_data(noun, prefix='name')
        data.update({'approved': True})

        form = BuildingCreate.ModeratorForm(data)

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

        self.person_1.move_out_game()

        self.assertTrue(self.bill.apply())

        bill = BillPrototype.get_by_id(self.bill.id)
        bill.state = BILL_STATE.VOTING
        bill.save()

        self.assertTrue(bill.apply())

        self.assertEqual(Building.objects.all().count(), 0)
Exemplo n.º 7
0
    def test_duplicate_apply(self):
        self.assertEqual(Building.objects.all().count(), 0)

        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

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

        form = BuildingCreate.ModeratorForm(data)

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

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

        form = BuildingCreate.ModeratorForm(data)

        bill = BillPrototype.get_by_id(self.bill.id)
        bill.state = BILL_STATE.VOTING
        bill.save()

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

        self.assertTrue(bill.apply())

        self.assertEqual(Building.objects.all().count(), 1)
        self.assertEqual(BuildingPrototype._db_get_object(0).utg_name, noun)
        self.assertNotEqual(BuildingPrototype._db_get_object(0).utg_name, dup_noun)
Exemplo n.º 8
0
    def test_reapply(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        old_storage_version = places_storage.resource_exchanges._version

        self.assertEqual(len(places_storage.resource_exchanges.all()), 1)

        form = BillDecline.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertTrue(self.bill.apply())

        self.bill.state = BILL_STATE.VOTING
        self.bill.save()

        with mock.patch('the_tale.game.bills.prototypes.BillPrototype.decline'
                        ) as skipped_decline:
            self.assertTrue(self.bill.apply())

        self.assertEqual(skipped_decline.call_count, 0)

        self.assertNotEqual(old_storage_version,
                            places_storage.resource_exchanges._version)
        self.assertEqual(len(places_storage.resource_exchanges.all()), 0)

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

        declined_bill = BillPrototype.get_by_id(self.declined_bill.id)
        self.assertTrue(declined_bill.state.is_ACCEPTED)
        self.assertTrue(declined_bill.is_declined)
        self.assertTrue(declined_bill.declined_by.id, bill.id)
Exemplo n.º 9
0
    def test_apply(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        old_storage_version = places_storage.resource_exchanges._version

        self.assertEqual(len(places_storage.resource_exchanges.all()), 1)

        form = BillDecline.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertTrue(self.bill.apply())

        self.assertNotEqual(old_storage_version,
                            places_storage.resource_exchanges._version)
        self.assertEqual(len(places_storage.resource_exchanges.all()), 0)

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

        declined_bill = BillPrototype.get_by_id(self.declined_bill.id)
        self.assertTrue(declined_bill.state.is_ACCEPTED)
        self.assertTrue(declined_bill.is_declined)
        self.assertTrue(declined_bill.declined_by.id, bill.id)
Exemplo n.º 10
0
    def test_apply(self):
        self.assertEqual(Building.objects.all().count(), 0)

        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        noun = names.generator.get_test_name('r-building-name')

        data = linguistics_helpers.get_word_post_data(noun, prefix='name')
        data.update({'approved': True})

        form = BuildingCreate.ModeratorForm(data)

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

        self.assertTrue(self.bill.apply())

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

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

        building = buildings_storage.all()[0]

        self.assertEqual(building.person.id, self.person_1.id)
        self.assertEqual(building.place.id, self.place1.id)
        self.assertEqual(building.utg_name, noun)
Exemplo n.º 11
0
    def test_apply(self):
        VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)

        old_storage_version = places_storage.resource_exchanges._version

        self.assertEqual(len(places_storage.resource_exchanges.all()), 1)

        data = self.bill.user_form_initials
        data["approved"] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.assertTrue(self.bill.apply())

        self.assertNotEqual(old_storage_version, places_storage.resource_exchanges._version)
        self.assertEqual(len(places_storage.resource_exchanges.all()), 0)

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

        declined_bill = BillPrototype.get_by_id(self.declined_bill.id)
        self.assertTrue(declined_bill.state.is_ACCEPTED)
        self.assertTrue(declined_bill.is_declined)
        self.assertTrue(declined_bill.declined_by.id, bill.id)
Exemplo n.º 12
0
    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 self.check_not_changed(lambda: self.place1.attrs.stability):
            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.places.sync(force=True)

            self.place1.refresh_attributes()

        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 apply_bill(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PlaceResourceExchange.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertEqual(len(places_storage.resource_exchanges.all()), 0)

        self.assertTrue(self.bill.apply())
Exemplo n.º 14
0
    def test_is_make_sense__person_out_game(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PersonChronicle.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.bill.data.person.move_out_game()

        self.assertFalse(self.bill.has_meaning())
Exemplo n.º 15
0
    def apply_bill(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PlaceResourceConversion.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertEqual(len(places_storage.resource_exchanges.all()), 0)

        self.assertTrue(self.bill.apply())
    def test_has_meaning__person_out_game(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PersonRemove.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.bill.data.person.move_out_game()

        self.assertFalse(self.bill.has_meaning())
Exemplo n.º 17
0
    def test_has_meaning__duplicate_modifier(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PlaceModifier.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.bill.data.place.modifier = self.bill.data.modifier_id
        self.bill.data.place.save()

        self.assertFalse(self.bill.has_meaning())
    def test_has_meaning__duplicate_modifier(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PlaceModifier.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.bill.data.place.modifier = self.bill.data.modifier_id
        self.bill.data.place.save()

        self.assertFalse(self.bill.has_meaning())
    def test_has_meaning__duplicate_description(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PlaceDescripton.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.place.description = 'new description'
        self.place.save()

        self.assertFalse(self.bill.has_meaning())
Exemplo n.º 20
0
    def test_apply(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PlaceModifier.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertTrue(self.bill.apply())

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

        self.assertTrue(self.place._modifier.is_TRADE_CENTER)
Exemplo n.º 21
0
    def test_apply(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PlaceModifier.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertTrue(self.bill.apply())

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

        self.assertTrue(self.place._modifier.is_TRADE_CENTER)
Exemplo n.º 22
0
    def test_has_meaning(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = BillDecline.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertTrue(self.bill.has_meaning())

        self.declined_bill.is_declined = True
        self.declined_bill.save()

        self.assertFalse(self.bill.has_meaning())
Exemplo n.º 23
0
    def test_has_meaning__no_building(self):
        self.assertEqual(Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 2)

        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = BuildingDestroy.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.building_1.destroy()
        self.building_1.save()

        self.assertFalse(self.bill.has_meaning())
Exemplo n.º 24
0
    def apply_bill(self):
        VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)

        data = self.bill.user_form_initials
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.assertEqual(len(places_storage.resource_exchanges.all()), 0)

        self.assertTrue(self.bill.apply())
    def test_has_meaning__no_building(self):
        self.assertEqual(
            Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 2)

        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = BuildingDestroy.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.building_1.destroy()
        self.building_1.save()

        self.assertFalse(self.bill.has_meaning())
Exemplo n.º 26
0
    def test_apply(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PlaceDescripton.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertTrue(self.bill.apply())

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

        self.assertNotEqual(self.place.description, 'old description' )
        self.assertEqual(self.place.description, 'new description' )
Exemplo n.º 27
0
    def test_has_meaning__duplicate_description(self):
        VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)

        data = self.bill.user_form_initials
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.place.description = 'new description'
        places_logic.save_place(self.place)

        self.assertFalse(self.bill.has_meaning())
Exemplo n.º 28
0
    def test_votes_agains_count(self):
        VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.REFRAINED)

        self.assertEqual(VotePrototype.votes_against_count(self.account1.id), 0)
        self.assertEqual(VotePrototype.votes_against_count(self.account2.id), 1)
        self.assertEqual(VotePrototype.votes_against_count(self.account3.id), 0)
        self.assertEqual(VotePrototype.votes_against_count(self.account4.id), 0)
Exemplo n.º 29
0
    def get_achievement_type_value(self, achievement_type):
        from the_tale.game.bills.prototypes import BillPrototype, VotePrototype

        if achievement_type.is_POLITICS_ACCEPTED_BILLS:
            return BillPrototype.accepted_bills_count(self.id)
        elif achievement_type.is_POLITICS_VOTES_TOTAL:
            return VotePrototype.votes_count(self.id)
        elif achievement_type.is_POLITICS_VOTES_FOR:
            return VotePrototype.votes_for_count(self.id)
        elif achievement_type.is_POLITICS_VOTES_AGAINST:
            return VotePrototype.votes_against_count(self.id)
        elif achievement_type.is_KEEPER_MIGHT:
            return self.might

        raise exceptions.UnkwnownAchievementTypeError(achievement_type=achievement_type)
Exemplo n.º 30
0
    def test_votes_agains_count(self):
        VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.REFRAINED)

        self.assertEqual(VotePrototype.votes_against_count(self.account1.id), 0)
        self.assertEqual(VotePrototype.votes_against_count(self.account2.id), 1)
        self.assertEqual(VotePrototype.votes_against_count(self.account3.id), 0)
        self.assertEqual(VotePrototype.votes_against_count(self.account4.id), 0)
Exemplo n.º 31
0
    def test_apply(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PlaceModifier.ModeratorForm({"approved": True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertTrue(self.bill.apply())

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

        self.assertNotEqual(self.place.modifier, None)
        self.assertEqual(self.place.modifier, TradeCenter(self.place))
Exemplo n.º 32
0
    def get_achievement_type_value(self, achievement_type):
        from the_tale.game.bills.prototypes import BillPrototype, VotePrototype

        if achievement_type.is_POLITICS_ACCEPTED_BILLS:
            return BillPrototype.accepted_bills_count(self.id)
        elif achievement_type.is_POLITICS_VOTES_TOTAL:
            return VotePrototype.votes_count(self.id)
        elif achievement_type.is_POLITICS_VOTES_FOR:
            return VotePrototype.votes_for_count(self.id)
        elif achievement_type.is_POLITICS_VOTES_AGAINST:
            return VotePrototype.votes_against_count(self.id)
        elif achievement_type.is_KEEPER_MIGHT:
            return self.might

        raise exceptions.UnkwnownAchievementTypeError(achievement_type=achievement_type)
Exemplo n.º 33
0
    def test_apply(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PlaceDescripton.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertTrue(self.bill.apply())

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

        self.assertNotEqual(self.place.description, 'old description')
        self.assertEqual(self.place.description, 'new description')
Exemplo n.º 34
0
    def apply_bill(self):
        VotePrototype.create(self.account2, self.bill,
                             relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)

        data = self.bill.user_form_initials
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.assertEqual(len(places_storage.resource_exchanges.all()), 0)

        self.assertTrue(self.bill.apply())
Exemplo n.º 35
0
    def check_apply(self, change_power_mock):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PersonChronicle.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        with mock.patch('the_tale.game.persons.prototypes.PersonPrototype.cmd_change_power') as cmd_change_power:
            self.assertTrue(self.bill.apply())

        self.assertEqual(cmd_change_power.call_args_list, change_power_mock)

        bill = BillPrototype.get_by_id(self.bill.id)
        self.assertTrue(bill.state.is_ACCEPTED)
Exemplo n.º 36
0
    def test_has_meaning__duplicate_description(self):
        VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)

        data = self.bill.user_form_initials
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.place.description = 'new description'
        places_logic.save_place(self.place)

        self.assertFalse(self.bill.has_meaning())
    def test_apply(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PersonRemove.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertTrue(self.bill.apply())

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

        self.assertNotEqual(self.place1.persons[0].id, self.person1.id)
        self.assertTrue(self.person1.out_game)
        self.assertTrue(Person.objects.get(id=self.person1.id).state, PERSON_STATE.OUT_GAME)
Exemplo n.º 38
0
    def test_has_meaning__duplicate(self):
        self.assertEqual(Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 2)

        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = BuildingDestroy.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)
        self.assertTrue(self.bill.apply())

        bill = BillPrototype.get_by_id(self.bill.id)
        bill.state = BILL_STATE.VOTING
        bill.save()

        self.assertFalse(bill.has_meaning())
Exemplo n.º 39
0
    def apply_bill(self):
        VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)

        form = PlaceResourceConversion.ModeratorForm({'caption': 'long caption',
                                                      'rationale': 'long rationale',
                                                      'chronicle_on_accepted': 'chronicle-on-accepted',
                                                      'place': self.place1.id,
                                                      'conversion': self.conversion_1,
                                                      'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertEqual(len(places_storage.resource_exchanges.all()), 0)

        self.assertTrue(self.bill.apply())
Exemplo n.º 40
0
    def test_has_meaning__no_building(self):
        self.assertEqual(Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 2)

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

        data = self.bill.user_form_initials
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        places_logic.destroy_building(self.building_1)

        self.assertFalse(self.bill.has_meaning())
Exemplo n.º 41
0
    def check_apply(self, change_power_mock):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PersonChronicle.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        with mock.patch('the_tale.game.persons.objects.Person.cmd_change_power'
                        ) as cmd_change_power:
            self.assertTrue(self.bill.apply())

        self.assertEqual(cmd_change_power.call_args_list, change_power_mock)

        bill = BillPrototype.get_by_id(self.bill.id)
        self.assertTrue(bill.state.is_ACCEPTED)
Exemplo n.º 42
0
    def test_apply(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PersonRemove.ModeratorForm({"approved": True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertTrue(self.bill.apply())

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

        self.assertNotEqual(self.place1.persons[0].id, self.person1.id)
        self.assertTrue(self.person1.out_game)
        self.assertTrue(Person.objects.get(id=self.person1.id).state, PERSON_STATE.OUT_GAME)
Exemplo n.º 43
0
    def test_vote_refrained_achievements(self):
        with mock.patch('the_tale.accounts.achievements.storage.AchievementsStorage.verify_achievements') as verify_achievements:
            VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.REFRAINED)

        self.assertEqual(verify_achievements.call_args_list, [mock.call(account_id=self.account2.id,
                                                                        type=ACHIEVEMENT_TYPE.POLITICS_VOTES_TOTAL,
                                                                        old_value=0,
                                                                        new_value=1),
                                                              mock.call(account_id=self.account2.id,
                                                                        type=ACHIEVEMENT_TYPE.POLITICS_VOTES_FOR,
                                                                        old_value=0,
                                                                        new_value=0),
                                                              mock.call(account_id=self.account2.id,
                                                                        type=ACHIEVEMENT_TYPE.POLITICS_VOTES_AGAINST,
                                                                        old_value=0,
                                                                        new_value=0)])
Exemplo n.º 44
0
    def test_vote_refrained_achievements(self):
        with mock.patch('the_tale.accounts.achievements.storage.AchievementsStorage.verify_achievements') as verify_achievements:
            VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.REFRAINED)

        self.assertEqual(verify_achievements.call_args_list, [mock.call(account_id=self.account2.id,
                                                                        type=ACHIEVEMENT_TYPE.POLITICS_VOTES_TOTAL,
                                                                        old_value=0,
                                                                        new_value=1),
                                                              mock.call(account_id=self.account2.id,
                                                                        type=ACHIEVEMENT_TYPE.POLITICS_VOTES_FOR,
                                                                        old_value=0,
                                                                        new_value=0),
                                                              mock.call(account_id=self.account2.id,
                                                                        type=ACHIEVEMENT_TYPE.POLITICS_VOTES_AGAINST,
                                                                        old_value=0,
                                                                        new_value=0)])
Exemplo n.º 45
0
    def test_has_meaning(self):
        VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)

        data = self.bill.user_form_initials
        data["approved"] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.assertTrue(self.bill.has_meaning())

        self.declined_bill.is_declined = True
        self.declined_bill.save()

        self.assertFalse(self.bill.has_meaning())
    def test_has_meaning__duplicate(self):
        self.assertEqual(
            Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 2)

        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = BuildingDestroy.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)
        self.assertTrue(self.bill.apply())

        bill = BillPrototype.get_by_id(self.bill.id)
        bill.state = BILL_STATE.VOTING
        bill.save()

        self.assertFalse(bill.has_meaning())
Exemplo n.º 47
0
    def test_has_meaning__no_building(self):
        self.assertEqual(Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 2)

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

        data = self.bill.user_form_initials
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.building_1.destroy()
        self.building_1.save()

        self.assertFalse(self.bill.has_meaning())
Exemplo n.º 48
0
    def test_apply(self):
        VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)

        data = self.bill.user_form_initials
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.assertTrue(self.bill.apply())

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

        self.assertTrue(self.place._modifier.is_TRADE_CENTER)
    def test_apply(self):
        VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)

        data = self.bill.user_form_initials
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.assertTrue(self.bill.apply())

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

        self.assertFalse(persons_storage.social_connections.is_connected(self.person_1_1, self.person_2_1))
Exemplo n.º 50
0
    def test_apply(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PersonMove.ModeratorForm({'approved': True})

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

        self.assertTrue(self.bill.apply())

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

        person = persons_storage.persons[self.person_1.id]

        self.assertEqual(person.place.id, self.place2.id)
Exemplo n.º 51
0
    def test_duplicate_apply(self):
        self.assertEqual(Building.objects.all().count(), 0)

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

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

        data = self.bill.user_form_initials
        data.update(linguistics_helpers.get_word_post_data(noun,
                                                           prefix='name'))
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        dup_noun = names.generator().get_test_name('dup-building-name')

        bill = BillPrototype.get_by_id(self.bill.id)
        bill.state = relations.BILL_STATE.VOTING
        bill.save()

        data = bill.user_form_initials
        data.update(
            linguistics_helpers.get_word_post_data(dup_noun, prefix='name'))
        data['approved'] = True
        form = bill.data.get_moderator_form_update(data)

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

        # apply first bill
        self.assertTrue(self.bill.apply())

        # apply second bill
        self.assertTrue(bill.apply())

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

        building = places_logic.load_building(Building.objects.all()[0].id)

        self.assertEqual(building.utg_name, noun)
        self.assertNotEqual(building.utg_name, dup_noun)
Exemplo n.º 52
0
    def test_has_meaning(self):
        VotePrototype.create(self.account2, self.bill,
                             relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)

        data = self.bill.user_form_initials
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.assertTrue(self.bill.has_meaning())

        self.declined_bill.is_declined = True
        self.declined_bill.save()

        self.assertFalse(self.bill.has_meaning())
Exemplo n.º 53
0
    def test_apply(self):
        VotePrototype.create(self.account2, self.bill,
                             relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)

        data = self.bill.user_form_initials
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.assertTrue(self.bill.apply())

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

        self.assertTrue(self.place.race.is_GOBLIN)
Exemplo n.º 54
0
    def apply_bill(self):
        VotePrototype.create(self.account2, self.bill,
                             relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)

        form = PlaceResourceConversion.ModeratorForm({
            'caption': 'long caption',
            'chronicle_on_accepted': 'chronicle-on-accepted',
            'place': self.place1.id,
            'conversion': self.conversion_1,
            'approved': True
        })
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertEqual(len(places_storage.resource_exchanges.all()), 0)

        self.assertTrue(self.bill.apply())
Exemplo n.º 55
0
    def test_apply_without_person(self):
        self.assertEqual(Building.objects.all().count(), 0)

        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

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

        data = linguistics_helpers.get_word_post_data(noun, prefix='name')
        data.update({'approved': True})

        form = BuildingCreate.ModeratorForm(data)

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

        self.person_1.move_out_game()

        self.assertFalse(self.bill.has_meaning())
Exemplo n.º 56
0
    def test_has_meaning__duplicate(self):
        self.assertEqual(Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 2)

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

        data = self.bill.user_form_initials
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        bill = BillPrototype.get_by_id(self.bill.id)
        bill.state = relations.BILL_STATE.VOTING
        bill.save()

        self.assertFalse(bill.has_meaning())
Exemplo n.º 57
0
    def test_has_meaning__already_in_town(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PersonMove.ModeratorForm({'approved': True})

        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)
        self.assertTrue(self.bill.has_meaning())
        self.assertTrue(self.bill.apply())

        bill = BillPrototype.get_by_id(self.bill.id)
        bill.state = BILL_STATE.VOTING
        bill.save()

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

        self.assertFalse(bill.has_meaning())