def test_pythonObjectFromYamlParsingShouldBeTheSameAsJsonParsing(self): # Given json_path = find_relative_path_for( "tests/integration/data/test-parsing.json") yaml_path = find_relative_path_for( "tests/integration/data/test-parsing.yml") # When json_data = json.load(open(json_path)) yaml_data = yaml.load(open(yaml_path)) # Then self.assertEqual( json_data, yaml_data, 'Error : python object made from json parsing is different from yaml parsing' )
def test_do_build_should_return_0_when_id_given_and_no_stack_section( self, mock_api_appliance_getall, mock_api_appliance_getinstallprofile, mock_api_targetformat_getall, mock_api_generate): # given yaml_path = find_relative_path_for( "tests/integration/data/publish_builder.yml") args = "--file '%s' --id 1" % yaml_path template = self.create_template("url", "username", "password", "login", "password") timeZone = "UTC" self.create_appliance_list(timeZone, mock_api_appliance_getall) self.create_installprofile(timeZone, mock_api_appliance_getinstallprofile) self.create_targetformat_list(mock_api_targetformat_getall) self.create_targetformat_list(mock_api_targetformat_getall) self.prepare_mock_generate(mock_api_generate) # when return_value = template.do_build(args) # then self.assertEqual(0, return_value)
def test_check_bundle_should_failed_when_tag_ospkg_in_directory(self, mock_method): #Given jsonPath = find_relative_path_for("tests/integration/data/bundle/bundleFilesTagOSPkgInDirectory.json") #When bundle = generics_utils.check_json_syntax(jsonPath) bundle_utils.check_bundle(bundle) #Then mock_method.assert_called_with("The file 'iotop-0.6-2.el7.noarch.rpm, with tag 'ospkg' must be in the first level files section", "ERROR")
def test_check_bundle_should_failed_when_files_no_source(self, mock_method): #Given jsonPath = find_relative_path_for("tests/integration/data/bundle/bundleFilesWithoutSource.json") #When bundle = generics_utils.check_json_syntax(jsonPath) bundle_utils.check_bundle(bundle) #Then mock_method.assert_called_with("There is no attribute [source] for a [file]", "ERROR")
def test_check_bundle_should_failed_when_no_version(self, mock_method): #Given jsonPath = find_relative_path_for("tests/integration/data/bundle/bundleWithoutVersion.json") #When bundle = generics_utils.check_json_syntax(jsonPath) bundle_utils.check_bundle(bundle) #Then mock_method.assert_called_with("no attribute [version] for [bundle]", "ERROR")
def test_check_bundle_should_failed_when_tag_bootscript_and_rights(self, mock_method): #Given jsonPath = find_relative_path_for("tests/integration/data/bundle/bundleFilesTagBootScriptKeyRights.json") #When bundle = generics_utils.check_json_syntax(jsonPath) bundle_utils.check_bundle(bundle) #Then mock_method.assert_called_with("There is the attribute [ownerGroup], [rights] or [symlink] for file 'cleanup_tmp.sh' but is not tagged as 'softwarefile'", "ERROR")
def test_check_bundle_should_failed_when_tag_softwarefile_and_bootorder(self, mock_method): #Given jsonPath = find_relative_path_for("tests/integration/data/bundle/bundleFilesTagSoftwareFileKeyBootOrder.json") #When bundle = generics_utils.check_json_syntax(jsonPath) bundle_utils.check_bundle(bundle) #Then mock_method.assert_called_with("There is the attribute [bootOrder] or [bootType] for file 'directoryTest' but is not tagged as 'bootscript'", "ERROR")
def test_check_bundle_should_succeed_when_no_restrictionRule(self): # Given jsonPath = find_relative_path_for("tests/integration/data/bundle/bundleWithoutRestrictionRule.json") # When bundle = generics_utils.check_json_syntax(jsonPath) bundle_utils.check_bundle(bundle) # Then self.assertIsNotNone(bundle)
def test_check_bundle_should_succeed(self): #Given jsonPath = find_relative_path_for( "tests/integration/data/bundle/bundleFull.json") #When bundle = generics_utils.check_json_syntax(jsonPath) bundle = bundle_utils.check_bundle(bundle) #Then self.assertIsNotNone(bundle)
def test_check_bundle_should_failed_when_no_version(self, mock_method): #Given jsonPath = find_relative_path_for( "tests/integration/data/bundle/bundleWithoutVersion.json") #When bundle = generics_utils.check_json_syntax(jsonPath) bundle_utils.check_bundle(bundle) #Then mock_method.assert_called_with("no attribute [version] for [bundle]", "ERROR")
def test_check_bundle_should_succeed_when_empty_restrictionRule(self): # Given jsonPath = find_relative_path_for( "tests/integration/data/bundle/bundleWithEmptyRestrictionRule.json" ) # When bundle = generics_utils.check_json_syntax(jsonPath) bundle_utils.check_bundle(bundle) # Then self.assertIsNotNone(bundle)
def test_check_bundle_should_failed_when_files_no_name(self, mock_method): #Given jsonPath = find_relative_path_for( "tests/integration/data/bundle/bundleFilesWithoutName.json") #When bundle = generics_utils.check_json_syntax(jsonPath) bundle_utils.check_bundle(bundle) #Then mock_method.assert_called_with( "There is no attribute [name] for a [file]", "ERROR")
def test_is_image_ready_to_publish_returns_true_when_memory_and_swap_size_are_defined(self): # given image = self.build_image_to_publish("complete", True, self.app_uri) file = find_relative_path_for("tests/integration/data/publish_builder.yml") builder = self.build_builder(file) # when image_ready = is_image_ready_to_publish(image, builder) # then self.assertEqual(image_ready, True)
def test_is_image_ready_to_publish_returns_false_when_status_is_cancelled(self): # given image = self.build_image_to_publish("cancelled", False, self.app_uri) file = find_relative_path_for("tests/integration/data/publish_builder.yml") builder = self.build_builder(file) # when image_ready = is_image_ready_to_publish(image, builder) # then self.assertEqual(image_ready, False)
def test_validate_builder_file_with_no_template_id_return_None_when_stack_and_builder_are_missing( self): # Given yaml_path = find_relative_path_for( "tests/integration/data/deploy_aws.yml") # When data = hammr_utils.validate_builder_file_with_no_template_id(yaml_path) # Then self.assertEqual(data, None)
def test_validate_validate_builder_file_with_no_template_id_return_data_when_stack_and_builder_are_not_missing( self): # Given json_path = find_relative_path_for( "tests/integration/data/templatePXE.json") # When data = hammr_utils.validate_builder_file_with_no_template_id(json_path) # Then self.assertNotEqual(data, None)
def testbuild_deployment_azure_returns_None_when_file_incomplete(self): # Given file = find_relative_path_for("tests/integration/data/deploy_azure_incomplete.yml") # When try: check_and_get_attributes_from_file(file, ["name", "userName"]) except ValueError: return #Then self.fail(self)
def test_do_build_should_return_2_when_no_id_given_and_no_stack_section(self): # given yaml_path = find_relative_path_for("tests/integration/data/publish_builder.yml") args = "--file '%s'" % yaml_path template = self.create_template("url", "username", "password", "login", "password") # when return_value = template.do_build(args) # then self.assertEqual(2, return_value)
def test_build_deployment_openstack_returns_None_when_file_incomplete(self): # Given file = find_relative_path_for("tests/integration/data/deploy_openstack_incomplete.yml") # When try: check_and_get_attributes_from_file(file, ["name", "region", "network", "flavor"]) except ValueError: return #Then self.fail(self)
def testbuild_deployment_azure_returns_None_when_file_incomplete(self): # Given file = find_relative_path_for( "tests/integration/data/deploy_azure_incomplete.yml") # When try: check_and_get_attributes_from_file(file, ["name", "userName"]) except ValueError: return #Then self.fail(self)
def test_check_bundle_should_failed_when_tag_softwarefile_and_bootorder( self, mock_method): #Given jsonPath = find_relative_path_for( "tests/integration/data/bundle/bundleFilesTagSoftwareFileKeyBootOrder.json" ) #When bundle = generics_utils.check_json_syntax(jsonPath) bundle_utils.check_bundle(bundle) #Then mock_method.assert_called_with( "There is the attribute [bootOrder] or [bootType] for file 'directoryTest' but is not tagged as 'bootscript'", "ERROR")
def test_check_bundle_should_failed_when_tag_bootscript_and_rights( self, mock_method): #Given jsonPath = find_relative_path_for( "tests/integration/data/bundle/bundleFilesTagBootScriptKeyRights.json" ) #When bundle = generics_utils.check_json_syntax(jsonPath) bundle_utils.check_bundle(bundle) #Then mock_method.assert_called_with( "There is the attribute [ownerGroup], [rights] or [symlink] for file 'cleanup_tmp.sh' but is not tagged as 'softwarefile'", "ERROR")
def test_check_bundle_should_failed_when_tag_ospkg_in_directory( self, mock_method): #Given jsonPath = find_relative_path_for( "tests/integration/data/bundle/bundleFilesTagOSPkgInDirectory.json" ) #When bundle = generics_utils.check_json_syntax(jsonPath) bundle_utils.check_bundle(bundle) #Then mock_method.assert_called_with( "The file 'iotop-0.6-2.el7.noarch.rpm, with tag 'ospkg' must be in the first level files section", "ERROR")
def test_do_build_should_return_2_when_no_id_given_and_no_stack_section( self): # given yaml_path = find_relative_path_for( "tests/integration/data/publish_builder.yml") args = "--file '%s'" % yaml_path template = self.create_template("url", "username", "password", "login", "password") # when return_value = template.do_build(args) # then self.assertEqual(2, return_value)
def test_build_deployment_openstack_returns_None_when_file_incomplete( self): # Given file = find_relative_path_for( "tests/integration/data/deploy_openstack_incomplete.yml") # When try: check_and_get_attributes_from_file( file, ["name", "region", "network", "flavor"]) except ValueError: return #Then self.fail(self)
def test_do_create_should_return_2_when_image_already_exist(self, mock_api_imports_getall, mock_api_upload): # given yaml_path = find_relative_path_for("tests/integration/data/test-parsing.yml") args = "--file " + yaml_path template = self.create_template("url", "username", "password", "login", "password") status = OpStatus() status.error = True status.message = "error" status.errorMessage = "error" mock_api_upload.return_value = status # when return_value = template.do_create(args) # then self.assertEqual(2, return_value)
def test_do_build_should_return_0_when_id_given_and_no_stack_section(self, mock_api_appliance_getall, mock_api_appliance_getinstallprofile, mock_api_targetformat_getall, mock_api_generate): # given yaml_path = find_relative_path_for("tests/integration/data/publish_builder.yml") args = "--file '%s' --id 1" % yaml_path template = self.create_template("url", "username", "password", "login", "password") timeZone = "UTC" self.create_appliance_list(timeZone, mock_api_appliance_getall) self.create_installprofile(timeZone, mock_api_appliance_getinstallprofile) self.create_targetformat_list(mock_api_targetformat_getall) self.create_targetformat_list(mock_api_targetformat_getall) self.prepare_mock_generate(mock_api_generate) # when return_value = template.do_build(args) # then self.assertEqual(0, return_value)
def prepare_image_deploy_command_openstack(self, id): args = "--file %s --publish-id %s" % (find_relative_path_for("tests/integration/data/deploy_openstack.yml"), id) return args