diff --git a/module_build_service/views.py b/module_build_service/views.py index 22ff45e7..50221ac4 100644 --- a/module_build_service/views.py +++ b/module_build_service/views.py @@ -428,9 +428,9 @@ class SCMHandler(BaseHandler): 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: diff --git a/tests/test_views/test_views.py b/tests/test_views/test_views.py index 99b1832b..928a29b0 100644 --- a/tests/test_views/test_views.py +++ b/tests/test_views/test_views.py @@ -1831,10 +1831,8 @@ class TestViews: 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 @@ class TestViews: '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