GithubHelp home page GithubHelp logo

Comments (8)

ezhov-evgeny avatar ezhov-evgeny commented on July 19, 2024 1

@Holt59 I have changed a way to support servers that do not support HEAD method, now in develop branch there are no requests in the constructor. Soon it will be released

from webdav-client-python-3.

evgeny-ezhov avatar evgeny-ezhov commented on July 19, 2024

Can you provide an example of dumbing URLs?
And why is it impossible to add dumb for method OPTIONS with return 200 and HEADER “Allow: HEAD”?

from webdav-client-python-3.

Holt59 avatar Holt59 commented on July 19, 2024

Any URL that does not exists, e.g.:

client = Client({
    "webdav_hostname": "https://webdav",
    "webdav_user": "user",
    "webdav_login": "login"
})

I have classes that have a _client member which is a Client object constructed during initialization, e.g.:

class A:
    def __init__(self, url):
        self._client = Client({"webdav_hostname": url})

Before this change, it was possible to perform unit-testing on class A using dumb URL because the Client constructor did not perform any operation:

def test_A_foo():
    a = A(url="https://webdav")
    assert a.foo() == 3

Now it is impossible because the A(...) initialization will fail, and setting-up a WebDAV client for unit-testing is kind of overkill, especially if I do not use it.

from webdav-client-python-3.

ezhov-evgeny avatar ezhov-evgeny commented on July 19, 2024

In your case, I can suggest trying to use patch from unittest.mock like:

@mock.patch("webdav3.client.Client")
def test_A_foo(mock_client):
    a = A(url="https://webdav")
    assert a.foo() == 3

It mocks the webdav3.client.Client in this method and put mock object as argument.
I think it solves your problem.

from webdav-client-python-3.

ezhov-evgeny avatar ezhov-evgeny commented on July 19, 2024

@Holt59 Is your problem resolved?

from webdav-client-python-3.

Holt59 avatar Holt59 commented on July 19, 2024

@ezhov-evgeny I'm sorry, I'm not using unittest but pytest and I did not have time to check if pytest offers something similar.

Currently, I've switched-back to the 0.13 version of the package.

But unit-testing aside, I think it would be a good thing to not perform a HTTP request in the Client constructor, or at least document it a bit more and allow to defer it.

from webdav-client-python-3.

ezhov-evgeny avatar ezhov-evgeny commented on July 19, 2024

For pytest I can suggest you https://github.com/pytest-dev/pytest-mock/

Actually now I think this request should be in the constructor but I'll think about it

from webdav-client-python-3.

ezhov-evgeny avatar ezhov-evgeny commented on July 19, 2024

@Holt59 Just released 3.14 try this version

from webdav-client-python-3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.