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)
Exemple #2
0
    def test_create(self):
        self.assertEqual(len(resource_exchange_storage.all()), 0)

        old_version = resource_exchange_storage._version

        exchange = ResourceExchangePrototype.create(place_1=self.place_1,
                                                    place_2=self.place_2,
                                                    resource_1=self.resource_1,
                                                    resource_2=self.resource_2,
                                                    bill=None)

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

        self.assertEqual(exchange.id, resource_exchange_storage.all()[0].id)
        self.assertNotEqual(old_version, resource_exchange_storage._version)
Exemple #3
0
    def test_create(self):
        self.assertEqual(len(resource_exchange_storage.all()), 0)

        old_version = resource_exchange_storage._version

        exchange = ResourceExchangePrototype.create(place_1=self.place_1,
                                                    place_2=self.place_2,
                                                    resource_1=self.resource_1,
                                                    resource_2=self.resource_2,
                                                    bill=None)

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

        self.assertEqual(exchange.id, resource_exchange_storage.all()[0].id)
        self.assertNotEqual(old_version, resource_exchange_storage._version)
Exemple #4
0
 def __init__(self, *args, **kwargs):
     super(UserForm, self).__init__(*args, **kwargs)
     bills = [
         exchange.bill for exchange in resource_exchange_storage.all()
         if exchange.bill
     ]
     self.fields['declined_bill'].choices = [(bill.id, bill.caption)
                                             for bill in bills]
    def test_apply(self):

        old_storage_version = resource_exchange_storage._version

        self.apply_bill()

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

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

        exchange = resource_exchange_storage.all()[0]

        self.assertEqual(set([exchange.place_1.id, exchange.place_2.id]), set([self.place1.id, self.place2.id]))
        self.assertEqual(set([exchange.resource_1, exchange.resource_2]), set([self.resource_1, self.resource_2]))
        self.assertEqual(exchange.bill_id, bill.id)
    def test_end__success(self):
        self.apply_bill()

        old_storage_version = resource_exchange_storage._version

        self.bill.end()

        self.assertNotEqual(old_storage_version, resource_exchange_storage._version)

        self.assertEqual(len(resource_exchange_storage.all()), 0)
Exemple #7
0
    def test_end__success(self):
        self.apply_bill()

        old_storage_version = resource_exchange_storage._version

        self.bill.end()

        self.assertNotEqual(old_storage_version,
                            resource_exchange_storage._version)

        self.assertEqual(len(resource_exchange_storage.all()), 0)
Exemple #8
0
    def test_apply(self):

        old_storage_version = resource_exchange_storage._version

        self.apply_bill()

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

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

        exchange = resource_exchange_storage.all()[0]

        self.assertEqual(exchange.place_1.id, self.place1.id)
        self.assertEqual(exchange.place_2, None)
        self.assertEqual(exchange.resource_1, self.conversion_1.resource_from)
        self.assertEqual(exchange.resource_2, self.conversion_1.resource_to)
        self.assertEqual(exchange.bill_id, bill.id)
Exemple #9
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(resource_exchange_storage.all()), 0)

        self.assertTrue(self.bill.apply())
    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(resource_exchange_storage.all()), 0)

        self.assertTrue(self.bill.apply())
    def test_decline__success(self):
        self.apply_bill()

        old_storage_version = resource_exchange_storage._version

        decliner = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')

        self.bill.decline(decliner)

        self.assertNotEqual(old_storage_version, resource_exchange_storage._version)

        self.assertEqual(len(resource_exchange_storage.all()), 0)
    def test_end__no_excange(self):
        self.apply_bill()

        ResourceExchangePrototype._db_all().delete()

        resource_exchange_storage.refresh()

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

        old_storage_version = resource_exchange_storage._version

        self.bill.end()

        self.assertEqual(old_storage_version, resource_exchange_storage._version)
    def test_apply(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.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)
Exemple #14
0
    def test_end__no_excange(self):
        self.apply_bill()

        ResourceExchangePrototype._db_all().delete()

        resource_exchange_storage.refresh()

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

        old_storage_version = resource_exchange_storage._version

        self.bill.end()

        self.assertEqual(old_storage_version,
                         resource_exchange_storage._version)
    def test_decline__no_excange(self):
        self.apply_bill()

        ResourceExchangePrototype._db_all().delete()

        resource_exchange_storage.refresh()

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

        old_storage_version = resource_exchange_storage._version

        decliner = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted-2')

        self.bill.decline(decliner)

        self.assertEqual(old_storage_version, resource_exchange_storage._version)
Exemple #16
0
    def test_decline__success(self):
        self.apply_bill()

        old_storage_version = resource_exchange_storage._version

        decliner = BillPrototype.create(
            self.account1,
            'bill-1-caption',
            'bill-1-rationale',
            self.bill_data,
            chronicle_on_accepted='chronicle-on-accepted')

        self.bill.decline(decliner)

        self.assertNotEqual(old_storage_version,
                            resource_exchange_storage._version)

        self.assertEqual(len(resource_exchange_storage.all()), 0)
Exemple #17
0
    def test_decline__no_excange(self):
        self.apply_bill()

        ResourceExchangePrototype._db_all().delete()

        resource_exchange_storage.refresh()

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

        old_storage_version = resource_exchange_storage._version

        decliner = BillPrototype.create(
            self.account1,
            'bill-1-caption',
            'bill-1-rationale',
            self.bill_data,
            chronicle_on_accepted='chronicle-on-accepted-2')

        self.bill.decline(decliner)

        self.assertEqual(old_storage_version,
                         resource_exchange_storage._version)
Exemple #18
0
 def __init__(self, *args, **kwargs):
     super(UserForm, self).__init__(*args, **kwargs)
     bills = [exchange.bill for exchange in resource_exchange_storage.all() if exchange.bill]
     self.fields['declined_bill'].choices = [(bill.id, bill.caption) for bill in bills]