Speed up the test by only registering some packs and not all packs on
disks.
We have way too many test fixture packs on disk and registering
resources from all inside the test takes a long time.
With this change tests are now substantially faster.
# See the License for the specific language governing permissions and
# limitations under the License.
+import os
+
import mock
+from st2common.content.loader import ContentPackLoader
from st2common.models.db.pack import PackDB
from st2common.persistence.pack import Pack
from st2common.router import Response
@@ -23,6 +26,12 @@ from st2api.controllers.v1.actionexecutions import ActionExecutionsControllerMix
from st2api.controllers.v1.packs import ENTITIES
from tests import FunctionalTest
+from st2tests.fixturesloader import get_fixtures_base_path
+
+__all__ = [
+ 'PacksControllerTestCase'
+]
+
PACK_INDEX = {
"test": {
"version": "0.4.0",
@@ -195,9 +204,27 @@ class PacksControllerTestCase(FunctionalTest):
]
self.assertEqual(resource_types, expected_order)
- def test_packs_register_endpoint(self):
+ @mock.patch.object(ContentPackLoader, 'get_packs')
+ def test_packs_register_endpoint(self, mock_get_packs):
# Register resources from all packs - make sure the count values are correctly added
# together
+
+ # Note: We only register a couple of packs and not all on disk to speed
+ # things up. Registering all the packs takes a long time.
+ fixtures_base_path = get_fixtures_base_path()
+ packs_base_path = os.path.join(fixtures_base_path, 'packs')
+ pack_names = [
+ 'dummy_pack_1',
+ 'dummy_pack_2',
+ 'dummy_pack_3',
+ 'dummy_pack_10',
+ ]
+ mock_return_value = {}
+ for pack_name in pack_names:
+ mock_return_value[pack_name] = os.path.join(packs_base_path, pack_name)
+
+ mock_get_packs.return_value = mock_return_value
+
resp = self.app.post_json('/v1/packs/register', {'fail_on_failure': False})
self.assertEqual(resp.status_int, 200)
@@ -213,7 +240,7 @@ class PacksControllerTestCase(FunctionalTest):
self.assertTrue('configs' in resp.json)
self.assertTrue(resp.json['actions'] >= 3)
- self.assertTrue(resp.json['configs'] >= 3)
+ self.assertTrue(resp.json['configs'] >= 1)
# Register resources from a specific pack
resp = self.app.post_json('/v1/packs/register', {'packs': ['dummy_pack_1'],
