예제 #1
0
    def test_get_exchanges_for_place__multiple(self):
        exchange_1 = ResourceExchangePrototype.create(
            place_1=self.place_1,
            place_2=self.place_2,
            resource_1=self.resource_1,
            resource_2=self.resource_2,
            bill=None)

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

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

        self.assertEqual(
            set(exchange.id for exchange in storage.resource_exchanges.
                get_exchanges_for_place(self.place_2)),
            set((exchange_1.id, exchange_3.id)))
예제 #2
0
 def apply(self, bill=None):
     if self.has_meaning():
         ResourceExchangePrototype.create(place_1=self.place_1,
                                          place_2=self.place_2,
                                          resource_1=self.resource_1,
                                          resource_2=self.resource_2,
                                          bill=bill)
예제 #3
0
 def apply(self, bill=None):
     if self.has_meaning():
         ResourceExchangePrototype.create(place_1=self.place_1,
                                          place_2=self.place_2,
                                          resource_1=self.resource_1,
                                          resource_2=self.resource_2,
                                          bill=bill)
예제 #4
0
    def test_get_exchanges_for_bill_id__exists(self):
        from the_tale.forum.models import Category, SubCategory
        from the_tale.game.bills.conf import bills_settings
        from the_tale.game.bills import bills
        from the_tale.game.bills.prototypes import BillPrototype

        account = self.accounts_factory.create_account()

        forum_category = Category.objects.create(caption='category-1', slug='category-1')
        SubCategory.objects.create(caption=bills_settings.FORUM_CATEGORY_UID + '-caption',
                                   uid=bills_settings.FORUM_CATEGORY_UID,
                                   category=forum_category)

        bill_data = bills.PlaceRenaming(place_id=self.place_1.id, name_forms=names.generator().get_test_name('new_name'))
        bill = BillPrototype.create(account, 'bill-caption', 'bill-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted')

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

        exchange_2 = ResourceExchangePrototype.create(place_1=self.place_1,
                                                      place_2=self.place_3,
                                                      resource_1=self.resource_1,
                                                      resource_2=self.resource_2,
                                                      bill=bill)

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

        self.assertEqual(exchange_2.id, storage.resource_exchanges.get_exchange_for_bill_id(bill.id).id)
 def apply(self, bill=None):
     if self.has_meaning():
         ResourceExchangePrototype.create(place_1=self.place,
                                          place_2=None,
                                          resource_1=self.conversion.resource_from,
                                          resource_2=self.conversion.resource_to,
                                          bill=bill)
예제 #6
0
 def apply(self, bill=None):
     if self.has_meaning():
         ResourceExchangePrototype.create(
             place_1=self.place,
             place_2=None,
             resource_1=self.conversion.resource_from,
             resource_2=self.conversion.resource_to,
             bill=bill)
예제 #7
0
    def test_get_exchanges_for_bill_id__exists(self):
        from the_tale.accounts.prototypes import AccountPrototype
        from the_tale.accounts.logic import register_user

        from the_tale.forum.models import Category, SubCategory
        from the_tale.game.bills.conf import bills_settings
        from the_tale.game.bills import bills
        from the_tale.game.bills.prototypes import BillPrototype

        result, account_id, bundle_id = register_user('test_user',
                                                      '*****@*****.**',
                                                      '111111')
        account = AccountPrototype.get_by_id(account_id)

        forum_category = Category.objects.create(caption='category-1',
                                                 slug='category-1')
        SubCategory.objects.create(caption=bills_settings.FORUM_CATEGORY_UID +
                                   '-caption',
                                   uid=bills_settings.FORUM_CATEGORY_UID,
                                   category=forum_category)

        bill_data = bills.PlaceRenaming(
            place_id=self.place_1.id,
            name_forms=names.generator.get_test_name('new_name'))
        bill = BillPrototype.create(
            account,
            'bill-caption',
            'bill-rationale',
            bill_data,
            chronicle_on_accepted='chronicle-on-accepted')

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

        exchange_2 = ResourceExchangePrototype.create(
            place_1=self.place_1,
            place_2=self.place_3,
            resource_1=self.resource_1,
            resource_2=self.resource_2,
            bill=bill)

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

        self.assertEqual(
            exchange_2.id,
            storage.resource_exchanges.get_exchange_for_bill_id(bill.id).id)
    def test_end__no_excange(self):
        self.apply_bill()

        ResourceExchangePrototype._db_all().delete()

        places_storage.resource_exchanges.refresh()

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

        old_storage_version = places_storage.resource_exchanges._version

        self.bill.end()

        self.assertEqual(old_storage_version, places_storage.resource_exchanges._version)
예제 #9
0
    def test_end__no_excange(self):
        self.apply_bill()

        ResourceExchangePrototype._db_all().delete()

        places_storage.resource_exchanges.refresh()

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

        old_storage_version = places_storage.resource_exchanges._version

        self.bill.end()

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

        ResourceExchangePrototype._db_all().delete()

        places_storage.resource_exchanges.refresh()

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

        old_storage_version = places_storage.resource_exchanges._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, places_storage.resource_exchanges._version)
예제 #11
0
    def test_get_exchanges_for_place__multiple(self):
        exchange_1 = ResourceExchangePrototype.create(place_1=self.place_1,
                                                      place_2=self.place_2,
                                                      resource_1=self.resource_1,
                                                      resource_2=self.resource_2,
                                                      bill=None)

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

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

        self.assertEqual(set(exchange.id for exchange in storage.resource_exchanges.get_exchanges_for_place(self.place_2)),
                         set((exchange_1.id, exchange_3.id)))
예제 #12
0
    def test_decline__no_excange(self):
        self.apply_bill()

        ResourceExchangePrototype._db_all().delete()

        places_storage.resource_exchanges.refresh()

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

        old_storage_version = places_storage.resource_exchanges._version

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

        self.bill.decline(decliner)

        self.assertEqual(old_storage_version,
                         places_storage.resource_exchanges._version)
예제 #13
0
    def test_create(self):
        self.assertEqual(len(storage.resource_exchanges.all()), 0)

        old_version = storage.resource_exchanges._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(storage.resource_exchanges.all()), 1)

        self.assertEqual(exchange.id, storage.resource_exchanges.all()[0].id)
        self.assertNotEqual(old_version, storage.resource_exchanges._version)
예제 #14
0
    def test_create(self):
        self.assertEqual(len(storage.resource_exchanges.all()), 0)

        old_version = storage.resource_exchanges._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(storage.resource_exchanges.all()), 1)

        self.assertEqual(exchange.id, storage.resource_exchanges.all()[0].id)
        self.assertNotEqual(old_version, storage.resource_exchanges._version)