def get_mocked_response(self): email_response = MockedResponse( 200, """{"elements": [{"handle": "urn:li:emailAddress:319371470", "handle~": {"emailAddress": "*****@*****.**"}}]}""" ) email_response.ok = True profile_response = MockedResponse( 200, """{ "profilePicture": { "displayImage": "urn:li:digitalmediaAsset:12345abcdefgh-12abcd" }, "id": "3735408165", "lastName": { "preferredLocale": { "language": "en", "country": "US" }, "localized": { "en_US": "Exampleton" } }, "firstName": { "preferredLocale": { "language": "en", "country": "US" }, "localized": { "en_US": "Larry" } } }""") profile_response.ok = True return [email_response, profile_response]
def get_mocked_response(self): return MockedResponse( 200, """ { "shop": { "id": "1234566", "name": "Test Shop", "email": "*****@*****.**" } } """, )
def get_mocked_response(self): return MockedResponse( 200, """ { "sub": "d8752092-0f2b-4b6e-86ef-6b72f2457a00", "emailVerified": true, "familyName": "Mckeeman", "phoneNumber": "+1 4156694355", "givenName": "Darren", "phoneNumberVerified": true, "email": "*****@*****.**"} """, )
def test_profile_invalid_response(self): data = { "error": { "code": "InvalidAuthenticationToken", "message": "Access token validation failure. Invalid audience.", } } response = MockedResponse(401, json.dumps(data)) with self.assertRaises(OAuth2Error): # no id, 4xx code, raises with message _check_errors(response)
def get_mocked_response(self): return MockedResponse( 200, """{ "Id": 123456, "FirstName": "John", "LastName": "Doe", "Email": "*****@*****.**", "DateOfBirth": "1986-02-01T00:00:00", "CoachedBy": 987654, "Weight": 87.5223617553711 }""", ) # noqa
def get_mocked_response(self): return MockedResponse( 200, """ { "CharacterID": 273042051, "CharacterName": "CCP illurkall", "ExpiresOn": "2014-05-23T15:01:15.182864Z", "Scopes": " ", "TokenType": "Character", "CharacterOwnerHash": "XM4D...FoY=" }""", )
def get_mocked_response(self): return MockedResponse(200, """ {"name":"pennersr","id":424732,"bio":"","follower_count":0, "angellist_url":"https://angel.co/dsxtst", "image":"https://angel.co/images/shared/nopic.png", "email":"*****@*****.**","blog_url":null, "online_bio_url":null,"twitter_url":"https://twitter.com/dsxtst", "facebook_url":null,"linkedin_url":null,"aboutme_url":null, "github_url":null,"dribbble_url":null,"behance_url":null, "what_ive_built":null,"locations":[],"roles":[],"skills":[], "investor":false,"scopes":["message","talent","dealflow","comment", "email"]} """)
def get_mocked_response(self): return MockedResponse( 200, """ { "email": "*****@*****.**", "eppn": "*****@*****.**", "firstname": "John", "lastname": "Doe", "idp_name": "Example University", "sub": "http://cilogon.org/serverA/users/1234567" }""", )
def get_mocked_response(self): return MockedResponse( 200, json.dumps( { "sub": "ZLARGMFT1M", "email": "*****@*****.**", "email_verified": True, "given_name": "Jane", "family_name": "Doe", } ), )
def test_account_tokens(self, multiple_login=False): if multiple_login: self.patches['requests'].get.side_effect = [ MockedResponse(200, self.response_data), MockedResponse(200, self.email_response_data), MockedResponse(200, self.response_data), MockedResponse(200, self.email_response_data), ] super(BitbucketOAuth2Tests, self).test_account_tokens(multiple_login) calls = [ mock.call('https://api.bitbucket.org/2.0/user', params=mock.ANY), mock.call('https://api.bitbucket.org/2.0/user/emails', params=mock.ANY), ] if multiple_login: calls.extend([ mock.call('https://api.bitbucket.org/2.0/user', params=mock.ANY), mock.call('https://api.bitbucket.org/2.0/user/emails', params=mock.ANY), ]) self.patches['requests'].get.assert_has_calls(calls)
def get_mocked_response(self, name='Raymond Penners', email="*****@*****.**"): return MockedResponse( 200, """ {"response": {"name": "%s", "avatar": { "permalink": "https://lh5.googleusercontent.com/photo.jpg" }, "email": "%s", "profileUrl": "https://plus.google.com/108204268033311374519", "id": "108204268033311374519" }} """ % (name, email))
def test_account_name_null(self): """String conversion when Gitea responds with empty username""" data = """{ "id": 4940, "login": "******", "username": null }""" self.login(MockedResponse(200, data)) socialaccount = SocialAccount.objects.get(uid="4940") self.assertIsNone(socialaccount.extra_data.get("name")) account = socialaccount.get_provider_account() self.assertIsNotNone(account.to_str()) self.assertEqual(account.to_str(), "giteauser")
def get_mocked_response(self): return MockedResponse(200, """ { "kind": "user", "name": "abc", "admin": false, "groups": [], "server": null, "pending": null, "created": "2016-12-06T18:30:50.297567Z", "last_activity": "2017-02-07T17:29:36.470236Z", "servers": null} """)
def test_account_invalid_response(self): body = ( "403 Forbidden - You (@domain.com) must accept the Terms of " "Service in order to perform this action. Please access GitLab " "from a web browser to accept these terms.") response = MockedResponse(403, body) # GitLab allow users to login with their API and provides # an error requiring the user to accept the Terms of Service. # see: https://gitlab.com/gitlab-org/gitlab-foss/-/issues/45849 with self.assertRaises(OAuth2Error): # no id, 4xx code, raises _check_errors(response)
def get_mocked_response(self): return MockedResponse( 200, """ { "identity_provider_display_name": "University of Gozorpazorp", "sub": "a6fc81e-4a6c1-97ac-b4c6-84ff6a8ce662", "preferred_username": "******", "identity_provider": "9a4c8312f-9432-9a7c-1654-6a987c6531fa", "organization": "University of Gozorpazorp", "email": "*****@*****.**", "name": "Morty Smith" } """)
def get_mocked_response(self): return MockedResponse( 200, """ { "id": 347514800, "properties": { "thumbnail_image": "http://mud-kage.kakao.co.kr/14/dn/btqfiLU5UyB/YVsnjWyjGbr63VEUnxJA40/o.jpg", "nickname": "\uc774\uc0c1\ud601", "profile_image": "http://mud-kage.kakao.co.kr/14/dn/btqficlJTd6/OORvqlHejQvk2l1wNZCC1k/o.jpg" } } """)
def get_mocked_response(self): return MockedResponse( 200, """ { "email": "*****@*****.**", "customer_id": "1234567", "firstname": "John", "developer": false, "lastname": "Doe", "allowedDownloads": ["FORC-FDEV-D-1010", "FORC-FDEV-D-1012", "COMBAT_TUTORIAL_DEMO", "FORC-FDEV-D-1013", "PUBLIC_TEST_SERVER", "FORC_FDEV_V_ADDER_LRPO", "FORC_FDEV_V_CHALLENGER_LRPO", "FORC_FDEV_V_CHIEFTAIN_LRPO", "FORC_FDEV_V_CRUSADER_LRPO", "FORC_FDEV_V_ANACONDA_LRPO", "FORC_FDEV_V_ASP_LRPO", "FORC_FDEV_V_ASP_SCOUT_LRPO", "FORC_FDEV_V_BELUGA_LRPO", "FORC_FDEV_V_COBRA_MKIII_LRPO", "FORC_FDEV_V_DIAMOND_EXPLORER_LRPO", "FORC_FDEV_V_COBRA_MKIV_LRPO", "FORC_FDEV_V_DIAMOND_SCOUT_LRPO", "FORC_FDEV_V_DOLPHIN_LRPO", "FORC_FDEV_V_EAGLE_LRPO", "FORC_FDEV_V_FEDERAL_ASSAULT_LRPO", "FORC_FDEV_V_FEDERAL_CORVETTE_LRPO", "FORC_FDEV_V_FEDDROP_LRPO", "FORC_FDEV_V_FEDERAL_FIGHTER_LRPO", "FORC_FDEV_V_FEDERAL_GUNSHIP_LRPO", "FORC_FDEV_V_FERDELANCE_LRPO", "FORC_FDEV_V_HAULER_LRPO", "FORC_FDEV_V_CLIPPER_LRPO", "FORC_FDEV_V_IMPERIAL_COURIER_LRPO", "FORC_FDEV_V_IMPERIAL_CUTTER_LRPO", "FORC_FDEV_V_IMPERIAL_EAGLE_LRPO", "FORC_FDEV_V_IMPERIAL_FIGHTER_LRPO", "FORC_FDEV_V_KEELBACK_LRPO", "FORC_FDEV_V_KRAIT_LRPO", "FORC_FDEV_V_KRAIT_LITE_LRPO", "FORC_FDEV_V_MAMBA_LRPO", "FORC_FDEV_V_ORCA_LRPO", "FORC_FDEV_V_PYTHON_LRPO", "FORC_FDEV_V_SIDEWINDER_LRPO", "FORC_FDEV_V_TAIPAN_LRPO", "FORC_FDEV_V_MAMMOTH_LRPO", "FORC_FDEV_V_TYPE6_LRPO", "FORC_FDEV_V_TYPE7_LRPO", "FORC_FDEV_V_TYPE9_LRPO", "FORC_FDEV_V_VIPER_MKIII_LRPO", "FORC_FDEV_V_VIPER_MKIV_LRPO", "FORC_FDEV_V_VULTURE_LRPO", "FORC-FDEV-D-1022", "FORC_FDEV_V_DECAL_1091", "FORC_FDEV_V_DECAL_1100", "FORC_FDEV_V_DECAL_1149", "FORC_FDEV_V_DECAL_1150", "FORC_FDEV_V_DECAL_1151", "FORC_FDEV_V_DECAL_1176", "FORC_FDEV_V_DECAL_1177", "FORC-FDEV-DO-1000", "FORC-FDEV-DO-1003", "FORC-FDEV-DO-1006", "PUBLIC_TEST_SERVER_OD"], "platform": "frontier" }""", )
def get_mocked_response(self): return MockedResponse( 200, """{ "data": { "relationships": { "pledges": { "data": [{ "type": "pledge", "id": "123456" }] } }, "attributes": { "last_name": "Interwebs", "is_suspended": false, "has_password": true, "full_name": "John Interwebs", "is_nuked": false, "first_name": "John", "social_connections": { "spotify": null, "discord": null, "twitter": null, "youtube": null, "facebook": null, "deviantart": null, "twitch": null }, "twitter": null, "is_email_verified": true, "facebook_id": null, "email": "*****@*****.**", "facebook": null, "thumb_url": "https://c8.patreon.com/100/123456", "vanity": null, "about": null, "is_deleted": false, "created": "2017-05-05T05:16:34+00:00", "url": "https://www.patreon.com/user?u=123456", "gender": 0, "youtube": null, "discord_id": null, "image_url": "https://c8.patreon.com/400/123456", "twitch": null }, "type": "user", "id": "123456" } }""", ) # noqa
def get_mocked_response(self): return MockedResponse( 200, """ { "email": "*****@*****.**", "firstname": "Test", "activated": true, "creationDate": "2014-04-17T17:04:01+02:00", "language": "en", "status": "ok", "offer": "25g", "lastname": "User" } """)
def get_mocked_response(self): # FIXME: Replace with actual/complete Bitbucket response return [ MockedResponse( 200, r""" [{"active": true, "email": "*****@*****.**", "primary": true}, {"active": true, "email": "*****@*****.**", "primary": false}, {"active": true, "email": "*****@*****.**", "primary": false}] """), MockedResponse( 200, r""" {"repositories": [], "user": {"avatar": "https://secure.gravatar.com/avatar.jpg", "display_name": "pennersr", "first_name": "", "is_team": false, "last_name": "", "resource_uri": "/1.0/users/pennersr", "username": "******"}} """) ] # noqa
def get_mocked_response(self, verified_email=True): return MockedResponse(200, """ {"response": [{"last_name": "Penners", "university_name": "", "photo": "http://vk.com/images/camera_c.gif", "sex": 2, "photo_medium": "http://vk.com/images/camera_b.gif", "relation": "0", "timezone": 1, "photo_big": "http://vk.com/images/camera_a.gif", "uid": 219004864, "universities": [], "city": "1430", "first_name": "Raymond", "faculty_name": "", "online": 1, "counters": {"videos": 0, "online_friends": 0, "notes": 0, "audios": 0, "photos": 0, "followers": 0, "groups": 0, "user_videos": 0, "albums": 0, "friends": 0}, "home_phone": "", "faculty": 0, "nickname": "", "screen_name": "id219004864", "has_mobile": 1, "country": "139", "university": 0, "graduation": 0, "activity": "", "last_seen": {"time": 1377805189}}]} """)
def get_mocked_response(self): return [ MockedResponse( 200, """<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <person> <id>oKmTqN2ffc</id> <first-name>R@ymØnd</first-name> <last-name>Pènnèrs</last-name> <email-address>[email protected]</email-address> <picture-url>http://m.c.lnkd.licdn.com/mpr/mprx/0_e0hbvSLc8QWo3ggPeVKqvaFR860d342Pogq4vakwx8IJOyR1XJrwRmr5mIx9C0DxWpGMsW9Lb8EQ</picture-url> <public-profile-url>http://www.linkedin.com/in/intenct</public-profile-url> </person> """) ]
def get_mocked_response(self): return MockedResponse( 200, """ { "picture": "https://secure.gravatar.com/avatar/123", "email": "*****@*****.**", "id": 2, "sub": 2, "identities": [], "name": "Mr Bob" } """, )
def test_account_name_null(self): """String conversion when GitHub responds with empty name""" data = """{ "type": "User", "id": 201022, "login": "******", "name": null }""" self.login(MockedResponse(200, data)) socialaccount = SocialAccount.objects.get(uid='201022') self.assertIsNone(socialaccount.extra_data.get('name')) account = socialaccount.get_provider_account() self.assertIsNotNone(account.to_str()) self.assertEqual(account.to_str(), 'pennersr')
def get_mocked_response(self): """Test authentication with an non-null image_id""" return MockedResponse(200, """{ "emails": { "email": "*****@*****.**", "verified": "True", "primary": "True" }, "id": "999999999", "name": "Andrew Godwin", "first_name": "Andrew", "last_name": "Godwin", "image_id": "99999999" }""")
def get_mocked_response(self): response_data = """ { "sub": "FSVIDUW3D7FSVIDUW3D72F2F", "name": "Jane Doe", "given_name": "Jane", "family_name": "Doe", "preferred_username": "******", "email": "*****@*****.**", "email_verified": true, "picture": "http://example.com/janedoe/me.jpg" } """ # noqa return MockedResponse(200, response_data)
def test_saves_email_as_verified_if_email_is_verified_in_cognito(self, ): mocked_claims = _get_mocked_claims() mocked_claims["email_verified"] = True mocked_payload = json.dumps(mocked_claims) mocked_response = MockedResponse(status_code=200, content=mocked_payload) self.login(mocked_response) user_id = SocialAccount.objects.get(uid=mocked_claims["sub"]).user_id email_address = EmailAddress.objects.get(user_id=user_id) self.assertEqual(email_address.email, mocked_claims["email"]) self.assertTrue(email_address.verified)
def get_mocked_response(self): return MockedResponse( 200, """ { "data": { "url": "https://www.pinterest.com/muravskiyyarosl/", "first_name": "Jane", "last_name": "Doe", "id": "351247977031674143" } } """, )
def get_mocked_response(self): return MockedResponse( 200, """ { "user_id": "https://www.paypal.com/webapps/auth/server/64ghr894040044", "name": "Jane Doe", "given_name": "Jane", "family_name": "Doe", "email": "*****@*****.**" } """, )
def get_mocked_response(self): # FIXME: Replace with actual/complete Twitter response return MockedResponse(200, r""" {"follow_request_sent": false, "profile_use_background_image": true, "id": 45671919, "verified": false, "profile_text_color": "333333", "profile_image_url_https": "https://pbs.twimg.com/profile_images/793142149/r_normal.png", "profile_sidebar_fill_color": "DDEEF6", "is_translator": false, "geo_enabled": false, "entities": {"description": {"urls": []}}, "followers_count": 43, "protected": false, "location": "The Netherlands", "default_profile_image": false, "id_str": "45671919", "status": {"contributors": null, "truncated": false, "text": "RT @denibertovic: Okay I'm definitely using django-allauth from now on. So easy to set up, far less time consuming, and it just works. #dja\u2026", "in_reply_to_status_id": null, "id": 400658301702381568, "favorite_count": 0, "source": "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>", "retweeted": true, "coordinates": null, "entities": {"symbols": [], "user_mentions": [{"indices": [3, 16], "screen_name": "denibertovic", "id": 23508244, "name": "Deni Bertovic", "id_str": "23508244"}], "hashtags": [{"indices": [135, 139], "text": "dja"}], "urls": []}, "in_reply_to_screen_name": null, "id_str": "400658301702381568", "retweet_count": 6, "in_reply_to_user_id": null, "favorited": false, "retweeted_status": {"lang": "en", "favorited": false, "in_reply_to_user_id": null, "contributors": null, "truncated": false, "text": "Okay I'm definitely using django-allauth from now on. So easy to set up, far less time consuming, and it just works. #django", "created_at": "Sun Jul 28 19:56:26 +0000 2013", "retweeted": true, "in_reply_to_status_id": null, "coordinates": null, "id": 361575897674956800, "entities": {"symbols": [], "user_mentions": [], "hashtags": [{"indices": [117, 124], "text": "django"}], "urls": []}, "in_reply_to_status_id_str": null, "in_reply_to_screen_name": null, "source": "web", "place": null, "retweet_count": 6, "geo": null, "in_reply_to_user_id_str": null, "favorite_count": 8, "id_str": "361575897674956800"}, "geo": null, "in_reply_to_user_id_str": null, "lang": "en", "created_at": "Wed Nov 13 16:15:57 +0000 2013", "in_reply_to_status_id_str": null, "place": null}, "utc_offset": 3600, "statuses_count": 39, "description": "", "friends_count": 83, "profile_link_color": "0084B4", "profile_image_url": "http://pbs.twimg.com/profile_images/793142149/r_normal.png", "notifications": false, "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png", "profile_background_color": "C0DEED", "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png", "name": "Raymond Penners", "lang": "nl", "profile_background_tile": false, "favourites_count": 0, "screen_name": "pennersr", "url": null, "created_at": "Mon Jun 08 21:10:45 +0000 2009", "contributors_enabled": false, "time_zone": "Amsterdam", "profile_sidebar_border_color": "C0DEED", "default_profile": true, "following": false, "listed_count": 1} """) # noqa