def test_init_cli_with_extra_context_not_overriding_default_parameter( self, generate_project_patch): # GIVEN generate_project successfully created a project # WHEN a project name has been passed init_cli( ctx=self.ctx, no_interactive=self.no_interactive, location=self.location, runtime=self.runtime, dependency_manager=self.dependency_manager, output_dir=self.output_dir, name=self.name, app_template=self.app_template, no_input=self.no_input, extra_context= '{"project_name": "my_project", "runtime": "java8", "schema_name":"events", "schema_type": "aws"}', auto_clone=False, ) # THEN we should receive no errors generate_project_patch.assert_called_once_with( ANY, self.runtime, self.dependency_manager, ".", self.name, True, { "project_name": "testing project", "runtime": "python3.6", "schema_name": "events", "schema_type": "aws" }, )
def test_init_cli_with_extra_context_parameter_not_passed( self, generate_project_patch): # GIVEN no extra_context parameter passed # WHEN sam init init_cli( ctx=self.ctx, no_interactive=self.no_interactive, location=self.location, pt_explicit=self.pt_explicit, package_type=self.package_type, runtime=self.runtime, base_image=self.base_image, dependency_manager=self.dependency_manager, output_dir=self.output_dir, name=self.name, app_template=self.app_template, no_input=self.no_input, extra_context=None, auto_clone=False, ) # THEN we should receive no errors generate_project_patch.assert_called_once_with( ANY, ZIP, self.runtime, self.dependency_manager, ".", self.name, True, self.extra_context_as_json)
def test_init_image_cli(self, generate_project_patch, sd_mock): # GIVEN generate_project successfully created a project # WHEN a project name has been passed init_cli( ctx=self.ctx, no_interactive=self.no_interactive, location=self.location, pt_explicit=self.pt_explicit, package_type=IMAGE, runtime=None, base_image="amazon/nodejs12.x-base", dependency_manager="npm", output_dir=None, name=self.name, app_template=None, no_input=self.no_input, extra_context=None, auto_clone=False, ) # THEN we should receive no errors generate_project_patch.assert_called_once_with( # need to change the location validation check ANY, IMAGE, "nodejs12.x", "npm", self.output_dir, self.name, True, { "runtime": "nodejs12.x", "project_name": "testing project" }, )
def test_init_cli_with_extra_context_parameter_passed_as_escaped(self, generate_project_patch): # GIVEN extra_context and default_parameter(name, runtime) # WHEN sam init init_cli( ctx=self.ctx, no_interactive=self.no_interactive, location=self.location, pt_explicit=self.pt_explicit, package_type=self.package_type, runtime=self.runtime, base_image=self.base_image, dependency_manager=self.dependency_manager, output_dir=self.output_dir, name=self.name, app_template=self.app_template, no_input=self.no_input, # fmt: off extra_context='{\"schema_name\":\"events\", \"schema_type\":\"aws\"}', # fmt: on auto_clone=False, ) # THEN we should receive no errors and right extra_context should be passed generate_project_patch.assert_called_once_with( ANY, ZIP, self.runtime, self.dependency_manager, ".", self.name, True, {"project_name": "testing project", "runtime": "python3.6", "schema_name": "events", "schema_type": "aws"}, )
def test_init_passes_dynamic_event_bridge_template( self, generate_project_patch, location_from_app_template_mock): location_from_app_template_mock.return_value = "applocation" # WHEN dynamic event bridge template is passed in non-interactive mode. init_cli( ctx=self.ctx, no_interactive=True, location=self.location, pt_explicit=self.pt_explicit, package_type=self.package_type, runtime=self.runtime, base_image=self.base_image, dependency_manager=self.dependency_manager, output_dir=None, name=self.name, app_template="eventBridge-schema-app", no_input=self.no_input, extra_context=None, auto_clone=False, ) generate_project_patch.assert_called_once_with( # need to change the location validation check ANY, ZIP, self.runtime, self.dependency_manager, self.output_dir, self.name, True, self.extra_context_as_json, )
def test_init_cli_with_extra_context_not_overriding_default_parameter(self, generate_project_patch): # GIVEN default_parameters(name, runtime) and extra_context trying to override default parameter # WHEN sam init init_cli( ctx=self.ctx, no_interactive=self.no_interactive, location=self.location, pt_explicit=self.pt_explicit, package_type=self.package_type, runtime=self.runtime, base_image=self.base_image, dependency_manager=self.dependency_manager, output_dir=self.output_dir, name=self.name, app_template=self.app_template, no_input=self.no_input, extra_context='{"project_name": "my_project", "runtime": "java8", "schema_name":"events", "schema_type": "aws"}', auto_clone=False, ) # THEN extra_context should have not overridden default_parameters(name, runtime) generate_project_patch.assert_called_once_with( ANY, ZIP, self.runtime, self.dependency_manager, ".", self.name, True, {"project_name": "testing project", "runtime": "python3.6", "schema_name": "events", "schema_type": "aws"}, )
def test_init_cli_must_only_set_passed_runtime_when_location_is_provided(self, generate_project_patch): # GIVEN only runtime and extra_context # WHEN sam init init_cli( ctx=self.ctx, no_interactive=self.no_interactive, location="custom location", pt_explicit=self.pt_explicit, package_type=self.package_type, runtime="java8", base_image=self.base_image, dependency_manager=None, output_dir=self.output_dir, name=None, app_template=None, no_input=None, extra_context='{"schema_name":"events", "schema_type": "aws"}', auto_clone=False, ) # THEN extra_context should be without name generate_project_patch.assert_called_once_with( "custom location", ZIP, "java8", None, ".", None, None, {"schema_name": "events", "schema_type": "aws", "runtime": "java8"}, )
def test_init_cli_must_set_default_context_when_location_is_provided( self, generate_project_patch): # GIVEN default_parameter(name, runtime) with location # WHEN sam init init_cli( ctx=self.ctx, no_interactive=self.no_interactive, location="custom location", runtime="java8", dependency_manager=None, output_dir=self.output_dir, name="test-project", app_template=None, no_input=None, extra_context='{"schema_name":"events", "schema_type": "aws"}', auto_clone=False, ) # THEN should set default parameter(name, runtime) as extra_context generate_project_patch.assert_called_once_with( "custom location", "java8", None, ".", "test-project", None, { "schema_name": "events", "schema_type": "aws", "runtime": "java8", "project_name": "test-project" }, )
def test_init_cli_must_only_set_passed_project_name_when_location_is_provided( self, generate_project_patch): # GIVEN only name and extra_context # WHEN sam init init_cli( ctx=self.ctx, no_interactive=self.no_interactive, location="custom location", runtime=None, dependency_manager=None, output_dir=self.output_dir, name="test-project", app_template=None, no_input=None, extra_context='{"schema_name":"events", "schema_type": "aws"}', auto_clone=False, ) # THEN extra_context should be without runtime generate_project_patch.assert_called_once_with( "custom location", None, None, ".", "test-project", None, { "schema_name": "events", "schema_type": "aws", "project_name": "test-project" }, )
def test_init_cli(self, generate_project_patch, sd_mock): # GIVEN generate_project successfully created a project # WHEN a project name has been passed init_cli( ctx=self.ctx, no_interactive=self.no_interactive, location=self.location, pt_explicit=self.pt_explicit, package_type=self.package_type, runtime=self.runtime, base_image=self.base_image, dependency_manager=self.dependency_manager, output_dir=None, name=self.name, app_template=self.app_template, no_input=self.no_input, extra_context=None, auto_clone=False, ) # THEN we should receive no errors generate_project_patch.assert_called_once_with( # need to change the location validation check ANY, ZIP, self.runtime, self.dependency_manager, self.output_dir, self.name, True, self.extra_context_as_json, )
def test_init_cli_generate_project_fails(self, generate_project_patch, sd_mock): # GIVEN generate_project fails to create a project generate_project_patch.side_effect = GenerateProjectFailedError( project=self.name, provider_error="Something wrong happened") # WHEN generate_project returns an error # THEN we should receive a GenerateProjectFailedError Exception with self.assertRaises(UserException): init_cli( self.ctx, no_interactive=self.no_interactive, location="self.location", runtime=self.runtime, dependency_manager=self.dependency_manager, output_dir=self.output_dir, name=self.name, app_template=None, no_input=self.no_input, auto_clone=False, ) generate_project_patch.assert_called_with(self.location, self.runtime, self.dependency_manager, self.output_dir, self.name, self.no_input)
def test_init_cli_generate_project_image_fails(self, generate_project_patch, sd_mock): # GIVEN generate_project fails to create a project generate_project_patch.side_effect = GenerateProjectFailedError( project=self.name, provider_error="Something wrong happened") # WHEN generate_project returns an error # THEN we should receive a GenerateProjectFailedError Exception with self.assertRaises(UserException): init_cli( self.ctx, no_interactive=self.no_interactive, location=self.location, pt_explicit=self.pt_explicit, package_type=IMAGE, runtime=None, base_image="python3.6-base", dependency_manager="wrong-dependency-manager", output_dir=self.output_dir, name=self.name, app_template=None, no_input=self.no_input, extra_context=None, auto_clone=False, ) generate_project_patch.assert_called_with(self.location, self.runtime, self.dependency_manager, self.output_dir, self.name, self.no_input)
def test_generate_project(self): # GIVEN generate_project successfully created a project # WHEN a project name has been passed init_cli( ctx=None, location=self.location, runtime=self.runtime, output_dir=self.output_dir, name=self.name, no_input=self.no_input) # THEN we should see a new project created and a successful return self.assertTrue(os.path.isdir(self.project_folder))
def test_custom_location(self): # GIVEN generate_project successfuly created a project # WHEN a custom template has been passed # and we were asked to accept default values provided by the template self.location = "https://github.com/aws-samples/cookiecutter-aws-sam-python" init_cli( ctx=None, location=self.location, runtime=self.runtime, output_dir=self.output_dir, name=self.name, no_input=True) # THEN we should see a new project created and a successful return # and this new folder should be named 'name-of-the-project' # which is the default value for this custom template self.assertTrue(os.path.isdir(self.custom_location_folder))
def test_init_cli(self, generate_project_patch): # GIVEN generate_project successfully created a project # WHEN a project name has been passed init_cli(ctx=self.ctx, location=self.location, runtime=self.runtime, dependency_manager=self.dependency_manager, output_dir=self.output_dir, name=self.name, no_input=self.no_input) # THEN we should receive no errors generate_project_patch.assert_called_once_with( self.location, self.runtime, self.dependency_manager, self.output_dir, self.name, self.no_input)
def test_init_fails_invalid_dep_mgr(self, sd_mock): # WHEN an unknown app template is passed in # THEN an exception should be raised with self.assertRaises(UserException): init_cli( ctx=self.ctx, no_interactive=self.no_interactive, location=self.location, runtime=self.runtime, dependency_manager="bad-wrong", output_dir=None, name=self.name, app_template=self.app_template, no_input=self.no_input, auto_clone=False, )
def test_init_cli_mutually_exclusive_params_fails(self): # WHEN we call init without necessary parameters # THEN we should receive a UserException with self.assertRaises(UserException): init_cli( self.ctx, no_interactive=self.no_interactive, location="whatever", runtime=self.runtime, dependency_manager=self.dependency_manager, output_dir=self.output_dir, name=self.name, app_template="fails-anyways", no_input=self.no_input, auto_clone=False, )
def test_init_cli_missing_params_fails(self): # WHEN we call init without necessary parameters # THEN we should receive a UserException with self.assertRaises(UserException): init_cli( self.ctx, no_interactive=True, location=None, runtime=None, dependency_manager=None, output_dir=None, name=None, app_template=None, no_input=True, auto_clone=False, )
def test_init_cli_with_extra_context_input_as_wrong_json_raises_exception(self, generate_project_patch): # GIVEN generate_project successfully created a project # WHEN a project name has been passed with self.assertRaises(UserException): init_cli( ctx=self.ctx, no_interactive=self.no_interactive, location=self.location, runtime=self.runtime, dependency_manager=self.dependency_manager, output_dir=self.output_dir, name=self.name, app_template=self.app_template, no_input=self.no_input, extra_context='{"project_name", "my_project", "runtime": "java8", "schema_name":"events", "schema_type": "aws"}', auto_clone=False, )
def test_init_cli_with_extra_context_input_as_wrong_json_raises_exception( self): # GIVEN extra_context as wrong json # WHEN a sam init is called with self.assertRaises(UserException): init_cli( ctx=self.ctx, no_interactive=self.no_interactive, location=self.location, runtime=self.runtime, dependency_manager=self.dependency_manager, output_dir=self.output_dir, name=self.name, app_template=self.app_template, no_input=self.no_input, extra_context= '{"project_name", "my_project", "runtime": "java8", "schema_name":"events", "schema_type": "aws"}', auto_clone=False, )
def test_init_cli_generate_project_fails(self, generate_project_patch): # GIVEN generate_project fails to create a project generate_project_patch.side_effect = GenerateProjectFailedError( project=self.name, provider_error="Something wrong happened") # WHEN generate_project returns an error # THEN we should receive a GenerateProjectFailedError Exception with self.assertRaises(UserException): init_cli(self.ctx, location="self.location", runtime=self.runtime, output_dir=self.output_dir, name=self.name, no_input=self.no_input) generate_project_patch.assert_called_with(self.location, self.runtime, self.output_dir, self.name, self.no_input)
def test_init_fails_invalid_template(self, sd_mock): # WHEN an unknown app template is passed in # THEN an exception should be raised with self.assertRaises(UserException): init_cli( ctx=self.ctx, no_interactive=self.no_interactive, location=self.location, pt_explicit=self.pt_explicit, package_type=self.package_type, runtime=self.runtime, base_image=self.base_image, dependency_manager=self.dependency_manager, output_dir=None, name=self.name, app_template="wrong-and-bad", no_input=self.no_input, extra_context=None, auto_clone=False, )
def test_init_cli_with_extra_context_parameter_not_passed(self, generate_project_patch): # GIVEN generate_project successfully created a project # WHEN a project name has been passed init_cli( ctx=self.ctx, no_interactive=self.no_interactive, location=self.location, runtime=self.runtime, dependency_manager=self.dependency_manager, output_dir=self.output_dir, name=self.name, app_template=self.app_template, no_input=self.no_input, extra_context=None, auto_clone=False, ) # THEN we should receive no errors generate_project_patch.assert_called_once_with( ANY, self.runtime, self.dependency_manager, ".", self.name, True, self.extra_context_as_json )