-
Jörn Künsemöller authoredJörn Künsemöller authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
t_lsmrapp_models.py 3.18 KiB
#!/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: $
import rest_framework.test
from lsmr.lsmrapp.models import GeneratorTemplate, RunTemplate, WorkRequestTemplate, WorkRelationTemplate
from django.utils import timezone # can't use datetime due to offset-awareness
client = rest_framework.test.APIClient()
class GeneratorTemplateTest(rest_framework.test.APITestCase):
# test data
test_data_1 = {"default_version": True,
"version": 'v0.314159265359',
"schema": '{"mykey": "my value"}',
"create_func": 'Funky'}
test_data_2 = {"default_version": False,
"version": 'v3.14159265359',
"schema": '{"mykey": "my other value"}',
"create_func": 'Trousers'}
def setUp(self):
pass
def test_GeneratorTemplate_gets_created_with_correct_creation_timestamp(self):
# setup
before = timezone.now()
entry = GeneratorTemplate.objects.create(**self.test_data_1)
entry.save()
after = timezone.now()
# assert
self.assertLess(before, entry.creation)
self.assertGreater(after, entry.creation)
def test_GET_GeneratorTemplate_list_view_shows_entry(self):
# setup
entry = GeneratorTemplate.objects.create(**self.test_data_1)
# assert
response = client.get('/generator_template/', format='json', follow=True)
self.assertEqual(response.status_code, 200)
for item in self.test_data_1.items(): # assertDictContainsSubset() is deprecated...
self.assertIn(item, response.data[0].items())
def test_GET_GeneratorTemplate_view_returns_correct_entry(self):
# setup
id1 = GeneratorTemplate.objects.create(**self.test_data_1).id
id2 = GeneratorTemplate.objects.create(**self.test_data_2).id
# assert
response1 = client.get('/generator_template/%s/' % id1, format='json', follow=True)
response2 = client.get('/generator_template/%s/' % id2, format='json', follow=True)
self.assertEqual(response1.status_code, 200)
self.assertEqual(response2.status_code, 200)
for item in self.test_data_1.items(): # assertDictContainsSubset() is deprecated...
self.assertIn(item, response1.data.items())
for item in self.test_data_2.items():
self.assertIn(item, response2.data.items())