How to use _makeitem method in pytest-play

Best Python code snippet using pytest-play_python

test_references.py

Source:test_references.py Github

copy

Full Screen

1# Copyright (C) 2008-2009 Open Society Institute2# Thomas Moroz: tmoroz@sorosny.org3#4# This program is free software; you can redistribute it and/or modify it5# under the terms of the GNU General Public License Version 2 as published6# by the Free Software Foundation. You may not use, modify or distribute7# this program under any other version of the GNU General Public License.8#9# This program is distributed in the hope that it will be useful, but10# WITHOUT ANY WARRANTY; without even the implied warranty of11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12# General Public License for more details.13#14# You should have received a copy of the GNU General Public License along15# with this program; if not, write to the Free Software Foundation, Inc.,16# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.17import unittest18import karl.testing19class TestBase:20 def setUp(self):21 from pyramid.testing import cleanUp22 cleanUp()23 karl.testing.registerDummyRenderer(24 'karl.content.views:templates/generic_layout.pt')25 def tearDown(self):26 from pyramid.testing import cleanUp27 cleanUp()28class DescriptionHTMLTests(unittest.TestCase):29 def _getTargetClass(self):30 from karl.content.views.references import DescriptionHTML31 return DescriptionHTML32 def _makeOne(self, context=None, request=None):33 from pyramid.testing import DummyModel34 from pyramid.testing import DummyRequest35 if context is None:36 context = DummyModel(description='dummy')37 if request is None:38 request = DummyRequest()39 return self._getTargetClass()(context, request)40 def test_class_conforms_to_IReferenceManualHTML(self):41 from zope.interface.verify import verifyClass42 from karl.content.interfaces import IReferenceManualHTML43 verifyClass(IReferenceManualHTML, self._getTargetClass())44 def test_instance_conforms_to_IReferenceManualHTML(self):45 from zope.interface.verify import verifyObject46 from karl.content.interfaces import IReferenceManualHTML47 verifyObject(IReferenceManualHTML, self._makeOne())48 def test___call__(self):49 adapter = self._makeOne()50 api = object()51 self.assertEqual(adapter(api), '<p>dummy</p>')52class TextHTMLTests(unittest.TestCase):53 def _getTargetClass(self):54 from karl.content.views.references import TextHTML55 return TextHTML56 def _makeOne(self, context=None, request=None):57 from pyramid.testing import DummyModel58 from pyramid.testing import DummyRequest59 if context is None:60 context = DummyModel(text='<p>dummy</p>')61 if request is None:62 request = DummyRequest()63 return self._getTargetClass()(context, request)64 def test_class_conforms_to_IReferenceManualHTML(self):65 from zope.interface.verify import verifyClass66 from karl.content.interfaces import IReferenceManualHTML67 verifyClass(IReferenceManualHTML, self._getTargetClass())68 def test_instance_conforms_to_IReferenceManualHTML(self):69 from zope.interface.verify import verifyObject70 from karl.content.interfaces import IReferenceManualHTML71 verifyObject(IReferenceManualHTML, self._makeOne())72 def test___call__(self):73 adapter = self._makeOne()74 api = object()75 self.assertEqual(adapter(api), '<p>dummy</p>')76class FileHTMLTests(unittest.TestCase):77 def _getTargetClass(self):78 from karl.content.views.references import FileHTML79 return FileHTML80 def _makeOne(self, context=None, request=None):81 from pyramid.testing import DummyModel82 from pyramid.testing import DummyRequest83 if context is None:84 context = DummyModel()85 if request is None:86 request = DummyRequest()87 return self._getTargetClass()(context, request)88 def test_class_conforms_to_IReferenceManualHTML(self):89 from zope.interface.verify import verifyClass90 from karl.content.interfaces import IReferenceManualHTML91 verifyClass(IReferenceManualHTML, self._getTargetClass())92 def test_instance_conforms_to_IReferenceManualHTML(self):93 from zope.interface.verify import verifyObject94 from karl.content.interfaces import IReferenceManualHTML95 verifyObject(IReferenceManualHTML, self._makeOne())96 def test___call__(self):97 from zope.interface import Interface98 from karl.content.views.interfaces import IFileInfo99 fileinfo = object()100 api = object()101 def _adapt(context, request):102 return fileinfo103 karl.testing.registerAdapter(_adapt, (Interface, Interface), IFileInfo)104 adapter = self._makeOne()105 renderer = karl.testing.registerDummyRenderer(106 'templates/inline_file.pt')107 adapter(api)108 self.failUnless(renderer.api is api)109 self.failUnless(renderer.fileinfo is fileinfo)110class Test_getTree(TestBase, unittest.TestCase):111 def _callFUT(self, context, request=None, api=None):112 from pyramid.testing import DummyRequest113 from karl.content.views.references import getTree114 if request is None:115 request = DummyRequest()116 if api is None:117 api = object()118 return getTree(context, request, api)119 def _makeItem(self, ifaces=(), **kw):120 from zope.interface import directlyProvides121 from pyramid.testing import DummyModel122 class _DummyOrdering:123 # The one in karl.testing doesn't have a working sync.124 def sync(self, entries):125 self._items = entries126 def items(self):127 return self._items128 item = DummyModel(ordering=_DummyOrdering(), **kw)129 directlyProvides(item, ifaces)130 return item131 def _registerAdapter(self, html, **kw):132 from zope.interface import Interface133 from karl.content.interfaces import IReferenceManualHTML134 def _adapt(context, request):135 def _html(api):136 return html % kw137 return _html138 karl.testing.registerAdapter(139 _adapt, (Interface, Interface), IReferenceManualHTML)140 def test_empty(self):141 root = self._makeItem()142 items = self._callFUT(root)143 self.assertEqual(len(items), 0)144 def test_w_child_wo_html_adapter(self):145 root = self._makeItem()146 root['aaa'] = self._makeItem(title='AAA', description='My aaa')147 items = self._callFUT(root)148 self.assertEqual(len(items), 1)149 self.assertEqual(items[0], {'name': 'aaa',150 'title': 'AAA',151 'href': 'http://example.com/aaa/',152 'html': '<p>Unknown type</p>',153 'subpath': '|aaa',154 'items': [],155 })156 def test_w_child_w_html_adapter(self):157 self._registerAdapter('<h1>FOOBAR</h1>')158 root = self._makeItem()159 root['aaa'] = self._makeItem(title='AAA', description='My aaa')160 items = self._callFUT(root)161 self.assertEqual(len(items), 1)162 self.assertEqual(items[0], {'name': 'aaa',163 'title': 'AAA',164 'href': 'http://example.com/aaa/',165 'html': '<h1>FOOBAR</h1>',166 'subpath': '|aaa',167 'items': [],168 })169 def test_w_child_leaf(self):170 root = self._makeItem()171 class _Leaf:172 def __init__(self, **kw):173 self.__dict__.update(kw)174 leaf = root['aaa'] = _Leaf(title='AAA', description='My aaa')175 leaf.__name__ = 'aaa'176 items = self._callFUT(root)177 self.assertEqual(len(items), 1)178 self.assertEqual(items[0], {'name': 'aaa',179 'title': 'AAA',180 'href': 'http://example.com/aaa/',181 'html': '<p>Unknown type</p>',182 'subpath': '|aaa',183 'items': (),184 })185 def test_w_nested(self):186 root = self._makeItem()187 class _Leaf:188 def __init__(self, **kw):189 self.__dict__.update(kw)190 child = root['aaa'] = self._makeItem(title='AAA', description='My aaa')191 grandchild = child['bbb'] = _Leaf(title='BBB', description='My bbb')192 grandchild.__name__ = 'bbb'193 items = self._callFUT(root)194 self.assertEqual(len(items), 1)195 self.assertEqual(items[0],196 {'name': 'aaa',197 'title': 'AAA',198 'href': 'http://example.com/aaa/',199 'html': '<p>Unknown type</p>',200 'subpath': '|aaa',201 'items': [{'name': 'bbb',202 'title': 'BBB',203 'href': 'http://example.com/aaa/bbb/',204 'html': '<p>Unknown type</p>',205 'subpath': '|aaa|bbb',206 'items': (),207 },208 ]209 })210class Test_move_subpath(unittest.TestCase):211 def _callFUT(self, context, subpath, direction):212 from karl.content.views.references import move_subpath213 return move_subpath(context, subpath, direction)214 def _makeItem(self, **kw):215 from pyramid.testing import DummyModel216 class _DummyOrdering:217 # The one in karl.testing doesn't have a working sync.218 _moved_up = _moved_down = None219 _sync_called = False220 def sync(self, entries):221 self._items = entries222 self._sync_called = True223 def items(self):224 return self._items225 def moveUp(self, name):226 self._moved_up = name227 def moveDown(self, name):228 self._moved_down = name229 return DummyModel(ordering=_DummyOrdering(), **kw)230 def test_miss_subpath(self):231 model = self._makeItem()232 self.assertRaises(KeyError, self._callFUT, model, '|a', 'up')233 def test_bad_direction(self):234 model = self._makeItem()235 model['a'] = self._makeItem()236 self.assertRaises(ValueError, self._callFUT, model, '|a', 'sideways')237 def test_move_up(self):238 model = self._makeItem()239 model['a'] = self._makeItem()240 model['b'] = self._makeItem()241 self._callFUT(model, '|a', 'up')242 self.failUnless(model.ordering._sync_called)243 self.assertEqual(model.ordering._moved_up, 'a')244 def test_move_up_file_with_extension(self):245 model = self._makeItem()246 model['a.doc'] = self._makeItem()247 model['b'] = self._makeItem()248 self._callFUT(model, '|a.doc', 'up')249 self.failUnless(model.ordering._sync_called)250 self.assertEqual(model.ordering._moved_up, 'a.doc')251 def test_move_up_file_with_many_dots(self):252 model = self._makeItem()253 model['a.file.with.dots'] = self._makeItem()254 model['b'] = self._makeItem()255 self._callFUT(model, '|a.file.with.dots', 'up')256 self.failUnless(model.ordering._sync_called)257 self.assertEqual(model.ordering._moved_up, 'a.file.with.dots')258 def test_move_up_nested(self):259 model = self._makeItem()260 child = model['a'] = self._makeItem()261 child['b'] = self._makeItem()262 self._callFUT(model, '|a|b', 'up')263 self.failUnless(model.ordering._sync_called)264 self.failUnless(child.ordering._sync_called)265 self.assertEqual(child.ordering._moved_up, 'b')266 def test_move_down(self):267 model = self._makeItem()268 model['a'] = self._makeItem()269 model['b'] = self._makeItem()270 self._callFUT(model, '|a', 'down')271 self.failUnless(model.ordering._sync_called)272 self.assertEqual(model.ordering._moved_down, 'a')273 def test_move_down_file_with_extension(self):274 model = self._makeItem()275 model['a.doc'] = self._makeItem()276 model['b'] = self._makeItem()277 self._callFUT(model, '|a.doc', 'down')278 self.failUnless(model.ordering._sync_called)279 self.assertEqual(model.ordering._moved_down, 'a.doc')280 def test_move_down_file_with_many_dots(self):281 model = self._makeItem()282 model['a.file.with.dots'] = self._makeItem()283 model['b'] = self._makeItem()284 self._callFUT(model, '|a.file.with.dots', 'down')285 self.failUnless(model.ordering._sync_called)286 self.assertEqual(model.ordering._moved_down, 'a.file.with.dots')287 def test_move_down_nested(self):288 model = self._makeItem()289 child = model['a'] = self._makeItem()290 child['b'] = self._makeItem()291 self._callFUT(model, '|a|b', 'down')292 self.failUnless(model.ordering._sync_called)293 self.failUnless(child.ordering._sync_called)294 self.assertEqual(child.ordering._moved_down, 'b')295class ShowTestBase(TestBase):296 def _makeContext(self):297 from pyramid.testing import DummyModel298 from karl.testing import DummyCatalog299 from karl.testing import DummyOrdering300 parent = DummyModel(title='dummyparent',301 ordering = DummyOrdering(),302 catalog = DummyCatalog(),303 )304 context = DummyModel(title='dummytitle',305 text='dummytext',306 ordering = DummyOrdering(),307 )308 context['attachments'] = DummyModel()309 parent['child'] = context310 return parent, context311 def _registerTagbox(self):312 from zope.interface import Interface313 from karl.models.interfaces import ITagQuery314 from karl.testing import DummyTagQuery315 karl.testing.registerAdapter(DummyTagQuery, (Interface, Interface),316 ITagQuery)317 def _registerAddables(self):318 from zope.interface import Interface319 from karl.views.interfaces import IFolderAddables320 from karl.testing import DummyFolderAddables321 karl.testing.registerAdapter(322 DummyFolderAddables, (Interface, Interface),323 IFolderAddables)324 def _registerLayoutProvider(self):325 from zope.interface import Interface326 from karl.views.interfaces import ILayoutProvider327 from karl.testing import DummyLayoutProvider328 karl.testing.registerAdapter(329 DummyLayoutProvider, (Interface, Interface),330 ILayoutProvider)331 def _callFUT(self, context=None, request=None):332 from pyramid.testing import DummyRequest333 if context is None:334 parent, context = self._makeContext()335 if request is None:336 request = DummyRequest()337 return self._getFUT()(context, request)338class ReferenceOutlineViewTests(ShowTestBase, unittest.TestCase):339 def _getFUT(self):340 from karl.content.views.references import reference_outline_view341 return reference_outline_view342 def test_it(self):343 self._registerTagbox()344 self._registerAddables()345 self._registerLayoutProvider()346 # XXX347 renderer = karl.testing.registerDummyRenderer(348 'templates/show_referencemanual.pt')349 self._callFUT()350 self.assertEqual(renderer.api.page_title, 'dummytitle')351 self.assertEqual(renderer.tree, [])352class ReferenceViewallViewTests(ShowTestBase, unittest.TestCase):353 def _getFUT(self):354 from karl.content.views.references import reference_viewall_view355 return reference_viewall_view356 def test_it(self):357 self._registerTagbox()358 self._registerAddables()359 self._registerLayoutProvider()360 # XXX361 renderer = karl.testing.registerDummyRenderer(362 'templates/viewall_referencemanual.pt')363 self._callFUT()364 self.assertEqual(renderer.api.page_title, 'dummytitle')365 self.assertEqual(renderer.tree, [])366class AddReferenceFCBaseTests(TestBase, unittest.TestCase):367 def _getTargetClass(self):368 from karl.content.views.references import AddReferenceFCBase369 return AddReferenceFCBase370 def _makeOne(self, context=None, request=None):371 from pyramid.testing import DummyModel372 from pyramid.testing import DummyRequest373 if context is None:374 context = DummyModel()375 if request is None:376 request = DummyRequest()377 request.environ['repoze.browserid'] = '1'378 base = self._getTargetClass()(context, request)379 base.page_title = 'Add Reference FC Base'380 return base381 def _registerFactory(self, controller):382 from pyramid.testing import DummyModel383 from repoze.lemonade.testing import registerContentFactory384 from zope.interface import Interface385 class IDummy(Interface):386 pass387 def factory(title, description, creator):388 rm = DummyModel(title=title, description=description,389 creator=creator)390 return rm391 controller.content_iface = IDummy392 registerContentFactory(factory, IDummy)393 def test_form_fields(self):394 controller = self._makeOne()395 fields = dict(controller.form_fields())396 self.failUnless('title' in fields)397 self.failUnless('tags' in fields)398 self.failUnless('description' in fields)399 def test_form_widgets(self):400 controller = self._makeOne()401 widgets = controller.form_widgets({})402 self.failUnless('title' in widgets)403 self.failUnless('tags' in widgets)404 self.failUnless('description' in widgets)405 def test___call__(self):406 controller = self._makeOne()407 response = controller()408 self.failUnless('api' in response)409 self.assertEqual(response['api'].page_title, 'Add Reference FC Base')410 self.failUnless('layout' in response)411 self.failUnless('actions' in response)412 def test_handle_cancel(self):413 controller = self._makeOne()414 response = controller.handle_cancel()415 self.assertEqual(response.location, 'http://example.com/')416 def test_handle_submit_context_wo_ordering(self):417 from pyramid.testing import DummyModel418 from karl.testing import DummyCatalog419 from karl.testing import DummyTags420 context = DummyModel(tags = DummyTags(),421 catalog = DummyCatalog(),422 )423 converted = {'title': u'Ref Manual Title',424 'tags': [u'foo', u'bar'],425 'description': u'ref manual description',426 }427 controller = self._makeOne(context=context)428 self._registerFactory(controller)429 response = controller.handle_submit(converted)430 self.failUnless(u'ref-manual-title' in context)431 manual = context[u'ref-manual-title']432 self.assertEqual(manual.title, u'Ref Manual Title')433 self.assertEqual(manual.description, u'ref manual description')434 self.assertEqual(context.tags._called_with[1]['tags'],435 [u'foo', u'bar'])436 def test_handle_submit(self):437 from pyramid.testing import DummyModel438 from karl.testing import DummyCatalog439 from karl.testing import DummyOrdering440 from karl.testing import DummyTags441 context = DummyModel(tags = DummyTags(),442 catalog = DummyCatalog(),443 ordering = DummyOrdering(),444 )445 converted = {'title': u'Ref Manual Title',446 'tags': [u'foo', u'bar'],447 'description': u'ref manual description',448 }449 controller = self._makeOne(context=context)450 self._registerFactory(controller)451 response = controller.handle_submit(converted)452 self.failUnless(u'ref-manual-title' in context)453 manual = context[u'ref-manual-title']454 self.assertEqual(manual.title, u'Ref Manual Title')455 self.assertEqual(manual.description, u'ref manual description')456 self.assertEqual(context.tags._called_with[1]['tags'],457 [u'foo', u'bar'])458class AddReferenceManualFormControllerTests(unittest.TestCase):459 def test_attrributes(self):460 from karl.content.interfaces import IReferenceManual461 from karl.content.views.references \462 import AddReferenceManualFormController as klass463 self.assertEqual(klass.page_title, "Add Reference Manual")464 self.assertEqual(klass.content_iface, IReferenceManual)465class AddReferenceSectionFormControllerTests(TestBase, unittest.TestCase):466 def test_attrributes(self):467 from karl.content.interfaces import IReferenceSection468 from karl.content.views.references \469 import AddReferenceSectionFormController as klass470 self.assertEqual(klass.page_title, "Add Reference Section")471 self.assertEqual(klass.content_iface, IReferenceSection)472class EditReferenceFCBaseTests(TestBase, unittest.TestCase):473 def _makeOne(self, context=None, request=None):474 from pyramid.testing import DummyRequest475 from karl.content.views.references import EditReferenceFCBase476 if context is None:477 parent, context = self._makeContext()478 if request is None:479 request = DummyRequest()480 request.environ['repoze.browserid'] = '1'481 base = EditReferenceFCBase(context, request)482 base.success_msg = 'BASE'483 return base484 def _makeContext(self):485 from pyramid.testing import DummyModel486 from karl.testing import DummyCatalog487 parent = DummyModel(title='dummyparent',488 catalog=DummyCatalog(),489 )490 context = DummyModel(title='dummytitle',491 description='dummydescription',492 )493 parent['dummytitle'] = context494 return parent, context495 def _registerTags(self, site):496 from zope.interface import Interface497 from karl.models.interfaces import ITagQuery498 from karl.testing import DummyTagQuery499 karl.testing.registerAdapter(DummyTagQuery, (Interface, Interface),500 ITagQuery)501 from karl.testing import DummyTags502 site.tags = DummyTags()503 def test_form_defaults(self):504 controller = self._makeOne()505 defaults = controller.form_defaults()506 self.assertEqual(defaults['title'], 'dummytitle')507 self.assertEqual(defaults['description'], 'dummydescription')508 def test_form_fields(self):509 controller = self._makeOne()510 fields = dict(controller.form_fields())511 self.failUnless('title' in fields)512 self.failUnless('tags' in fields)513 self.failUnless('description' in fields)514 def test_form_widgets(self):515 parent, context = self._makeContext()516 self._registerTags(parent)517 controller = self._makeOne(context)518 widgets = controller.form_widgets({})519 self.failUnless('title' in widgets)520 self.failUnless('tags' in widgets)521 self.failUnless('description' in widgets)522 def test___call__(self):523 controller = self._makeOne()524 response = controller()525 self.failUnless('api' in response)526 self.assertEqual(response['api'].page_title,527 'Edit dummytitle')528 self.failUnless('layout' in response)529 self.failUnless('actions' in response)530 def test_handle_cancel(self):531 controller = self._makeOne()532 response = controller.handle_cancel()533 self.assertEqual(response.location,534 'http://example.com/dummytitle/')535 def test_handle_submit(self):536 converted = {'title': u'New Title',537 'tags': [u'foo', u'bar'],538 'description': u'new description',539 }540 parent, context = self._makeContext()541 self._registerTags(parent)542 controller = self._makeOne(context)543 response = controller.handle_submit(converted)544 # XXX test reseponse type, location?545 self.assertEqual(response.location,546 'http://example.com/dummytitle/?status_message=BASE')547 self.assertEqual(context.title, u'New Title')548 self.assertEqual(context.description, u'new description')549 self.assertEqual(parent.tags._called_with[1]['tags'],550 [u'foo', u'bar'])551class EditReferenceManualFormControllerTests(unittest.TestCase):552 def test_attrributes(self):553 from karl.content.views.references \554 import EditReferenceManualFormController as klass555 self.assertEqual(klass.success_msg, 'Reference%20manual%20edited')556class EditReferenceSectionFormControllerTests(unittest.TestCase):557 def test_attrributes(self):558 from karl.content.views.references \559 import EditReferenceSectionFormController as klass...

