コード例 #1
0
    def test_MessagingUtils_no_data(self):
        reduction_run = getReductionRun()

        with self.assertRaises(Exception) as e:
            MessagingUtils().send_pending(reduction_run)

        self.assertEqual(e.exception.message, "No data path found for reduction run", "Expecting exception to be raised")
コード例 #2
0
    def test_MessagingUtils_cancel(self):
        reduction_run = getReductionRun()

        data_location = DataLocation(file_path="/test/data/path", reduction_run=reduction_run)
        data_location.save()
        reduction_run.data_location.add(data_location)
        reduction_run.save()

        send_called = [False]

        parent = self

        class mock_client(object):
            def __init__(self, brokers, user, password, topics=None, consumer_name='QueueProcessor', client_only=True, use_ssl=ACTIVEMQ['SSL'], ssl_version=3):  pass
            def connect(self): pass
            def stop(self): pass

            def send(self, destination, message, persistent='true', priority=4, delay=None):
                send_called[0] = True
                data_dict = json.loads(message)
                parent.assertTrue('cancel' in data_dict, "Expecting 'cancel' in message")
                parent.assertEqual(data_dict['cancel'], True, "Expecting 'cancel' to be true")

        with patch('autoreduce_webapp.queue_processor.Client', mock_client):
            MessagingUtils().send_cancel(reduction_run)

        self.assertTrue(send_called[0], "Expecting send to be called")
コード例 #3
0
    def test_get_script_and_arguments_successful(self):
        run_variables = []

        reduction_run = getReductionRun()
        reduction_run.script = getValidScript("reduce.py")

        variable = RunVariable(
            reduction_run=reduction_run, name="test", value="testvalue1", type="text", is_advanced=False
        )
        variable.save()
        run_variables.append(variable)
        variable = RunVariable(
            reduction_run=reduction_run, name="advanced_test", value="testvalue2", type="text", is_advanced=True
        )
        variable.save()
        run_variables.append(variable)

        script, arguments = ReductionRunUtils().get_script_and_arguments(reduction_run)

        self.assertNotEqual(script, None, "Expecting to get a script path back.")
        self.assertNotEqual(script, "", "Expecting to get a script path back.")
        self.assertNotEqual(arguments, None, "Expecting to get some arguments path back.")
        self.assertNotEqual(arguments, {}, "Expecting to get some arguments path back.")
        self.assertTrue("standard_vars" in arguments, "Expecting arguments to have a 'standard_vars' key.")
        self.assertTrue("advanced_vars" in arguments, "Expecting arguments to have a 'advanced_vars' key.")
        self.assertEqual(
            arguments["standard_vars"]["test"], "testvalue1", "Expecting to find testvalue1 in standard_vars."
        )
        self.assertEqual(
            arguments["advanced_vars"]["advanced_test"], "testvalue2", "Expecting to find testvalue2 in advanced_vars."
        )
コード例 #4
0
    def test_get_script_and_arguments_successful(self):
        run_variables = []

        reduction_run = getReductionRun()
        reduction_run.script = getValidScript("reduce.py")

        variable = RunVariable(reduction_run=reduction_run,
                               name='test',
                               value='testvalue1',
                               type='text',
                               is_advanced=False)
        variable.save()
        run_variables.append(variable)
        variable = RunVariable(reduction_run=reduction_run,
                               name='advanced_test',
                               value='testvalue2',
                               type='text',
                               is_advanced=True)
        variable.save()
        run_variables.append(variable)

        script, arguments = ReductionRunUtils().get_script_and_arguments(
            reduction_run)

        self.assertNotEqual(script, None,
                            "Expecting to get a script path back.")
        self.assertNotEqual(script, "", "Expecting to get a script path back.")
        self.assertNotEqual(arguments, None,
                            "Expecting to get some arguments path back.")
        self.assertNotEqual(arguments, {},
                            "Expecting to get some arguments path back.")
        self.assertTrue('standard_vars' in arguments,
                        "Expecting arguments to have a 'standard_vars' key.")
        self.assertTrue('advanced_vars' in arguments,
                        "Expecting arguments to have a 'advanced_vars' key.")
        self.assertEqual(arguments['standard_vars']['test'], 'testvalue1',
                         "Expecting to find testvalue1 in standard_vars.")
        self.assertEqual(arguments['advanced_vars']['advanced_test'],
                         'testvalue2',
                         "Expecting to find testvalue2 in advanced_vars.")
コード例 #5
0
    def test_MessagingUtils_successful(self):
        reduction_run = getReductionRun()

        data_location = DataLocation(file_path="/test/data/path", reduction_run=reduction_run)
        data_location.save()
        reduction_run.data_location.add(data_location)
        reduction_run.save()

        send_called = [False]

        parent = self

        class mock_client(object):
            def __init__(self, brokers, user, password, topics=None, consumer_name='QueueProcessor', client_only=True, use_ssl=ACTIVEMQ['SSL'], ssl_version=3):
                pass

            def connect(self):
                pass
                
            def stop(self):
                pass

            def send(self, destination, message, persistent='true', priority=4, delay=None):
                send_called[0] = True
                data_dict = json.loads(message)
                parent.assertEqual(destination, '/queue/ReductionPending', "Expecting the destination to be '/queue/ReductionPending' but was '%s'." % destination)
                parent.assertEqual(data_dict['data'], '/test/data/path', "Expecting the data path to be '/test/data/path' but was '%s'." % data_dict['data'])
                parent.assertEqual(data_dict['run_number'], reduction_run.run_number, "Expecting the run number to be '%s' but was '%s'." % (reduction_run.run_number, data_dict['run_number']))
                parent.assertEqual(data_dict['run_version'], reduction_run.run_version, "Expecting the run version to be '%s' but was '%s'." % (reduction_run.run_version, data_dict['run_version']))
                parent.assertEqual(data_dict['instrument'], reduction_run.instrument.name, "Expecting the run number to be '%s' but was '%s'." % (reduction_run.instrument.name, data_dict['instrument']))
                parent.assertNotEqual(data_dict['reduction_arguments'], None, "Expecting to find some arguments")
                parent.assertNotEqual(data_dict['reduction_arguments'], {}, "Expecting to find some arguments")
                parent.assertTrue('standard_vars' in data_dict['reduction_arguments'], "Expecting to find some standard_vars.")
                parent.assertTrue('advanced_vars' in data_dict['reduction_arguments'], "Expecting to find some advanced_vars.")

        with patch('autoreduce_webapp.queue_processor.Client', mock_client):
            MessagingUtils().send_pending(reduction_run)

        self.assertTrue(send_called[0], "Expecting send to be called")