summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/layerindexlib
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/layerindexlib')
-rw-r--r--bitbake/lib/layerindexlib/tests/restapi.py164
1 files changed, 87 insertions, 77 deletions
diff --git a/bitbake/lib/layerindexlib/tests/restapi.py b/bitbake/lib/layerindexlib/tests/restapi.py
index bfaac43db4..58766950ce 100644
--- a/bitbake/lib/layerindexlib/tests/restapi.py
+++ b/bitbake/lib/layerindexlib/tests/restapi.py
@@ -23,113 +23,122 @@ from layerindexlib.tests.common import LayersTest
23 23
24import logging 24import logging
25 25
26class LayerIndexWebRestApiTest(LayersTest): 26def skipIfNoNetwork():
27
28 if os.environ.get("BB_SKIP_NETTESTS") == "yes": 27 if os.environ.get("BB_SKIP_NETTESTS") == "yes":
29 print("Unset BB_SKIP_NETTESTS to run network tests") 28 return unittest.skip("Network tests being skipped")
30 else: 29 return lambda f: f
31 def setUp(self):
32 LayersTest.setUp(self)
33 self.layerindex = layerindexlib.LayerIndex(self.d)
34 self.layerindex.load_layerindex('http://layers.openembedded.org/layerindex/api/;branch=sumo', load=['layerDependencies'])
35 30
36 def test_layerindex_is_empty(self): 31class LayerIndexWebRestApiTest(LayersTest):
37 self.assertFalse(self.layerindex.is_empty(), msg="Layerindex is empty")
38 32
39 def test_layerindex_store_file(self): 33 @skipIfNoNetwork()
40 self.layerindex.store_layerindex('file://%s/file.json' % self.tempdir, self.layerindex.indexes[0]) 34 def setUp(self):
35 self.assertFalse(os.environ.get("BB_SKIP_NETTESTS") == "yes", msg="BB_SKIP_NETTESTS set, but we tried to test anyway")
36 LayersTest.setUp(self)
37 self.layerindex = layerindexlib.LayerIndex(self.d)
38 self.layerindex.load_layerindex('http://layers.openembedded.org/layerindex/api/;branch=sumo', load=['layerDependencies'])
41 39
42 self.assertTrue(os.path.isfile('%s/file.json' % self.tempdir), msg="Temporary file was not created by store_layerindex") 40 @skipIfNoNetwork()
41 def test_layerindex_is_empty(self):
42 self.assertFalse(self.layerindex.is_empty(), msg="Layerindex is empty")
43 43
44 reload = layerindexlib.LayerIndex(self.d) 44 @skipIfNoNetwork()
45 reload.load_layerindex('file://%s/file.json' % self.tempdir) 45 def test_layerindex_store_file(self):
46 self.layerindex.store_layerindex('file://%s/file.json' % self.tempdir, self.layerindex.indexes[0])
46 47
47 self.assertFalse(reload.is_empty(), msg="Layerindex is empty") 48 self.assertTrue(os.path.isfile('%s/file.json' % self.tempdir), msg="Temporary file was not created by store_layerindex")
48 49
49 # Calculate layerItems in original index that should NOT be in reload 50 reload = layerindexlib.LayerIndex(self.d)
50 layerItemNames = [] 51 reload.load_layerindex('file://%s/file.json' % self.tempdir)
51 for itemId in self.layerindex.indexes[0].layerItems:
52 layerItemNames.append(self.layerindex.indexes[0].layerItems[itemId].name)
53 52
54 for layerBranchId in self.layerindex.indexes[0].layerBranches: 53 self.assertFalse(reload.is_empty(), msg="Layerindex is empty")
55 layerItemNames.remove(self.layerindex.indexes[0].layerBranches[layerBranchId].layer.name)
56 54
57 for itemId in reload.indexes[0].layerItems: 55 # Calculate layerItems in original index that should NOT be in reload
58 self.assertFalse(reload.indexes[0].layerItems[itemId].name in layerItemNames, msg="Item reloaded when it shouldn't have been") 56 layerItemNames = []
57 for itemId in self.layerindex.indexes[0].layerItems:
58 layerItemNames.append(self.layerindex.indexes[0].layerItems[itemId].name)
59 59
60 # Compare the original to what we wrote... 60 for layerBranchId in self.layerindex.indexes[0].layerBranches:
61 for type in self.layerindex.indexes[0]._index: 61 layerItemNames.remove(self.layerindex.indexes[0].layerBranches[layerBranchId].layer.name)
62 if type == 'apilinks' or \
63 type == 'layerItems' or \
64 type in self.layerindex.indexes[0].config['local']:
65 continue
66 for id in getattr(self.layerindex.indexes[0], type):
67 self.logger.debug(1, "type %s" % (type))
68 62
69 self.assertTrue(id in getattr(reload.indexes[0], type), msg="Id number not in reloaded index") 63 for itemId in reload.indexes[0].layerItems:
64 self.assertFalse(reload.indexes[0].layerItems[itemId].name in layerItemNames, msg="Item reloaded when it shouldn't have been")
70 65
71 self.logger.debug(1, "%s ? %s" % (getattr(self.layerindex.indexes[0], type)[id], getattr(reload.indexes[0], type)[id])) 66 # Compare the original to what we wrote...
67 for type in self.layerindex.indexes[0]._index:
68 if type == 'apilinks' or \
69 type == 'layerItems' or \
70 type in self.layerindex.indexes[0].config['local']:
71 continue
72 for id in getattr(self.layerindex.indexes[0], type):
73 self.logger.debug(1, "type %s" % (type))
72 74
73 self.assertEqual(getattr(self.layerindex.indexes[0], type)[id], getattr(reload.indexes[0], type)[id], msg="Reloaded contents different") 75 self.assertTrue(id in getattr(reload.indexes[0], type), msg="Id number not in reloaded index")
74 76
75 def test_layerindex_store_split(self): 77 self.logger.debug(1, "%s ? %s" % (getattr(self.layerindex.indexes[0], type)[id], getattr(reload.indexes[0], type)[id]))
76 self.layerindex.store_layerindex('file://%s' % self.tempdir, self.layerindex.indexes[0])
77 78
78 reload = layerindexlib.LayerIndex(self.d) 79 self.assertEqual(getattr(self.layerindex.indexes[0], type)[id], getattr(reload.indexes[0], type)[id], msg="Reloaded contents different")
79 reload.load_layerindex('file://%s' % self.tempdir)
80 80
81 self.assertFalse(reload.is_empty(), msg="Layer index is empty") 81 @skipIfNoNetwork()
82 def test_layerindex_store_split(self):
83 self.layerindex.store_layerindex('file://%s' % self.tempdir, self.layerindex.indexes[0])
82 84
83 for type in self.layerindex.indexes[0]._index: 85 reload = layerindexlib.LayerIndex(self.d)
84 if type == 'apilinks' or \ 86 reload.load_layerindex('file://%s' % self.tempdir)
85 type == 'layerItems' or \
86 type in self.layerindex.indexes[0].config['local']:
87 continue
88 for id in getattr(self.layerindex.indexes[0] ,type):
89 self.logger.debug(1, "type %s" % (type))
90 87
91 self.assertTrue(id in getattr(reload.indexes[0], type), msg="Id number missing from reloaded data") 88 self.assertFalse(reload.is_empty(), msg="Layer index is empty")
92 89
93 self.logger.debug(1, "%s ? %s" % (getattr(self.layerindex.indexes[0] ,type)[id], getattr(reload.indexes[0], type)[id])) 90 for type in self.layerindex.indexes[0]._index:
91 if type == 'apilinks' or \
92 type == 'layerItems' or \
93 type in self.layerindex.indexes[0].config['local']:
94 continue
95 for id in getattr(self.layerindex.indexes[0] ,type):
96 self.logger.debug(1, "type %s" % (type))
94 97
95 self.assertEqual(getattr(self.layerindex.indexes[0] ,type)[id], getattr(reload.indexes[0], type)[id], msg="reloaded data does not match original") 98 self.assertTrue(id in getattr(reload.indexes[0], type), msg="Id number missing from reloaded data")
96 99
97 def test_dependency_resolution(self): 100 self.logger.debug(1, "%s ? %s" % (getattr(self.layerindex.indexes[0] ,type)[id], getattr(reload.indexes[0], type)[id]))
98 # Verify depth first searching...
99 (dependencies, invalidnames) = self.layerindex.find_dependencies(names=['meta-python'])
100 101
101 first = True 102 self.assertEqual(getattr(self.layerindex.indexes[0] ,type)[id], getattr(reload.indexes[0], type)[id], msg="reloaded data does not match original")
102 for deplayerbranch in dependencies:
103 layerBranch = dependencies[deplayerbranch][0]
104 layerDeps = dependencies[deplayerbranch][1:]
105 103
106 if not first: 104 @skipIfNoNetwork()
107 continue 105 def test_dependency_resolution(self):
106 # Verify depth first searching...
107 (dependencies, invalidnames) = self.layerindex.find_dependencies(names=['meta-python'])
108 108
109 first = False 109 first = True
110 for deplayerbranch in dependencies:
111 layerBranch = dependencies[deplayerbranch][0]
112 layerDeps = dependencies[deplayerbranch][1:]
110 113
111 # Top of the deps should be openembedded-core, since everything depends on it. 114 if not first:
112 self.assertEqual(layerBranch.layer.name, "openembedded-core", msg='OpenEmbedded-Core is no the first dependency') 115 continue
113 116
114 # meta-python should cause an openembedded-core dependency, if not assert! 117 first = False
115 for dep in layerDeps:
116 if dep.layer.name == 'meta-python':
117 break
118 else:
119 self.logger.debug(1, "meta-python was not found")
120 self.assetTrue(False)
121 118
122 # Only check the first element... 119 # Top of the deps should be openembedded-core, since everything depends on it.
123 break 120 self.assertEqual(layerBranch.layer.name, "openembedded-core", msg='OpenEmbedded-Core is no the first dependency')
121
122 # meta-python should cause an openembedded-core dependency, if not assert!
123 for dep in layerDeps:
124 if dep.layer.name == 'meta-python':
125 break
124 else: 126 else:
125 # Empty list, this is bad. 127 self.logger.debug(1, "meta-python was not found")
126 self.logger.debug(1, "Empty list of dependencies") 128 self.assetTrue(False)
127 self.assertIsNotNone(first, msg="Empty list of dependencies") 129
130 # Only check the first element...
131 break
132 else:
133 # Empty list, this is bad.
134 self.logger.debug(1, "Empty list of dependencies")
135 self.assertIsNotNone(first, msg="Empty list of dependencies")
128 136
129 # Last dep should be the requested item 137 # Last dep should be the requested item
130 layerBranch = dependencies[deplayerbranch][0] 138 layerBranch = dependencies[deplayerbranch][0]
131 self.assertEqual(layerBranch.layer.name, "meta-python", msg="Last dependency not meta-python") 139 self.assertEqual(layerBranch.layer.name, "meta-python", msg="Last dependency not meta-python")
132 140
141 @skipIfNoNetwork()
133 def test_find_collection(self): 142 def test_find_collection(self):
134 def _check(collection, expected): 143 def _check(collection, expected):
135 self.logger.debug(1, "Looking for collection %s..." % collection) 144 self.logger.debug(1, "Looking for collection %s..." % collection)
@@ -149,6 +158,7 @@ class LayerIndexWebRestApiTest(LayersTest):
149 for collection,result in tests: 158 for collection,result in tests:
150 _check(collection, result) 159 _check(collection, result)
151 160
161 @skipIfNoNetwork()
152 def test_find_layerbranch(self): 162 def test_find_layerbranch(self):
153 def _check(name, expected): 163 def _check(name, expected):
154 self.logger.debug(1, "Looking for layerbranch %s..." % name) 164 self.logger.debug(1, "Looking for layerbranch %s..." % name)