from unittest.mock import patch, PropertyMock

import pytest

from dockci.api.job import filter_jobs_by_request

class TestFilterJobsByRequest(object):
    """ Test the ``filter_jobs_by_request`` function """
    @pytest.mark.parametrize('mock_values,expected_kwargs', [
        ({'versioned': ''}, {'versioned': True}),
        ({'versioned': 'y'}, {'versioned': True}),
        ({'versioned': 'no'}, {'versioned': False}),
        ({'completed': ''}, {'completed': True}),
        ({'passed': ''}, {'passed': True}),
        ({'branch': 'abc'}, {'branch': 'abc'}),
        (
            {'branch': 'abc', 'versioned': 'y'},
            {'branch': 'abc', 'versioned': True},
        ),
    ])
    def test_filter_kwargs(self, mocker, mock_values, expected_kwargs):
        """ Ensure that the correct kwargs are passed to ``filtered_jobs`` """

        class MockProject(object):
            filtered_jobs_called = False
            def filtered_jobs(self, **kwargs):
                self.filtered_jobs_called = True
                assert kwargs == expected_kwargs
                return 'test val'

        import flask
        mocker.patch.object(flask.request, 'values', new=mock_values)
        mock_project = MockProject()

        assert filter_jobs_by_request(mock_project) == 'test val'
        assert mock_project.filtered_jobs_called

@@ -106,16 +106,397 @@
 equest%0A%0A
+from contextlib import contextmanager%0Aimport flask%0A%0A@contextmanager%0Adef request_values(values):%0A    %22%22%22%0A    Mock request values. Python mocks isn't used because it attempts to delete%0A    things, and we get an exception%0A    %22%22%22%0A    old_values = flask.request.values%0A    flask.request.values = values%0A%0A    try:%0A        yield%0A%0A    finally:%0A        flask.request.values = old_values%0A%0A%0A
 class Te
@@ -1104,16 +1104,8 @@
 elf,
- mocker,
  moc
@@ -1480,78 +1480,28 @@
     
-import flask%0A        mocker.patch.object(flask.
+with 
 request
-, '
+_
 values
-', new=
+(
 mock
@@ -1508,17 +1508,22 @@
 _values)
-%0A
+:%0A    
         
@@ -1552,16 +1552,20 @@
 ject()%0A%0A
+    
         
@@ -1622,16 +1622,20 @@
 st val'%0A
+    
         

Fix tests