1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515
16- import os
17-
1816import requests
1917import mock
2018import sys
3230from st2tests .api import FunctionalTest
3331from st2tests .api import APIControllerWithIncludeAndExcludeFilterTestCase
3432
35- from st2tests .fixturesloader import get_fixtures_base_path
33+ from st2tests .fixtures .packs .dummy_pack_1 .fixture import (
34+ PACK_NAME as DUMMY_PACK_1 ,
35+ PACK_PATH as DUMMY_PACK_1_PATH ,
36+ )
37+ from st2tests .fixtures .packs .dummy_pack_10 .fixture import (
38+ PACK_NAME as DUMMY_PACK_10 ,
39+ PACK_PATH as DUMMY_PACK_10_PATH ,
40+ )
3641
3742__all__ = ["PacksControllerTestCase" ]
3843
@@ -498,15 +503,10 @@ def test_packs_register_endpoint(self, mock_get_packs):
498503
499504 # Note: We only register a couple of packs and not all on disk to speed
500505 # things up. Registering all the packs takes a long time.
501- fixtures_base_path = get_fixtures_base_path ()
502- packs_base_path = os .path .join (fixtures_base_path , "packs" )
503- pack_names = [
504- "dummy_pack_1" ,
505- "dummy_pack_10" ,
506- ]
507- mock_return_value = {}
508- for pack_name in pack_names :
509- mock_return_value [pack_name ] = os .path .join (packs_base_path , pack_name )
506+ mock_return_value = {
507+ DUMMY_PACK_1 : DUMMY_PACK_1_PATH ,
508+ DUMMY_PACK_10 : DUMMY_PACK_10_PATH ,
509+ }
510510
511511 mock_get_packs .return_value = mock_return_value
512512
@@ -529,7 +529,8 @@ def test_packs_register_endpoint(self, mock_get_packs):
529529
530530 # Register resources from a specific pack
531531 resp = self .app .post_json (
532- "/v1/packs/register" , {"packs" : ["dummy_pack_1" ], "fail_on_failure" : False }
532+ "/v1/packs/register" ,
533+ {"packs" : [DUMMY_PACK_1 ], "fail_on_failure" : False },
533534 )
534535
535536 self .assertEqual (resp .status_int , 200 )
@@ -538,13 +539,13 @@ def test_packs_register_endpoint(self, mock_get_packs):
538539 self .assertTrue (resp .json ["configs" ] >= 1 )
539540
540541 # Verify metadata_file attribute is set
541- action_dbs = Action .query (pack = "dummy_pack_1" )
542+ action_dbs = Action .query (pack = DUMMY_PACK_1 )
542543 self .assertEqual (action_dbs [0 ].metadata_file , "actions/my_action.yaml" )
543544
544545 # Register 'all' resource types should try include any possible content for the pack
545546 resp = self .app .post_json (
546547 "/v1/packs/register" ,
547- {"packs" : ["dummy_pack_1" ], "fail_on_failure" : False , "types" : ["all" ]},
548+ {"packs" : [DUMMY_PACK_1 ], "fail_on_failure" : False , "types" : ["all" ]},
548549 )
549550
550551 self .assertEqual (resp .status_int , 200 )
@@ -566,7 +567,7 @@ def test_packs_register_endpoint(self, mock_get_packs):
566567 # * policies -> policy types
567568 resp = self .app .post_json (
568569 "/v1/packs/register" ,
569- {"packs" : ["dummy_pack_1" ], "fail_on_failure" : False , "types" : ["actions" ]},
570+ {"packs" : [DUMMY_PACK_1 ], "fail_on_failure" : False , "types" : ["actions" ]},
570571 )
571572
572573 self .assertEqual (resp .status_int , 200 )
@@ -575,7 +576,7 @@ def test_packs_register_endpoint(self, mock_get_packs):
575576
576577 resp = self .app .post_json (
577578 "/v1/packs/register" ,
578- {"packs" : ["dummy_pack_1" ], "fail_on_failure" : False , "types" : ["rules" ]},
579+ {"packs" : [DUMMY_PACK_1 ], "fail_on_failure" : False , "types" : ["rules" ]},
579580 )
580581
581582 self .assertEqual (resp .status_int , 200 )
@@ -611,7 +612,7 @@ def test_packs_register_endpoint(self, mock_get_packs):
611612
612613 # Register specific type for a single packs
613614 resp = self .app .post_json (
614- "/v1/packs/register" , {"packs" : ["dummy_pack_1" ], "types" : ["action" ]}
615+ "/v1/packs/register" , {"packs" : [DUMMY_PACK_1 ], "types" : ["action" ]}
615616 )
616617
617618 self .assertEqual (resp .status_int , 200 )
@@ -620,7 +621,7 @@ def test_packs_register_endpoint(self, mock_get_packs):
620621
621622 # Verify that plural name form also works
622623 resp = self .app .post_json (
623- "/v1/packs/register" , {"packs" : ["dummy_pack_1" ], "types" : ["actions" ]}
624+ "/v1/packs/register" , {"packs" : [DUMMY_PACK_1 ], "types" : ["actions" ]}
624625 )
625626
626627 self .assertEqual (resp .status_int , 200 )
@@ -632,7 +633,7 @@ def test_packs_register_endpoint(self, mock_get_packs):
632633 resp = self .app .post_json (
633634 "/v1/packs/register" ,
634635 {
635- "packs" : ["dummy_pack_1" , "dummy_pack_1" , "dummy_pack_1" ],
636+ "packs" : [DUMMY_PACK_1 , DUMMY_PACK_1 , DUMMY_PACK_1 ],
636637 "types" : ["actions" ],
637638 "fail_on_failure" : False ,
638639 },
@@ -653,13 +654,13 @@ def test_packs_register_endpoint(self, mock_get_packs):
653654 # Fail on failure is enabled by default
654655 resp = self .app .post_json ("/v1/packs/register" , expect_errors = True )
655656
656- expected_msg = 'Failed to register pack "dummy_pack_10 ":'
657+ expected_msg = f 'Failed to register pack "{ DUMMY_PACK_10 } ":'
657658 self .assertEqual (resp .status_int , 400 )
658659 self .assertIn (expected_msg , resp .json ["faultstring" ])
659660
660661 # Fail on failure (broken pack metadata)
661662 resp = self .app .post_json (
662- "/v1/packs/register" , {"packs" : ["dummy_pack_1" ]}, expect_errors = True
663+ "/v1/packs/register" , {"packs" : [DUMMY_PACK_1 ]}, expect_errors = True
663664 )
664665
665666 expected_msg = 'Referenced policy_type "action.mock_policy_error" doesnt exist'
0 commit comments