def setUp(self): super(HeroPositionTest, self).setUp() self.place_1, self.place_2, self.place_3 = create_test_map() result, account_id, bundle_id = register_user('test_user') self.storage = LogicStorage() self.storage.load_account_data(AccountPrototype.get_by_id(account_id)) self.hero = self.storage.accounts_to_heroes[account_id] self.road_1_2 = roads_storage.get_by_places(self.place_1, self.place_2) self.road_2_3 = roads_storage.get_by_places(self.place_2, self.place_3)
def setUp(self): super(HeroPositionTest, self).setUp() self.place_1, self.place_2, self.place_3 = create_test_map() account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.road_1_2 = roads_storage.get_by_places(self.place_1, self.place_2) self.road_2_3 = roads_storage.get_by_places(self.place_2, self.place_3)
def clean(self): cleaned_data = super(UserForm, self).clean() place_1 = places_storage.places.get(int(cleaned_data['place_1'])) place_2 = places_storage.places.get(int(cleaned_data['place_2'])) if roads_storage.get_by_places(place_1, place_2) is None: raise ValidationError(u'Обмениваться ресурсами могут только города связаные дорогой') if (c.PLACE_MAX_BILLS_NUMBER <= len(places_storage.resource_exchanges.get_exchanges_for_place(place_1)) or c.PLACE_MAX_BILLS_NUMBER <= len(places_storage.resource_exchanges.get_exchanges_for_place(place_2)) ): raise ValidationError(u'Один город может поддерживать не более чем %(max_exchanges)d активных законов' % {'max_exchanges': c.PLACE_MAX_BILLS_NUMBER}) resource_1 = cleaned_data.get('resource_1') resource_2 = cleaned_data.get('resource_2') if resource_1 is None: raise ValidationError(u'Не указан ресурс от первого города') if resource_2 is None: raise ValidationError(u'Не указан ресурс от второго города') if resource_1 not in ALLOWED_EXCHANGE_TYPES: raise ValidationError(u'Нельзя заключить договор на обмен ресурса «%s»' % resource_1.text) if resource_2 not in ALLOWED_EXCHANGE_TYPES: raise ValidationError(u'Нельзя заключить договор на обмен ресурса «%s»' % resource_2.text) if resource_1.parameter == resource_2.parameter: raise ValidationError(u'Нельзя заключить договор на обмен одинаковыми ресурсами') return cleaned_data
def has_meaning(self): if roads_storage.get_by_places(self.place_1, self.place_2) is None: return False if (c.PLACE_MAX_BILLS_NUMBER <= len(places_storage.resource_exchanges.get_exchanges_for_place(self.place_1)) or c.PLACE_MAX_BILLS_NUMBER <= len(places_storage.resource_exchanges.get_exchanges_for_place(self.place_2)) ): return False return True
def has_meaning(self): if roads_storage.get_by_places(self.place_1, self.place_2) is None: return False if (c.PLACE_MAX_BILLS_NUMBER <= len( places_storage.resource_exchanges.get_exchanges_for_place( self.place_1)) or c.PLACE_MAX_BILLS_NUMBER <= len( places_storage.resource_exchanges.get_exchanges_for_place( self.place_2))): return False return True
def clean(self): cleaned_data = super(UserForm, self).clean() place_1 = places_storage.places.get(int(cleaned_data['place_1'])) place_2 = places_storage.places.get(int(cleaned_data['place_2'])) if roads_storage.get_by_places(place_1, place_2) is None: raise ValidationError( u'Обмениваться ресурсами могут только города связаные дорогой') if (c.PLACE_MAX_BILLS_NUMBER <= len( places_storage.resource_exchanges.get_exchanges_for_place( place_1)) or c.PLACE_MAX_BILLS_NUMBER <= len( places_storage.resource_exchanges.get_exchanges_for_place( place_2))): raise ValidationError( u'Один город может поддерживать не более чем %(max_exchanges)d активных законов' % {'max_exchanges': c.PLACE_MAX_BILLS_NUMBER}) resource_1 = cleaned_data.get('resource_1') resource_2 = cleaned_data.get('resource_2') if resource_1 is None: raise ValidationError(u'Не указан ресурс от первого города') if resource_2 is None: raise ValidationError(u'Не указан ресурс от второго города') if resource_1 not in ALLOWED_EXCHANGE_TYPES: raise ValidationError( u'Нельзя заключить договор на обмен ресурса «%s»' % resource_1.text) if resource_2 not in ALLOWED_EXCHANGE_TYPES: raise ValidationError( u'Нельзя заключить договор на обмен ресурса «%s»' % resource_2.text) if resource_1.parameter == resource_2.parameter: raise ValidationError( u'Нельзя заключить договор на обмен одинаковыми ресурсами') return cleaned_data
def setUp(self): super(GeneralTest, self).setUp() self.p1, self.p2, self.p3 = create_test_map() self.r1 = roads_storage.get_by_places(self.p1, self.p2) self.r2 = roads_storage.get_by_places(self.p2, self.p3)