-
- import re
- import requests
- import json
-
- from docs_validation.helper_functions.helpers import get_datafile, \
- load_settings, \
- build_headers
- from docs_validation.scripts.setup.datafile import get_python_sample
-
-
- def test_fetching_datafile_via_cdn():
-
- headers = build_headers()
- settings = load_settings()
-
- url = f'https://cdn.abc.com/public/{settings["accountId"]}/s' \
- f'/{settings["project_id"]}_production.json'
-
- r = requests.get(url, headers=headers)
- assert r.status_code == 200
- cdn_datafile = r.text
- # TODO to add assertions once 400 error is fixed
-
-
- def test_fetching_datafile_via_rest_api():
-
- headers = build_headers()
- settings = load_settings()
-
- url = f'https://www.abc.com/experiment/v1/projects' \
- f'/{settings["project_id"]}/json'
-
- r = requests.get(url, headers=headers)
- assert r.status_code == 200
- rest_datafile = r.json()
-
- # convert dict-string to dict
- cdn_datafile = json.loads(get_datafile())
-
- # comparing dicts of datafiles
- assert rest_datafile == cdn_datafile
- assert rest_datafile['accountId']
- assert cdn_datafile['accountId']
-
-
- # =========================================================
- # BUILD_HEADRES FUNCTION IS IN A SEPARATE HELPER FILE:
- # =========================================================
- def build_headers():
- """Create heares for API requests."""
-
- settings = load_settings()
- _token = settings['token']
-
- headers = {
- 'user-agent': 'application/json',
- 'Authorization': 'Bearer ' + str(_token),
- }
-
- return headers
-