Skip to content
Snippets Groups Projects
Commit bbe022a8 authored by Jörn Künsemöller's avatar Jörn Künsemöller
Browse files

TMSS-909: Fix invalid Swagger parameter config and add test that detects when Swagger breaks again

parent b14b06a3
No related branches found
No related tags found
3 merge requests!634WIP: COBALT commissioning delta,!523TMSS-909: Fix invalid Swagger parameter config and add test that detects when Swagger breaks again,!481Draft: SW-971 SW-973 SW-975: Various fixes to build LOFAR correctly.
...@@ -20,6 +20,7 @@ from rest_framework.response import Response as RestResponse ...@@ -20,6 +20,7 @@ from rest_framework.response import Response as RestResponse
from drf_yasg.utils import swagger_auto_schema from drf_yasg.utils import swagger_auto_schema
from drf_yasg.openapi import Parameter from drf_yasg.openapi import Parameter
from drf_yasg import openapi
from lofar.sas.tmss.tmss.tmssapp.viewsets.lofar_viewset import LOFARViewSet, LOFARNestedViewSet, AbstractTemplateViewSet, LOFARCopyViewSet, LOFARFilterBackend from lofar.sas.tmss.tmss.tmssapp.viewsets.lofar_viewset import LOFARViewSet, LOFARNestedViewSet, AbstractTemplateViewSet, LOFARCopyViewSet, LOFARFilterBackend
from lofar.sas.tmss.tmss.tmssapp import models from lofar.sas.tmss.tmss.tmssapp import models
...@@ -81,14 +82,14 @@ class SchedulingUnitObservingStrategyTemplateViewSet(LOFARViewSet): ...@@ -81,14 +82,14 @@ class SchedulingUnitObservingStrategyTemplateViewSet(LOFARViewSet):
@swagger_auto_schema(responses={status.HTTP_201_CREATED: 'The newly created scheduling unit', @swagger_auto_schema(responses={status.HTTP_201_CREATED: 'The newly created scheduling unit',
status.HTTP_403_FORBIDDEN: 'forbidden'}, status.HTTP_403_FORBIDDEN: 'forbidden'},
operation_description="Create a new SchedulingUnit based on this SchedulingUnitObservingStrategyTemplate, with the given <name> and <description> and make it a child of the given <scheduling_set_id>", operation_description="Create a new SchedulingUnit based on this SchedulingUnitObservingStrategyTemplate, with the given <name> and <description> and make it a child of the given <scheduling_set_id>",
request_body=openapi.Schema(type=openapi.TYPE_OBJECT,
description="a JSON dict containing the override values for the parameters in the template"),
manual_parameters=[Parameter(name='scheduling_set_id', required=True, type='integer', in_='query', manual_parameters=[Parameter(name='scheduling_set_id', required=True, type='integer', in_='query',
description="the id of the scheduling_set which will be the parent of the newly created scheduling_unit"), description="the id of the scheduling_set which will be the parent of the newly created scheduling_unit"),
Parameter(name='name', required=False, type='string', in_='query', Parameter(name='name', required=False, type='string', in_='query',
description="The name for the newly created scheduling_unit"), description="The name for the newly created scheduling_unit"),
Parameter(name='description', required=False, type='string', in_='query', Parameter(name='description', required=False, type='string', in_='query',
description="The description for the newly created scheduling_unit"), description="The description for the newly created scheduling_unit")
Parameter(name='requirements_doc_overrides', required=False, type='dict', in_='body',
description="a JSON dict containing the override values for the parameters in the template")
]) ])
@action(methods=['post'], detail=True) @action(methods=['post'], detail=True)
def create_scheduling_unit(self, request, pk=None): def create_scheduling_unit(self, request, pk=None):
......
...@@ -40,6 +40,7 @@ if(BUILD_TESTING) ...@@ -40,6 +40,7 @@ if(BUILD_TESTING)
lofar_add_test(t_complex_serializers) lofar_add_test(t_complex_serializers)
lofar_add_test(t_observation_strategies_specification_and_scheduling_test) lofar_add_test(t_observation_strategies_specification_and_scheduling_test)
lofar_add_test(t_reservations) lofar_add_test(t_reservations)
lofar_add_test(t_swagger)
set_tests_properties(t_scheduling PROPERTIES TIMEOUT 300) set_tests_properties(t_scheduling PROPERTIES TIMEOUT 300)
set_tests_properties(t_tmssapp_scheduling_REST_API PROPERTIES TIMEOUT 300) set_tests_properties(t_tmssapp_scheduling_REST_API PROPERTIES TIMEOUT 300)
......
#!/usr/bin/env python3
# Copyright (C) 2018 ASTRON (Netherlands Institute for Radio Astronomy)
# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
#
# This file is part of the LOFAR software suite.
# The LOFAR software suite is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# The LOFAR software suite is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
# $Id: $
# This test checks functionality of our swagger API
import unittest
import logging
logger = logging.getLogger('lofar.'+__name__)
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
from lofar.common.test_utils import exit_with_skipped_code_if_skip_integration_tests
exit_with_skipped_code_if_skip_integration_tests()
# Do Mandatory setup step:
# use setup/teardown magic for tmss test database, ldap server and django server
# (ignore pycharm unused import statement, python unittests does use at RunTime the tmss_test_environment_unittest_setup module)
from lofar.sas.tmss.test.tmss_test_environment_unittest_setup import *
from lofar.sas.tmss.test.tmss_test_data_django_models import *
from django.contrib.auth import get_user_model
User = get_user_model()
from django.test import TestCase
# import and setup test data creator
from lofar.sas.tmss.test.tmss_test_data_rest import TMSSRESTTestDataCreator
test_data_creator = TMSSRESTTestDataCreator(BASE_URL, AUTH)
class BasicSwaggerTestCase(TestCase):
"""
Test that the Swagger main page loads successfully.
"""
def test_generator_template_list_apiformat(self):
r = requests.get(BASE_URL + '/swagger/', auth=AUTH)
self.assertEqual(r.status_code, 200)
self.assertNotIn("Failed to load API definition", r.content.decode('utf8'))
self.assertNotIn("Fetch error", r.content.decode('utf8'))
self.assertIn("LOFAR Internal API", r.content.decode('utf8'))
if __name__ == "__main__":
unittest.main()
#!/bin/bash
# Run the unit test
source python-coverage.sh
python_coverage_test "*tmss*" t_swagger.py
#!/bin/sh
./runctest.sh t_swagger
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment