def moves_auth(): httpretty.enable() def _method(method): return {"GET": httpretty.GET, "POST": httpretty.POST}[method] strategy = DjangoStrategy(MovesOAuth2, DjangoStorage) start_url = strategy.start().url target_url = handle_state(MovesOAuth2, start_url, strategy.build_absolute_uri("/complete/{0}/?code=foobar")) httpretty.register_uri(httpretty.GET, start_url, status=301, location=target_url) httpretty.register_uri(httpretty.GET, target_url, status=200, body="foobar") httpretty.register_uri( _method(MovesOAuth2.ACCESS_TOKEN_METHOD), uri=MovesOAuth2.ACCESS_TOKEN_URL, status=200, body=json.dumps({"access_token": "foobar", "token_type": "bearer"}), content_type="text/json", ) user_data_url = "https://api.moves-app.com.com/oauth2/v1/user/profile" if user_data_url: httpretty.register_uri( httpretty.GET, user_data_url, body=json.dumps({"userId": "1010101010011"}), content_type="application/json" ) yield httpretty.disable() httpretty.reset()
def google_auth(): # TODO: This could be abstracted for twitter and facebook too. httpretty.enable() def _method(method): return {"GET": httpretty.GET, "POST": httpretty.POST}[method] strategy = DjangoStrategy(GoogleOAuth2, DjangoStorage) start_url = strategy.start().url target_url = handle_state(GoogleOAuth2, start_url, strategy.build_absolute_uri("/complete/{0}/?code=foobar")) httpretty.register_uri(httpretty.GET, start_url, status=301, location=target_url) httpretty.register_uri(httpretty.GET, target_url, status=200, body="foobar") httpretty.register_uri( _method(GoogleOAuth2.ACCESS_TOKEN_METHOD), uri=GoogleOAuth2.ACCESS_TOKEN_URL, status=200, body=json.dumps({"access_token": "foobar", "token_type": "bearer"}), content_type="text/json", ) user_data_url = "https://www.googleapis.com/oauth2/v1/userinfo" if user_data_url: httpretty.register_uri( httpretty.GET, user_data_url, body=json.dumps({"email": "*****@*****.**", "id": "101010101010101010101"}), content_type="application/json", ) yield httpretty.disable() httpretty.reset()