コード例 #1
0
ファイル: tests.py プロジェクト: btbroot/exmo2010
 def mock_request(self, username, task):
     """
     Patch get_object_or_404 to return given task.
     Yield Mock request as context variable.
     """
     patch("scores.views.get_object_or_404", Mock(side_effect=lambda *a, **k: task)).start()
     yield Mock(user=self.users[username], method="GET", is_ajax=lambda: True, GET={"task_id": 1})
     patch.stopall()
コード例 #2
0
ファイル: terrain.py プロジェクト: bharatmooc/js-test-tool
def teardown_scenario(scenario):
    """
    Empty the temporary directory and restore the working directory.
    """
    # remove the scenario variables
    del world.scenario

    # Remove the fixtures directory
    shutil.rmtree(world.fixtures_dir)

    # Restore the current working directory
    os.chdir(world.old_cwd)

    # Uninstall all mocks
    patch.stopall()
コード例 #3
0
ファイル: patcher.py プロジェクト: Angakkuit/asiaq-aws
        def _patched(*args, **kwargs):
            try:
                for patch in patches:
                    mock = patch.start()
                    if isinstance(mock.kwargs_field, str):
                        kwargs[mock.kwargs_field] = mock

                # Merge additional fields into kwargs with kwargs taking precedence
                kwargs = dict(additional_fields.items() + kwargs.items())

                retval = func(*args, **kwargs)
            finally:
                Patch.stopall()

            return retval
コード例 #4
0
ファイル: rest_test.py プロジェクト: adjih/cli-tools
    def test__method(self):
        """ Test Api._method rest submission """
        ret = {'test': 'val'}
        ret_val = RequestRet(content=json_dumps(ret).encode('utf-8'),
                             status_code=200)
        post = patch('requests.post', return_value=ret_val).start()
        delete = patch('requests.delete', return_value=ret_val).start()
        get = patch('requests.get', return_value=ret_val).start()

        # pylint:disable=protected-access
        _auth = Mock()

        # call get
        ret = rest.Api._method(self._url)
        get.assert_called_with(self._url, auth=None)
        self.assertEquals(ret, ret)
        ret = rest.Api._method(self._url, method='GET', auth=_auth)
        get.assert_called_with(self._url, auth=_auth)
        self.assertEquals(ret, ret)

        # call delete
        ret = rest.Api._method(self._url, method='DELETE')
        delete.assert_called_with(self._url, auth=None)
        self.assertEquals(ret, ret)

        # call post
        ret = rest.Api._method(self._url, method='POST', data={})
        post.assert_called_with(
            self._url, data='{}'.encode('utf-8'),
            headers={'content-type': 'application/json'},
            auth=None)
        self.assertEquals(ret, ret)

        # call multipart
        _files = {'entry': '{}'}
        ret = rest.Api._method(self._url, method='MULTIPART', data=_files)
        post.assert_called_with(self._url, files=_files, auth=None)
        self.assertEquals(ret, ret)
        patch.stopall()
コード例 #5
0
ファイル: __init__.py プロジェクト: mathcamp/devbox
 def tearDown(self):
     super(FakeFSTest, self).tearDown()
     patch.stopall()
コード例 #6
0
ファイル: tests.py プロジェクト: globocom/iaas-usage
 def tearDown(self):
     cache.clear()
     patch.stopall()
コード例 #7
0
ファイル: test_auth.py プロジェクト: twu/pypicloud
 def tearDown(self):
     super(TestBasicAuthPolicy, self).tearDown()
     patch.stopall()
コード例 #8
0
 def tearDown(self):
     """
     Undo all patches.
     """
     patch.stopall()
コード例 #9
0
ファイル: test_auth.py プロジェクト: stevearc/pyramid_duh
 def tearDown(self):
     super(TestAuth, self).tearDown()
     patch.stopall()
コード例 #10
0
ファイル: test_base.py プロジェクト: openpermissions/koi
def teardown_module(module):
    """Stop patches and enable logging output"""
    patch.stopall()
    logging.disable(logging.NOTSET)
コード例 #11
0
ファイル: test_subprocess.py プロジェクト: rschuitema/sqatt
    def tearDown(self):
        """Tear down of test cases."""

        patch.stopall()
コード例 #12
0
 def tearDown(self):
     cache.clear()
     db.drop_all()
     patch.stopall()
コード例 #13
0
ファイル: auth_test.py プロジェクト: OlegHahm/cli-tools
 def tearDown(self):
     try:
         os.remove(TEST_RC_FILE)
     except OSError:
         pass
     patch.stopall()
コード例 #14
0
 def tearDown(self):
   patch.stopall()
   if path.exists(TEST_WORKSPACE):
     shutil.rmtree(TEST_WORKSPACE)
コード例 #15
0
ファイル: test_server.py プロジェクト: SpamExperts/spoon
 def tearDown(self):
     unittest.TestCase.tearDown(self)
     patch.stopall()
