spacepaste

  1.  
  2. import re
  3. import requests
  4. import json
  5. from docs_validation.helper_functions.helpers import get_datafile, \
  6. load_settings, \
  7. build_headers
  8. from docs_validation.scripts.setup.datafile import get_python_sample
  9. def test_fetching_datafile_via_cdn():
  10. headers = build_headers()
  11. settings = load_settings()
  12. url = f'https://cdn.abc.com/public/{settings["accountId"]}/s' \
  13. f'/{settings["project_id"]}_production.json'
  14. r = requests.get(url, headers=headers)
  15. assert r.status_code == 200
  16. cdn_datafile = r.text
  17. # TODO to add assertions once 400 error is fixed
  18. def test_fetching_datafile_via_rest_api():
  19. headers = build_headers()
  20. settings = load_settings()
  21. url = f'https://www.abc.com/experiment/v1/projects' \
  22. f'/{settings["project_id"]}/json'
  23. r = requests.get(url, headers=headers)
  24. assert r.status_code == 200
  25. rest_datafile = r.json()
  26. # convert dict-string to dict
  27. cdn_datafile = json.loads(get_datafile())
  28. # comparing dicts of datafiles
  29. assert rest_datafile == cdn_datafile
  30. assert rest_datafile['accountId']
  31. assert cdn_datafile['accountId']
  32. # =========================================================
  33. # BUILD_HEADRES FUNCTION IS IN A SEPARATE HELPER FILE:
  34. # =========================================================
  35. def build_headers():
  36. """Create heares for API requests."""
  37. settings = load_settings()
  38. _token = settings['token']
  39. headers = {
  40. 'user-agent': 'application/json',
  41. 'Authorization': 'Bearer ' + str(_token),
  42. }
  43. return headers
  44.