Skip to content

Instantly share code, notes, and snippets.

@blaix
Last active February 23, 2016 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blaix/f5e2834f5f4d01111110 to your computer and use it in GitHub Desktop.
Save blaix/f5e2834f5f4d01111110 to your computer and use it in GitHub Desktop.
def validate_token(secret, auth_token):
# do the token check logic... (using settings.PARTNER_ID)
def validate_token_from_yola(auth_token):
yola = Yola()
partner = yola.get_partner(settings.PARTNER_ID)
validate_token(partner['shared_secret_key'], auth_token)
@blaix
Copy link
Author

blaix commented Feb 23, 2016

I guess I psyched myself out with how much set up the auth test was having to do for what is basically a ==

That's a good instinct. If you have places where collaboration and business logic mix, your tests are probably ugly, and a better design is probably hiding. In this gist I split that logic up:

validate_token is now all about the logic. So the tests can just pass in dicts and assert agains the == check.

validate_token_for_yola_user is now all about collaboration. This is where mocks should be used. The tests should mock Yola and validate_token and assert get_user and get_partner and validate_token are called correctly.

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