| 
10 | 10 | from integration.helpers.deployer.utils.retry import retry_with_exponential_backoff_and_jitter  | 
11 | 11 | from integration.helpers.stack import Stack  | 
12 | 12 | from integration.helpers.yaml_utils import load_yaml  | 
13 |  | -from integration.helpers.resource import read_test_config_file, write_test_config_file_to_json  | 
 | 13 | +from integration.helpers.resource import (  | 
 | 14 | +    read_test_config_file,  | 
 | 15 | +    write_test_config_file_to_json,  | 
 | 16 | +    current_region_does_not_support,  | 
 | 17 | +)  | 
14 | 18 | 
 
  | 
15 | 19 | try:  | 
16 | 20 |     from pathlib import Path  | 
 | 
21 | 25 | 
 
  | 
22 | 26 | COMPANION_STACK_NAME = "sam-integ-stack-companion"  | 
23 | 27 | COMPANION_STACK_TEMPLATE = "companion-stack.yaml"  | 
 | 28 | +SAR_APP_TEMPLATE = "example-sar-app.yaml"  | 
 | 29 | +SAR_APP_NAME = "sam-integration-test-sar-app"  | 
 | 30 | +SAR_APP_VERSION = "1.0.3"  | 
24 | 31 | 
 
  | 
25 | 32 | 
 
  | 
26 | 33 | def _get_all_buckets():  | 
@@ -68,6 +75,38 @@ def setup_companion_stack_once(tmpdir_factory, get_prefix):  | 
68 | 75 |     companion_stack.create_or_update(_stack_exists(stack_name))  | 
69 | 76 | 
 
  | 
70 | 77 | 
 
  | 
 | 78 | +@pytest.fixture()  | 
 | 79 | +def get_serverless_application_repository_app():  | 
 | 80 | +    """Create or re-use a simple SAR app"""  | 
 | 81 | +    if current_region_does_not_support(["ServerlessRepo"]):  | 
 | 82 | +        LOG.info("Creating SAR application is skipped since SAR tests are not supported in this region.")  | 
 | 83 | +        return  | 
 | 84 | + | 
 | 85 | +    sar_client = ClientProvider().sar_client  | 
 | 86 | +    sar_apps = sar_client.list_applications().get("Applications", [])  | 
 | 87 | +    for sar_app in sar_apps:  | 
 | 88 | +        if sar_app.get("Name") == SAR_APP_NAME:  | 
 | 89 | +            LOG.info("SAR Application was already created, skipping SAR application publish")  | 
 | 90 | +            return sar_app.get("ApplicationId")  | 
 | 91 | + | 
 | 92 | +    LOG.info("SAR application not found, publishing new one...")  | 
 | 93 | + | 
 | 94 | +    tests_integ_dir = Path(__file__).resolve().parents[1]  | 
 | 95 | +    template_foler = Path(tests_integ_dir, "integration", "setup")  | 
 | 96 | +    sar_app_template_path = Path(template_foler, SAR_APP_TEMPLATE)  | 
 | 97 | +    with open(sar_app_template_path) as f:  | 
 | 98 | +        sar_template_contents = f.read()  | 
 | 99 | +    create_app_result = sar_client.create_application(  | 
 | 100 | +        Author="SAM Team",  | 
 | 101 | +        Description="SAR Application for Integration Tests",  | 
 | 102 | +        Name=SAR_APP_NAME,  | 
 | 103 | +        SemanticVersion=SAR_APP_VERSION,  | 
 | 104 | +        TemplateBody=sar_template_contents,  | 
 | 105 | +    )  | 
 | 106 | +    LOG.info("SAR application creation result: %s", create_app_result)  | 
 | 107 | +    return create_app_result.get("ApplicationId")  | 
 | 108 | + | 
 | 109 | + | 
71 | 110 | @pytest.fixture()  | 
72 | 111 | def upload_resources(get_s3):  | 
73 | 112 |     """  | 
 | 
0 commit comments