Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking library #798

Open
CaptainDriftwood opened this issue Feb 3, 2023 · 2 comments
Open

Mocking library #798

CaptainDriftwood opened this issue Feb 3, 2023 · 2 comments

Comments

@CaptainDriftwood
Copy link

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
Copy link
Contributor

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
Copy link

salderma commented Mar 9, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants