Esempio n. 1
0
    def test_send_on_valve_is_none(self):
        kwargs_1 = {'1': 1}
        kwargs_2 = {'2': 2}

        valve.unload_valve_function()
        valve.send(mock_signal, 'signal_1', **kwargs_1)
        valve.send(mock_signal, 'signal_1', **kwargs_2)
        self.assertEqual(mock_signal.signal_1.history[0], kwargs_1)
        self.assertEqual(mock_signal.signal_1.history[1], kwargs_2)

        mock_signal.clear()
Esempio n. 2
0
    def test_set_valve_function(self):
        self.assertRaises(Exception, valve.set_valve_function, args=[1])

        def func():
            return True

        valve.unload_valve_function()
        valve.set_valve_function(func)
        self.assertEqual(valve.valve_function(), func)
        self.assertRaises(Exception, valve.set_valve_function, args=[func])

        valve.__valve_function = None
Esempio n. 3
0
    def test_send_on_closed(self):
        kwargs_1 = {'1': 1}
        kwargs_2 = {'2': 2}

        def is_valve_closed():
            return True

        valve.unload_valve_function()
        valve.set_valve_function(is_valve_closed)
        valve.send(mock_signal, 'signal_1', **kwargs_1)
        valve.send(mock_signal, 'signal_1', **kwargs_2)
        self.assertEqual(len(mock_signal.signal_1.history), 0)

        mock_signal.clear()
        Signal.objects.all().delete()
Esempio n. 4
0
    def test_send_on_valve_opened(self):
        kwargs_1 = {'1': 1}
        kwargs_2 = {'2': 2}

        def is_valve_closed():
            return False

        valve.unload_valve_function()
        valve.set_valve_function(is_valve_closed)
        valve.send(mock_signal, 'signal_1', **kwargs_1)
        valve.send(mock_signal, 'signal_1', **kwargs_2)
        self.assertEqual(mock_signal.signal_1.history[0], kwargs_1)
        self.assertEqual(mock_signal.signal_1.history[1], kwargs_2)

        mock_signal.clear()
Esempio n. 5
0
    def test_open_valve(self):
        kwargs_1 = {'1': 1}
        kwargs_2 = {'2': 2}

        def valve_closed():
            return True

        valve.unload_valve_function()
        valve.set_valve_function(valve_closed)
        valve.send(mock_signal, 'signal_1', **kwargs_1)
        valve.send(mock_signal, 'signal_1', **kwargs_2)
        self.assertEqual(len(mock_signal.signal_1.history), 0)
        valve.open_valve(mock_signal)
        self.assertEqual(mock_signal.signal_1.history[0], kwargs_1)
        self.assertEqual(mock_signal.signal_1.history[1], kwargs_2)

        mock_signal.clear()
Esempio n. 6
0
 def setUp(self):
     valve.unload_valve_function()
Esempio n. 7
0
"""

import traceback

from django.test import TestCase

from pipeline.django_signal_valve import valve
from pipeline.engine import states, signals, exceptions
from pipeline.engine.models import Status
from pipeline.engine.utils import Stack
from pipeline.engine.models.core import PipelineProcess, ProcessSnapshot, SubProcessRelationship

from ..mock import *  # noqa
from pipeline.tests.mock_settings import *  # noqa

valve.unload_valve_function()


class TestPipelineProcess(TestCase):
    def test_prepare_for_pipeline(self):
        pipeline = PipelineObject()

        process = PipelineProcess.objects.prepare_for_pipeline(pipeline)
        self.assertEqual(len(process.id), 32)
        self.assertEqual(process.root_pipeline_id, pipeline.id)
        self.assertEqual(process.current_node_id, pipeline.start_event.id)
        self.assertIsNotNone(process.snapshot)
        self.assertEqual(process.top_pipeline.id, pipeline.id)

    def test_fork_child(self):
        context = MockContext()