コード例 #16
0
 def kill_patches(
 ):  # Create a cleanup callback that undoes our patches
     patch.stopall()  # Stops all patches started with start()
     imp.reload(
         implement
     )  # Reload our UUT module which restores the original decorator
コード例 #17
0
def tearDownModule():
    patch.stopall()
コード例 #18
0
 def tearDown(self):
     super(TestGoogleCloudStorage, self).tearDown()
     patch.stopall()
コード例 #19
0
 def tearDown(self):
     db.drop_all()
     patch.stopall()
コード例 #20
0
 def tearDown(self):
     # to destroy patch of a structure
     patch.stopall()
コード例 #21
0
ファイル: test_dealer.py プロジェクト: nivbend/bdd_bot
    def teardown(self):
        super(BaseDealerTest, self).teardown()
        patch.stopall()

        # Reset dealer instance.
        self.dealer = None
コード例 #22
0
ファイル: test_storage.py プロジェクト: mathcamp/pypicloud
 def tearDown(self):
     super(TestGoogleCloudStorage, self).tearDown()
     patch.stopall()
コード例 #23
0
 def tearDown(self):
     patch.stopall()
     sys.stderr = sys.__stderr__
コード例 #24
0
 def tearDown(self):
     """
     Undo patches.
     """
     super(TestCoachDashboard, self).tearDown()
     patch.stopall()
コード例 #25
0
 def tearDown(self):
     self.client._connected = False
     self.client.destroy()
     patch.stopall()
コード例 #26
0
 def tearDown(self):
     """
     Undo all patches and reset the cwd
     """
     patch.stopall()
     os.chdir(self._old_cwd)
コード例 #27
0
 def kill_patches():
     patch.stopall()
     imp.reload(repository_module)
コード例 #28
0
ファイル: test_auth.py プロジェクト: philwhln/pypicloud
 def tearDown(self):
     super(TestBasicAuthPolicy, self).tearDown()
     patch.stopall()
コード例 #29
0
 def tearDownClass(cls):
     patch.stopall()
コード例 #30
0
def teardown_module():
    patch.stopall()
コード例 #31
0
ファイル: test_bb_reader.py プロジェクト: halm90/org-mgmt
 def tearDown(self):
     """
     Test teardowns: clean up test-wide patches.
     """
     patch.stopall()
コード例 #32
0
ファイル: test_views.py プロジェクト: rmoorman/edx-platform
 def tearDown(self):
     """
     Undo patches.
     """
     super(TestCoachDashboard, self).tearDown()
     patch.stopall()
コード例 #33
0
ファイル: test_app.py プロジェクト: maxpmaxp/decaptcher
def test_solve_captcha(app):

    m = 'controllers.solve'
    check_request = _patch("%s.check_request" % m)
    decaptcher_response = _patch("%s.decaptcher_response" % m)
    solvers = _patch("%s.solvers" % m)
    check_solver = _patch("%s.check_solver" % m)
    storage = _patch("%s.RedisStorage" % m)()

    solve = MagicMock()
    solvers.get_highest_notblocked.return_value.__getitem__.return_value\
            = solvers.get_by_name.return_value.__getitem__.return_value\
            = solvers.get_next.return_value.__getitem__.return_value\
            = solve

    pict = Upload('captcha.png', 'picture_binary_data')
    some_data = {'pict': pict}

    # моделирование запроса с невалидными POST-данными
    check_request.return_value = "error description"
    decaptcher_response.return_value = "error"
    app.post('/', some_data)
    #
    assert check_request.called
    assert decaptcher_response.called
    assert not solve.called
    reset_mocks(locals())

    # моделирование запроса с валидными POST-данными
    # без явного указания сервиса-расшифровщика
    check_request.return_value = None
    check_solver.side_effect = ["errcode", None]
    solve.side_effect = [SolverError, "captchacode1"]
    decaptcher_response.return_value = "resp1"
    app.post('/', some_data)
    #
    assert solvers.get_highest_notblocked.call_count == 2
    assert not solvers.get_by_name.called
    assert check_solver.call_count == 2
    assert storage.block.call_count == 1
    assert storage.incr_uses.call_count == 2
    assert solve.call_count == 2
    assert storage.incr_fails.call_count == 1
    assert solvers.get_next.call_count == 1
    assert decaptcher_response.called
    reset_mocks(locals())
    check_solver.side_effect = None

    # моделирование запроса с валидными POST-данными
    # с явным указанием сервиса-расшифровщика
    check_request.return_value = None
    decaptcher_response.return_value = "resp2"
    solve.side_effect = ["captchacode2"]
    app.post('/?upstream_service=captchabot', some_data)
    #
    assert solvers.get_by_name.called
    assert not solvers.get_highest_notblocked.called
    assert not check_solver.called
    assert storage.incr_uses.call_count == 1
    assert solve.call_count == 1
    assert not storage.incr_fails.called
    assert not solvers.get_next.called
    assert decaptcher_response.called
    reset_mocks(locals())
    check_solver.side_effect = None

    # моделирование случая, при котором число попыток
    # расшифровать капчу превышает допустимое
    check_request.return_value = None
    check_solver.return_value = None
    solve.side_effect = SolverError
    decaptcher_response.return_value = "resp1"
    app.post('/', some_data)
    #
    assert storage.incr_uses.call_count\
            == storage.incr_fails.call_count\
            == solve.call_count\
            == solvers.get_next.call_count\
            == settings.MAX_ATTEMPTS_TO_SOLVE
    assert decaptcher_response.called
    reset_mocks(locals())

    # проверяем, что параметры "pict_type" и "pict" передаются в расшифровщик
    some_data = {'pict': pict, 'pict_type': 'some_type'}
    check_request.return_value = None
    check_solver.return_value = None
    solve.side_effect = None
    decaptcher_response.return_value = "resp1"
    app.post('/', some_data)
    #
    assert solve.call_args[1]['pict_type'] == some_data['pict_type']
    reset_mocks(locals())

    patch.stopall()
