box / box-python-sdk

Box SDK for Python
http://opensource.box.com/box-python-sdk/
Apache License 2.0
419 stars 215 forks source link

Mocking library #798

Open CaptainDriftwood opened 1 year ago

CaptainDriftwood commented 1 year ago

Is your feature request related to a problem? Please describe.

Will a library ever be implemented, similar to Moto for aws boto3 that developers can use to mock out the box-sdk for unit testing purposes?

Describe the solution you'd like

The ability to create a fake box environment that the box sdk can interact with in Python. I'd like to be able to create metadata templates, folder structures, files with metadata attached, etc.

Describe alternatives you've considered

The only alternative is having to mock out each individual http request and response for the box sdk after recording them via a tool like vcrpy

lukaszsocha2 commented 1 year ago

Hi @Jasonca2, currently we don't have any plans to implement box SDK mock available for testing. I'll bring this topic as an idea for an improvement to discuss during next team planning. In Python SDK test.unit folder we have many mock fixtures and maybe some of them could be reused in your project. Best, @lukaszsocha2

salderma commented 1 year ago

I'd like to throw my support behind @Jasonca2 's request. I've just started my first project with boxsdk and would love to have an easier means to test my code that wraps the boxsdk with out having to mock everyhing I'm using in the SDK...which is something of a struggle, even with the examples in this repo's test folder.

Supposing I wrote a python script to perform this example task from the SDK Doc Site https://developer.box.com/guides/authentication/tokens/sdks/ -

from boxsdk import Client, OAuth2

oauth = OAuth2(
    client_id='YOUR_CLIENT_ID',
    client_secret='YOUR_CLIENT_SECRET',
    access_token='ACCESS_TOKEN',
    refresh_token='REFRESH_TOKEN',
)

client = Client(oauth)

user = client.user().get()
print(f'User ID is {user.id}')

To run pytest or mock assertions on this, with fake data for client_id, client_secret, etc. I'd have to mock the OAuth2, Client, and Client.user().get() objects, and set tghe value of the user's ID and make an assertion against the returned ID.