def mock_factory(): obj = ConditionFactory() obj._map = { 'type_1': mock.MagicMock(return_value=mock.sentinel.type_1), 'type_2': mock.MagicMock(return_value=mock.sentinel.type_2), 'type_3': mock.MagicMock(return_value=mock.sentinel.type_3), } return obj
def test_can_configure_conditions_from_dictionary(self, monkeypatch): mock_fact = ConditionFactory() mock_fact.create_condition = mock.MagicMock(return_value=mock.sentinel.condition) monkeypatch.setattr('sensormesh.endpoints.ConditionFactory', mock.MagicMock(return_value=mock_fact)) o = DataEndpoint(when={'type_1': 2, 'type_2': [2, 3, 4]}) mock_fact.create_condition.assert_has_calls( [mock.call('type_1', 2), mock.call('type_2', [2, 3, 4])], any_order=True) assert o._conditions == [mock.sentinel.condition, mock.sentinel.condition]