#1162 Always allow submitting yaml for scratch module builds.
Merged 4 months ago by jkaluza. Opened 4 months ago by merlinm.

@@ -428,9 +428,9 @@

  

  class YAMLFileHandler(BaseHandler):

      def __init__(self, request):

-         if not conf.yaml_submit_allowed:

-             raise Forbidden("YAML submission is not enabled")

          super(YAMLFileHandler, self).__init__(request)

+         if not self.data['scratch'] and not conf.yaml_submit_allowed:

+             raise Forbidden("YAML submission is not enabled")

  

      def validate(self):

          if "yaml" not in request.files:

@@ -1831,10 +1831,8 @@

             new_callable=PropertyMock, return_value=True)

      @patch('module_build_service.config.Config.yaml_submit_allowed',

             new_callable=PropertyMock, return_value=False)

-     def test_submit_scratch_build_with_mmd_not_allowed(self, mocked_allow_yaml,

-                                                        mocked_allow_scratch,

-                                                        mocked_get_user,

-                                                        api_version):

+     def test_submit_scratch_build_with_mmd_yaml_not_allowed(

+             self, mocked_allow_yaml, mocked_allow_scratch, mocked_get_user, api_version):

          base_dir = path.abspath(path.dirname(__file__))

          mmd_path = path.join(base_dir, '..', 'staged_data', 'testmodule.yaml')

          post_url = '/module-build-service/{0}/module-builds/'.format(api_version)

@@ -1846,11 +1844,6 @@

                  'yaml': yaml_file,

              }

              rv = self.client.post(post_url, content_type='multipart/form-data', data=post_data)

-         data = json.loads(rv.data)

-         expected_error = {

-             'error': 'Forbidden',

-             'message': 'YAML submission is not enabled',

-             'status': 403

-         }

-         assert data == expected_error

-         assert rv.status_code == expected_error['status']

+         # this test is the same as the previous except YAML_SUBMIT_ALLOWED is False,

+         # but it should still succeed since yaml is always allowed for scratch builds

+         assert rv.status_code == 201

Setting YAML_SUBMIT_ALLOWED = True in the config file should not be required in order to submit a modulemd file for scratch module builds. This PR fixes that logic and an associated test.

make better condition to avoid "pass" statement
if not conf.yaml_submit_allowed and not self.data['scratch']

rebased onto 244d873

4 months ago

Pull-Request has been merged by jkaluza

4 months ago