コード例 #34
0
 def tearDown(self):
     patch.stopall()
     self.testbed.deactivate()
コード例 #35
0
 def tearDown(self):
     patch.stopall()
コード例 #36
0
ファイル: test_storage.py プロジェクト: philwhln/pypicloud
 def tearDown(self):
     super(TestS3Storage, self).tearDown()
     patch.stopall()
     self.s3_mock.stop()
コード例 #37
0
ファイル: test_storage.py プロジェクト: incrmntal/pypicloud
 def tearDown(self):
     super(TestGoogleCloudStorage, self).tearDown()
     patch.stopall()
     os.remove(self._config_file)
コード例 #38
0
ファイル: test_integration.py プロジェクト: Shoobx/diff-cover
 def tearDown(self):
     """
     Undo all patches and reset the cwd
     """
     patch.stopall()
     os.chdir(self._old_cwd)
コード例 #39
0
ファイル: test_utils.py プロジェクト: sbilac/incubator-beam
 def remove_patches():
     patch.stopall()
     # Reload module again after removing patch.
     imp.reload(module)
コード例 #40
0
 def tearDown(self):
     HelperMixin.tearDown(self)
     patch.stopall()
     shutil.rmtree(self.symbol_dir)
コード例 #41
0
ファイル: controller_test.py プロジェクト: deepOak/churada
 def tearDown(self):
     patch.stopall()
     self.controller = None
コード例 #42
0
ファイル: test_storage.py プロジェクト: incrmntal/pypicloud
 def tearDown(self):
     super(TestS3Storage, self).tearDown()
     patch.stopall()
     self.s3_mock.stop()
コード例 #43
0
def api_mock_stop():
    """ Stop all patches started by api_mock.
    Actually it stops everything but not a problem """
    patch.stopall()
コード例 #44
0
ファイル: test_api.py プロジェクト: drtyhbo/rockstor-core
 def tearDownClass(cls):
     patch.stopall()
コード例 #45
0
 def tearDown(self):
     api_mock_stop()
     patch.stopall()
コード例 #46
0
 def tearDown(self):
     """
     Undo all patches.
     """
     patch.stopall()
コード例 #47
0
 def tearDown(self):
     os.remove(self.node.TTY)
     patch.stopall()
コード例 #48
0
 def tearDown(self):
     patch.stopall()
     sys.stderr = sys.__stderr__
コード例 #49
0
ファイル: test_utils.py プロジェクト: lukecwik/incubator-beam
 def remove_patches():
   patch.stopall()
   # Reload module again after removing patch.
   imp.reload(module)
コード例 #50
0
ファイル: tests.py プロジェクト: globocom/iaas-usage
 def tearDown(self):
     db.drop_all()
     patch.stopall()
コード例 #51
0
def tearDownModule():
    patch.stopall()
コード例 #52
0
ファイル: unit-symbolstore.py プロジェクト: MekliCZ/positron
 def tearDown(self):
     HelperMixin.tearDown(self)
     patch.stopall()
     shutil.rmtree(self.symbol_dir)
コード例 #53
0
 def tearDown(self):
     super(TestBaseBackend, self).tearDown()
     patch.stopall()
コード例 #54
0
 def tearDown(self):
     self.smtp_server_thread.stop()
     patch.stopall()
コード例 #55
0
 def tearDown(self) -> None:
     patch.stopall()
コード例 #56
0
ファイル: local_torrent_test.py プロジェクト: deepOak/churada
 def tearDown(self):
     patch.stopall()
コード例 #57
0
ファイル: test_auth.py プロジェクト: twu/pypicloud
 def tearDown(self):
     super().tearDown()
     patch.stopall()