Full Screen

Full Screen

research_cm_handlers.py

Source:research_cm_handlers.py Github

copy

Full Screen

1# Embedded file name: scripts/client/gui/Scaleform/daapi/view/lobby/techtree/research_cm_handlers.py2from gui.Scaleform.locale.MENU import MENU3from gui.Scaleform.managers.context_menu.AbstractContextMenuHandler import AbstractContextMenuHandler4from gui.Scaleform.daapi.view.lobby.techtree import NODE_STATE, UnlockStats5from gui.Scaleform.daapi.view.lobby.techtree.techtree_dp import g_techTreeDP6from gui.Scaleform.daapi.view.lobby.hangar.hangar_cm_handlers import MODULE, SimpleVehicleCMHandler, VEHICLE7from gui.Scaleform.framework.entities.EventSystemEntity import EventSystemEntity8from gui.shared import g_itemsCache, event_dispatcher as shared_events9from gui.shared.gui_items.items_actions import factory as ItemsActionsFactory10class ResearchItemContextMenuHandler(AbstractContextMenuHandler, EventSystemEntity):11 def __init__(self, cmProxy, ctx = None):12 super(ResearchItemContextMenuHandler, self).__init__(cmProxy, ctx, {MODULE.INFO: 'showModuleInfo',13 MODULE.UNLOCK: 'unlockModule',14 MODULE.BUY_AND_EQUIP: 'buyModule',15 MODULE.EQUIP: 'equipModule',16 MODULE.SELL: 'sellModule'})17 def fini(self):18 super(ResearchItemContextMenuHandler, self).fini()19 def showModuleInfo(self):20 vehicle = g_itemsCache.items.getItemByCD(self._rootCD)21 if vehicle:22 shared_events.showModuleInfo(self._nodeCD, vehicle.descriptor)23 def unlockModule(self):24 vehicle = g_itemsCache.items.getItemByCD(self._rootCD)25 if vehicle:26 unlockIdx, xpCost, _ = vehicle.getUnlockDescrByIntCD(self._nodeCD)27 ItemsActionsFactory.doAction(ItemsActionsFactory.UNLOCK_ITEM, self._nodeCD, self._rootCD, unlockIdx, xpCost)28 def buyModule(self):29 ItemsActionsFactory.doAction(ItemsActionsFactory.BUY_AND_INSTALL_ITEM, self._nodeCD, self._rootCD)30 def equipModule(self):31 ItemsActionsFactory.doAction(ItemsActionsFactory.INSTALL_ITEM, self._nodeCD, self._rootCD)32 def sellModule(self):33 ItemsActionsFactory.doAction(ItemsActionsFactory.SELL_ITEM, self._nodeCD)34 def _initFlashValues(self, ctx):35 self._nodeCD = int(ctx.nodeCD)36 self._rootCD = int(ctx.rootCD)37 self._nodeState = int(ctx.nodeState)38 def _clearFlashValues(self):39 self._nodeCD = None40 self._rootCD = None41 self._nodeState = None42 return43 def _generateOptions(self):44 options = [self._makeItem(MODULE.INFO, MENU.contextmenu(MODULE.INFO)), self._makeSeparator(), self._makeItem(MODULE.UNLOCK, MENU.contextmenu(MODULE.UNLOCK), {'enabled': NODE_STATE.isAvailable2Unlock(self._nodeState)})]45 if NODE_STATE.isUnlocked(self._nodeState):46 if NODE_STATE.inInventory(self._nodeState) or NODE_STATE.isInstalled(self._nodeState):47 options.extend([self._makeItem(MODULE.EQUIP, MENU.contextmenu(MODULE.EQUIP), {'enabled': self._isAvailable2Install()}), self._makeSeparator(), self._makeItem(MODULE.SELL, MENU.CONTEXTMENU_SELLFROMINVENTORY, {'enabled': not NODE_STATE.isInstalled(self._nodeState)})])48 else:49 options.extend([self._makeItem(MODULE.BUY_AND_EQUIP, MENU.CONTEXTMENU_BUYANDEQUIP, {'enabled': self._isAvailable2Buy()}), self._makeSeparator(), self._makeItem(MODULE.SELL, MENU.CONTEXTMENU_SELLFROMINVENTORY, {'enabled': NODE_STATE.isAvailable2Sell(self._nodeState)})])50 else:51 options.extend([self._makeItem(MODULE.BUY_AND_EQUIP, MENU.CONTEXTMENU_BUYANDEQUIP, {'enabled': False}), self._makeSeparator(), self._makeItem(MODULE.SELL, MENU.CONTEXTMENU_SELLFROMINVENTORY, {'enabled': False})])52 return options53 def _isAvailable2Install(self):54 return not NODE_STATE.isInstalled(self._nodeState) and NODE_STATE.inInventory(self._nodeState) and self._canInstallItems()55 def _isAvailable2Buy(self):56 return not NODE_STATE.isInstalled(self._nodeState) and NODE_STATE.isAvailable2Buy(self._nodeState) and self._canInstallItems()57 def _canInstallItems(self):58 rootItem = g_itemsCache.items.getItemByCD(self._rootCD)59 return rootItem.isInInventory and not rootItem.lock and not rootItem.repairCost60class ResearchVehicleContextMenuHandler(SimpleVehicleCMHandler):61 def __init__(self, cmProxy, ctx = None):62 super(ResearchVehicleContextMenuHandler, self).__init__(cmProxy, ctx, {VEHICLE.INFO: 'showVehicleInfo',63 VEHICLE.UNLOCK: 'unlockVehicle',64 VEHICLE.BUY: 'buyVehicle',65 VEHICLE.SELL: 'sellVehicle',66 VEHICLE.SELECT: 'selectVehicle',67 VEHICLE.STATS: 'showVehicleStats'})68 def getVehCD(self):69 return self._nodeCD70 def getVehInvID(self):71 return self._nodeInvID72 def unlockVehicle(self):73 stats = g_itemsCache.items.stats74 unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs, stats.freeXP)75 unlockKwargs = unlockStats._asdict()76 _, unlockProps = g_techTreeDP.isNext2Unlock(self._nodeCD, **unlockKwargs)77 ItemsActionsFactory.doAction(ItemsActionsFactory.UNLOCK_ITEM, self._nodeCD, unlockProps.parentID, unlockProps.unlockIdx, unlockProps.xpCost)78 def selectVehicle(self):79 shared_events.selectVehicleInHangar(self._nodeCD)80 def _initFlashValues(self, ctx):81 self._nodeCD = int(ctx.nodeCD)82 self._rootCD = int(ctx.rootCD)83 self._nodeState = int(ctx.nodeState)84 vehicle = g_itemsCache.items.getItemByCD(self._nodeCD)85 self._nodeInvID = vehicle.invID if vehicle is not None else None86 return87 def _clearFlashValues(self):88 self._nodeCD = None89 self._rootCD = None90 self._nodeState = None91 self._nodeInvID = None92 return93 def _generateOptions(self):94 vehicle = g_itemsCache.items.getItemByCD(self._nodeCD)95 options = [self._makeItem(VEHICLE.INFO, MENU.CONTEXTMENU_VEHICLEINFOEX),96 self._makeItem(VEHICLE.STATS, MENU.CONTEXTMENU_SHOWVEHICLESTATISTICS, {'enabled': NODE_STATE.isWasInBattle(self._nodeState)}),97 self._makeSeparator(),98 self._makeItem(VEHICLE.UNLOCK, MENU.CONTEXTMENU_UNLOCK, {'enabled': NODE_STATE.isAvailable2Unlock(self._nodeState) and not NODE_STATE.isPremium(self._nodeState)})]99 if not vehicle.isPremiumIGR:100 options.extend([self._makeItem(VEHICLE.BUY, MENU.CONTEXTMENU_BUY, {'enabled': NODE_STATE.isAvailable2Buy(self._nodeState)}),101 self._makeItem(VEHICLE.SELL, MENU.CONTEXTMENU_VEHICLEREMOVE if vehicle.isRented else MENU.CONTEXTMENU_SELL, {'enabled': NODE_STATE.isAvailable2Sell(self._nodeState)}),102 self._makeSeparator(),103 self._makeItem(VEHICLE.SELECT, MENU.CONTEXTMENU_SELECTVEHICLEINHANGAR, {'enabled': NODE_STATE.inInventory(self._nodeState) and NODE_STATE.isVehicleCanBeChanged(self._nodeState)})])...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-play automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful