本文整理汇总了Python中the_tale.game.bills.prototypes.BillPrototype类的典型用法代码示例。如果您正苦于以下问题:Python BillPrototype类的具体用法?Python BillPrototype怎么用?Python BillPrototype使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BillPrototype类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_bill_decline__exchange
def create_bill_decline__exchange(self):
resource_1, resource_2 = choose_exchange_resources()
declined_bill_data = bills.PlaceResourceExchange(
place_1_id=self.place_1.id, place_2_id=self.place_2.id, resource_1=resource_1, resource_2=resource_2
)
declined_bill = BillPrototype.create(
self.account,
"declined-bill-caption",
"declined-bill-rationale",
declined_bill_data,
chronicle_on_accepted="chronicle-on-accepted",
)
declined_form = bills.PlaceResourceExchange.ModeratorForm({"approved": True})
self.assertTrue(declined_form.is_valid())
declined_bill.update_by_moderator(declined_form)
declined_bill.apply()
bill_data = bills.BillDecline(declined_bill_id=declined_bill.id)
bill = BillPrototype.create(
self.account, "bill-caption", "bill-rationale", bill_data, chronicle_on_accepted="chronicle-on-accepted"
)
return bill, declined_bill
示例2: test_update
def test_update(self):
declined_bill_2 = BillPrototype.create(
self.account1,
"declined-bill-caption",
"declined-bill-rationale",
self.declined_bill_data,
chronicle_on_accepted="chronicle-on-accepted-2",
)
data = declined_bill_2.user_form_initials
data["approved"] = True
declined_form = declined_bill_2.data.get_moderator_form_update(data)
self.assertTrue(declined_form.is_valid())
declined_bill_2.update_by_moderator(declined_form)
declined_bill_2.apply()
form = self.bill.data.get_user_form_update(
post={
"caption": "new-caption",
"rationale": "new-rationale",
"chronicle_on_accepted": "chronicle-on-accepted-3",
"declined_bill": declined_bill_2.id,
}
)
self.assertTrue(form.is_valid())
self.bill.update(form)
self.bill = BillPrototype.get_by_id(self.bill.id)
self.assertEqual(self.bill.data.declined_bill_id, declined_bill_2.id)
示例3: test_reapply
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)
示例4: setUp
def setUp(self):
super(BillDeclineResourceExchangeTests, self).setUp()
self.resource_1, self.resource_2 = choose_exchange_resources()
self.declined_bill_data = PlaceResourceExchange(
place_1_id=self.place1.id, place_2_id=self.place2.id, resource_1=self.resource_1, resource_2=self.resource_2
)
self.declined_bill = BillPrototype.create(
owner=self.account1,
caption="declined-bill-caption",
rationale="declined-bill-rationale",
chronicle_on_accepted="chronicle-on-accepted",
bill=self.declined_bill_data,
)
data = self.declined_bill.user_form_initials
data["approved"] = True
declined_form = self.declined_bill.data.get_moderator_form_update(data)
self.assertTrue(declined_form.is_valid())
self.declined_bill.update_by_moderator(declined_form)
self.declined_bill.apply()
self.bill_data = BillDecline(declined_bill_id=self.declined_bill.id)
self.bill = BillPrototype.create(
self.account1,
"bill-caption",
"bill-rationale",
self.bill_data,
chronicle_on_accepted="chronicle-on-accepted",
)
示例5: test_reapply
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)
示例6: test_get_minimum_created_time_of_active_bills
def test_get_minimum_created_time_of_active_bills(self):
self.assertEqual(self.bill.created_at, BillPrototype.get_minimum_created_time_of_active_bills())
self.bill.remove(initiator=self.account1)
# not there are no anothe bills an get_minimum_created_time_of_active_bills return now()
self.assertTrue(self.bill.created_at < BillPrototype.get_minimum_created_time_of_active_bills())
示例7: test_apply
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)
示例8: setUp
def setUp(self):
super(GetApplicableBillsTest, self).setUp()
self.bill_data = PlaceDescripton(place_id=self.place1.id, description='description')
self.bill_1 = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
self.bill_2 = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
self.bill_3 = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
BillPrototype._model_class.objects.all().update(updated_at=datetime.datetime.now() - datetime.timedelta(seconds=bills_settings.BILL_LIVE_TIME),
approved_by_moderator=True)
self.bill_1.reload()
self.bill_2.reload()
self.bill_3.reload()
示例9: test_accepted_bills_count
def test_accepted_bills_count(self):
for state in relations.BILL_STATE.records:
bill = self.create_bill(self.account1)
bill.state = state
bill.save()
for state in relations.BILL_STATE.records:
bill = self.create_bill(self.account2)
bill.state = state
bill.save()
self.assertEqual(BillPrototype.accepted_bills_count(self.account1.id), 1)
self.assertEqual(BillPrototype.accepted_bills_count(self.account2.id), 1)
self.assertEqual(BillPrototype.accepted_bills_count(self.account3.id), 0)
示例10: test_user_form_validation__wrong_bill
def test_user_form_validation__wrong_bill(self):
bill_data = PlaceDescripton(place_id=self.place1.id, description="new description")
bill = BillPrototype.create(
self.account1,
"bill-1-caption",
"bill-1-rationale",
bill_data,
chronicle_on_accepted="chronicle-on-accepted",
)
data = bill.user_form_initials
data["approved"] = True
form = bill.data.get_moderator_form_update(data)
self.assertTrue(form.is_valid())
bill.update_by_moderator(form)
self.assertTrue(bill.apply())
form = self.bill.data.get_user_form_update(
post={
"caption": "caption",
"rationale": "rationale",
"chronicle_on_accepted": "chronicle-on-accepted-3",
"declined_bill": bill.id,
}
)
self.assertFalse(form.is_valid())
示例11: test_update
def test_update(self):
self.person_2_2.politic_power.change_power(
self.person_2_2, hero_id=self.account.id, has_in_preferences=True, power=100
)
persons_logic.create_social_connection(
connection_type=persons_relations.SOCIAL_CONNECTION_TYPE.PARTNER,
person_1=self.person_2_2,
person_2=self.person_3_1,
)
data = {
"caption": "new-caption",
"rationale": "new-rationale",
"chronicle_on_accepted": "new-chronicle-on-accepted",
"person_1": self.person_2_2.id,
"person_2": self.person_3_1.id,
}
form = self.bill.data.get_user_form_update(post=data, owner_id=self.account.id)
self.assertTrue(form.is_valid())
self.bill.update(form)
self.bill = BillPrototype.get_by_id(self.bill.id)
self.assertEqual(self.bill.data.person_1_id, self.person_2_2.id)
self.assertEqual(self.bill.data.person_2_id, self.person_3_1.id)
self.assertEqual(self.bill.data.place_1_id, self.place2.id)
self.assertEqual(self.bill.data.place_2_id, self.place3.id)
self.assertEqual(self.bill.data.old_place_1_name, self.place2.utg_name)
self.assertEqual(self.bill.data.old_place_2_name, self.place3.utg_name)
示例12: setUp
def setUp(self):
super(PersonRemoveSocialConnectionTests, self).setUp()
self.person_1_1 = self.place1.persons[0]
self.person_2_1, self.person_2_2 = self.place2.persons[0:2]
self.person_3_1 = self.place3.persons[0]
self.account = self.accounts_factory.create_account()
persons_logic.create_social_connection(
connection_type=persons_relations.SOCIAL_CONNECTION_TYPE.PARTNER,
person_1=self.person_1_1,
person_2=self.person_2_1,
)
self.bill_data = PersonRemoveSocialConnection(person_1_id=self.person_1_1.id, person_2_id=self.person_2_1.id)
self.bill = BillPrototype.create(
self.account1,
"bill-1-caption",
"bill-1-rationale",
self.bill_data,
chronicle_on_accepted="chronicle-on-accepted",
)
self.person_1_1.politic_power.change_power(
self.person_1_1, hero_id=self.account.id, has_in_preferences=True, power=100
)
示例13: create_bill_decline__conversion
def create_bill_decline__conversion(self):
conversion_1, conversion_2 = choose_conversions()
declined_bill_data = bills.PlaceResourceConversion(place_id=self.place_1.id,
conversion=conversion_1)
declined_bill = BillPrototype.create(self.account, 'declined-bill-caption', 'declined-bill-rationale', declined_bill_data, chronicle_on_accepted='chronicle-on-accepted')
declined_form = bills.PlaceResourceConversion.ModeratorForm({'approved': True})
self.assertTrue(declined_form.is_valid())
declined_bill.update_by_moderator(declined_form)
declined_bill.apply()
bill_data = bills.BillDecline(declined_bill_id=declined_bill.id)
bill = BillPrototype.create(self.account, 'bill-caption', 'bill-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted')
return bill, declined_bill
示例14: test_update
def test_update(self):
form = self.bill.data.get_user_form_update(post={'caption': 'new-caption',
'rationale': 'new-rationale',
'chronicle_on_accepted': 'chronicle-on-accepted-2',
'place_1': self.place2.id,
'place_2': self.place1.id,
'resource_1': self.resource_2,
'resource_2': self.resource_1})
self.assertTrue(form.is_valid())
self.bill.update(form)
self.bill = BillPrototype.get_by_id(self.bill.id)
self.assertEqual(self.bill.data.place_1_id, self.place2.id)
self.assertEqual(self.bill.data.place_2_id, self.place1.id)
self.assertEqual(self.bill.data.resource_1, self.resource_2)
self.assertEqual(self.bill.data.resource_2, self.resource_1)
self.assertEqual(self.bill.data.old_place_1_name_forms, self.place2.utg_name)
self.assertEqual(self.bill.data.old_place_2_name_forms, self.place1.utg_name)
self.assertEqual(self.bill.data.place_1.id, self.place2.id)
self.assertEqual(self.bill.data.place_2.id, self.place1.id)
self.assertEqual(self.bill.data.old_place_1_name, self.place2.utg_name.normal_form())
self.assertEqual(self.bill.data.old_place_2_name, self.place1.utg_name.normal_form())
self.assertFalse(self.bill.data.place_2_name_changed)
self.assertFalse(self.bill.data.place_1_name_changed)
示例15: test_apply
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)