예제 #1
0
 def GetAPINodeAvailability(self, api_name):
     schema_graph = APISchemaGraph()
     api_graph = APISchemaGraph(
         json.loads(CANNED_MASTER_FS_DATA['api'][api_name + '.json']))
     # Give the graph fake ChannelInfo; it's not used in tests.
     channel_info = ChannelInfo('stable', '28', 28)
     schema_graph.Update(api_graph, lambda _: channel_info)
     return schema_graph
    def testUpdate(self):
        result = APISchemaGraph(API_SCHEMA)
        to_add = APISchemaGraph({
            'tabs': {
                'properties': {
                    'TAB_PROPERTY_THREE': {
                        'description': 'better than two'
                    },
                    'TAB_PROPERTY_FOUR': {
                        'value': 4
                    }
                },
                'functions': {
                    'get': {
                        'name': {},
                        'parameters': {
                            'tab': {
                                'type': {},
                                'name': {},
                                'description': {},
                                'surprise': {}
                            }
                        }
                    },
                    'getAllInWindow': {
                        'parameters': {
                            'windowId': {
                                'type': 'object'
                            }
                        }
                    }
                }
            }
        })
        result.Update(to_add, annotation='first')
        # Looking up elements that were originally available in |result|. Because
        # of this, no |annotation| object should be attached to the LookupResult
        # object.
        self.assertEqual(LookupResult(True, None), result.Lookup('tabs'))
        self.assertEqual(
            LookupResult(True, None),
            result.Lookup('tabs', 'functions', 'get', 'parameters'))
        self.assertEqual(
            LookupResult(True, None),
            result.Lookup('tabs', 'properties', 'TAB_PROPERTY_ONE'))
        self.assertEqual(
            LookupResult(True, None),
            result.Lookup('tabs', 'properties', 'TAB_PROPERTY_ONE'))
        self.assertEqual(
            LookupResult(True, None),
            result.Lookup('tabs', 'functions', 'get', 'parameters', 'tabId'))

        # Looking up elements that were just added to |result|.
        self.assertEqual(
            LookupResult(True, 'first'),
            result.Lookup('tabs', 'properties', 'TAB_PROPERTY_THREE'))
        self.assertEqual(
            LookupResult(True, 'first'),
            result.Lookup('tabs', 'properties', 'TAB_PROPERTY_FOUR'))
        self.assertEqual(
            LookupResult(True, 'first'),
            result.Lookup('tabs', 'functions', 'getAllInWindow', 'parameters',
                          'windowId'))
        self.assertEqual(
            LookupResult(True, 'first'),
            result.Lookup('tabs', 'functions', 'get', 'parameters', 'tab',
                          'surprise'))

        to_add = APISchemaGraph({
            'tabs': {
                'properties': {
                    'TAB_PROPERTY_FIVE': {
                        'description': 'stayin\' alive'
                    }
                },
                'functions': {
                    'getAllInWindow': {
                        'parameters': {
                            'callback': {
                                'type': 'function'
                            }
                        }
                    }
                }
            }
        })
        result.Update(to_add, annotation='second')
        # Looking up the second group of elements added to |result|.
        self.assertEqual(
            LookupResult(True, 'first'),
            result.Lookup('tabs', 'properties', 'TAB_PROPERTY_FOUR'))
        self.assertEqual(
            LookupResult(True, 'second'),
            result.Lookup('tabs', 'properties', 'TAB_PROPERTY_FIVE'))
        self.assertEqual(
            LookupResult(True, 'first'),
            result.Lookup('tabs', 'functions', 'getAllInWindow', 'parameters',
                          'windowId'))
        self.assertEqual(
            LookupResult(True, 'second'),
            result.Lookup('tabs', 'functions', 'getAllInWindow', 'parameters',
                          'callback'))
        self.assertEqual(LookupResult(True, 'first'),
                         result.Lookup('tabs', 'functions', 'getAllInWindow'))