|
168 | 168 | "from users import UserHelper\n", |
169 | 169 | "from authfactory import AuthFactory\n", |
170 | 170 | "\n", |
171 | | - "tests = ApimTesting(\"OAuth 3rd Party (Spotify) Sample Tests\")\n", |
| 171 | + "tests = ApimTesting(\"OAuth 3rd Party (Spotify) Sample Tests\", sample_folder, deployment)\n", |
172 | 172 | "\n", |
173 | 173 | "# 1) Marketing Member Role\n", |
174 | 174 | "# Create a JSON Web Token with a payload and sign it with the symmetric key from above.\n", |
175 | 175 | "encoded_jwt_token_marketing_member = AuthFactory.create_symmetric_jwt_token_for_user(UserHelper.get_user_by_role(Role.MARKETING_MEMBER), nb_helper.jwt_key_value)\n", |
176 | 176 | "print(f'\\nJWT token for Marketing Member:\\n{encoded_jwt_token_marketing_member}') # this value is used to call the APIs via APIM\n", |
177 | 177 | "\n", |
178 | | - "# 2) Issue a direct request to API Management\n", |
179 | | - "artist_id = '6XpaIBNiVzIetEPCWDvAFP' # Whitney Houston's Spotify Artist ID\n", |
180 | | - "reqsApim = ApimRequests(apim_gateway_url)\n", |
181 | | - "reqsApim.headers['Authorization'] = f'Bearer {encoded_jwt_token_marketing_member}'\n", |
182 | | - "\n", |
183 | | - "output = reqsApim.singleGet(f'/oauth-3rd-party-spotify/artists/{artist_id}', msg = 'Calling the Spotify Artist API via API Management Gateway URL. Response codes 200 and 403 are both valid depending on the infrastructure used.')\n", |
184 | | - "artist = json.loads(output)\n", |
185 | | - "tests.verify(artist['name'], 'Whitney Houston')\n", |
186 | | - "utils.print_info(f'{artist[\"name\"]} has a popularity rating of {artist[\"popularity\"]} with {artist[\"followers\"][\"total\"]:,} followers on Spotify.')\n", |
187 | | - "\n", |
188 | | - "# 2) Issue requests against Front Door.\n", |
189 | | - "# Check if the infrastructure architecture deployment uses Azure Front Door.\n", |
| 178 | + "# Issue requests against Front Door.\n", |
190 | 179 | "utils.print_message('Checking if the infrastructure architecture deployment uses Azure Front Door.', blank_above = True)\n", |
191 | 180 | "afd_endpoint_url = utils.get_frontdoor_url(deployment, rg_name)\n", |
192 | 181 | "\n", |
193 | 182 | "if afd_endpoint_url:\n", |
194 | | - " artist_id = '2VSHKHBTiXWplO8lxcnUC9' # Taylor Swift's Spotify Artist ID\n", |
| 183 | + " artist_id = '06HL4z0CvFAxyc27GXpf02' # Taylor Swift's Spotify Artist ID\n", |
195 | 184 | " reqsAfd = ApimRequests(afd_endpoint_url)\n", |
196 | 185 | " reqsAfd.headers['Authorization'] = f'Bearer {encoded_jwt_token_marketing_member}'\n", |
197 | | - " output = reqsAfd.singleGet(f'/oauth-3rd-party-spotify/artists/{artist_id}', msg = 'Calling the Spotify Artist API via API Management Gateway URL. Response codes 200 and 403 are both valid depending on the infrastructure used.')\n", |
| 186 | + " output = reqsAfd.singleGet(f'/oauth-3rd-party-spotify/artists/{artist_id}', msg = 'Calling the Spotify Artist API via API Management Gateway URL.')\n", |
| 187 | + " artist = json.loads(output)\n", |
| 188 | + " tests.verify(artist['name'], 'Taylor Swift')\n", |
| 189 | + " utils.print_info(f'{artist[\"name\"]} has a popularity rating of {artist[\"popularity\"]} with {artist[\"followers\"][\"total\"]:,} followers on Spotify.')\n", |
| 190 | + "else:\n", |
| 191 | + " # Issue a direct request to API Management\n", |
| 192 | + " artist_id = '6XpaIBNiVzIetEPCWDvAFP' # Whitney Houston's Spotify Artist ID\n", |
| 193 | + " reqsApim = ApimRequests(apim_gateway_url)\n", |
| 194 | + " reqsApim.headers['Authorization'] = f'Bearer {encoded_jwt_token_marketing_member}'\n", |
| 195 | + " output = reqsApim.singleGet(f'/oauth-3rd-party-spotify/artists/{artist_id}', msg = 'Calling the Spotify Artist API via API Management Gateway URL.')\n", |
198 | 196 | " artist = json.loads(output)\n", |
199 | 197 | " tests.verify(artist['name'], 'Whitney Houston')\n", |
200 | 198 | " utils.print_info(f'{artist[\"name\"]} has a popularity rating of {artist[\"popularity\"]} with {artist[\"followers\"][\"total\"]:,} followers on Spotify.')\n", |
|
0 commit comments