Skip to content
Snippets Groups Projects
Commit 72b9246d authored by Mattia Mancini's avatar Mattia Mancini
Browse files

SW-382: fix tests

parent a816b998
No related branches found
No related tags found
No related merge requests found
......@@ -62,7 +62,7 @@ def freeze_tbb(stations, dm, timesec, timensec):
# lcuhead to the stations and chain it into the command, so that we are not delayed by lcurun/ssh.
# wait for timestamp, then stop all boards on all stations.
timestamp = float("%s.%09d" % (timesec, timensec))
timestamp = float("%d.%09d" % (timesec, timensec))
if dm is not None:
timestamp += 0.32 * dm
......
......@@ -24,7 +24,7 @@ import unittest
import os
import logging
from lofar.triggerservices.trigger_service import TriggerHandler, ALERTHandler
from lofar.triggerservices.trigger_service import TriggerHandler, ALERTHandler, DEFAULT_TBB_PROJECT
import lofar.triggerservices.trigger_service as serv
from lofar.specificationservices.translation_service import SpecificationTranslationHandler
from lxml import etree
......@@ -124,12 +124,22 @@ class TestALERTHandler(unittest.TestCase):
logging.info('Setup test %s' % self._testMethodName)
def test_valid_voevent_should_invoke_tbb_dump(self):
with mock.patch('lofar.triggerservices.trigger_service.momqueryrpc') as momrpc, \
mock.patch('lofar.mac.tbbservice.client.tbbservice_rpc.TBBRPC.do_tbb_subband_dump') as dump, \
mock.patch('lofar.triggerservices.voevent_decider.ALERTDecider') as sciencecheck:
momrpc.allows_triggers.return_value = {'allows': True}
momrpc.get_trigger_quota.return_value = {'used_triggers': 4, 'allocated_triggers': 5}
with mock.patch('lofar.mac.tbbservice.client.tbbservice_rpc.TBBRPC.do_tbb_subband_dump') as dump, \
mock.patch('lofar.triggerservices.voevent_decider.ALERTDecider') as sciencecheck:
self.handler._cache.get_project_info = mock.MagicMock()
self.handler._cache.get_project_info.return_value = {'allow_triggers':True,
'num_used_triggers': 4,
'num_allowed_triggers': 5}
self.handler._cache.get_active_tasks = mock.MagicMock()
self.handler._cache.get_stations = mock.MagicMock()
self.handler._cache.get_stations.return_value = ['CS004C']
test_task = mock.MagicMock()
test_task.radb_task = dict(otdb_id=123456)
self.handler._cache.get_active_tasks.return_value = [test_task]
sciencecheck.is_acceptable.return_value = True
self.handler.handle_event(self.voevent_xml, self.voevent_etree)
dump.assert_called_once()
......@@ -140,7 +150,7 @@ class TestALERTHandler(unittest.TestCase):
with self.assertRaises(Exception) as err:
self.handler.handle_event(self.voevent_xml, self.voevent_etree)
self.assertTrue('exceeded' in str(err.exception))
self.assertTrue('pre-flight checks!' in str(err.exception))
def test_voevent_not_authorized_should_raise_exception(self):
with mock.patch('lofar.triggerservices.trigger_service.momqueryrpc') as momrpc:
......@@ -149,7 +159,7 @@ class TestALERTHandler(unittest.TestCase):
with self.assertRaises(Exception) as err:
self.handler.handle_event(self.voevent_xml, self.voevent_etree)
self.assertTrue('not allowed' in str(err.exception))
self.assertTrue('pre-flight checks!' in str(err.exception))
if __name__ == '__main__':
......
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