Signing back into the Community for the first time? You'll need to reset your password to access your account. Find out more.
Forum Discussion
Former Member
4 years ago[25] Testing ?
I was wondering how you would recommend testing our scripts that make use of the CLI ?
There is for instance the --dry-run
option, but do you use other means on your side ?
For instance, would you have some "mock modes" where you would not make any query to the server (and therefore do not need any authentication)
1Password Version: 7.9.2
Extension Version: 2.0.0-beta.7
OS Version: macOS 11.6
- Former Member
Hey @ebreton
Do you find the new
--dry-run
option inop item create/edit
helpful for testing? Keep in mind that authentication is still required to use the--dry-run
option.Given your feedback, I'm also thinking that mock modes for create and edit commands that validate the input could be quite useful.
While we don't have official testing guides, I do my fair share of testing on
op
as a developer.My general approach is to have a Test vault, and create items just for testing. Once my testing is done, I usually clean up the test item(s).
To speed things up, I have a few templates of some of the more common item categories as well
Appreciate your input!
- Former Member
To be honest, I have not used
--dry-run
so much. I am playing around with test vault / items as you do, in order to check both the general behaviour and specific cases.I have now reached a point where I am writing unittests for my code and I was looking for mocking the
op
part. Firstofall because I am not really interested into testing theop
inside (that's for you folks ;) ) and more important because I do not want the test to require my input to authenticate.Ideally, I would have something similar as
requests-mock
which is available for the popular python librequests
. You write code such as the following:
def my_test():
with requests_mock.Mocker() as mocker:
# mock the authentication request
mocker.post(
sender.authentication_url,
json={'access_token': 'test-token'},
status_code=200,
)
# mock a post request that will be performed by my code
mocker.post(sender.post_url, status_code=200)
# test my stuff
...
- Former Member
Ah, I see you meant for programatic testing.
I am not at all familiar with the Python testing paradigms, but in the languages that I am familiar with (Go, Java, C++) I would encapsulate all the
op
interactions into a module/class/package, and replace it with a mock. - Former Member
Yes, that would definitively work, and I would need to override all op commands with mocked response.
Actually, I just wanted to check if there was already something to simplify the work ;)
Thanks for digging out my question ^^