builddiscover.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python
  2. import os.path
  3. import urlparse
  4. from openid.test import discoverdata
  5. manifest_header = """\
  6. # This file contains test cases for doing YADIS identity URL and
  7. # service discovery. For each case, there are three URLs. The first
  8. # URL is the user input. The second is the identity URL and the third
  9. # is the URL from which the XRDS document should be read.
  10. #
  11. # The file format is as follows:
  12. # User URL <tab> Identity URL <tab> XRDS URL <newline>
  13. #
  14. # blank lines and lines starting with # should be ignored.
  15. #
  16. # To use this test:
  17. #
  18. # 1. Run your discovery routine on the User URL.
  19. #
  20. # 2. Compare the identity URL returned by the discovery routine to the
  21. # identity URL on that line of the file. It must be an EXACT match.
  22. #
  23. # 3. Do a regular HTTP GET on the XRDS URL. Compare the content that
  24. # was returned by your discovery routine with the content returned
  25. # from that URL. It should also be an exact match.
  26. """
  27. def buildDiscover(base_url, out_dir):
  28. """Convert all files in a directory to apache mod_asis files in
  29. another directory."""
  30. test_data = discoverdata.readTests(discoverdata.default_test_file)
  31. def writeTestFile(test_name):
  32. template = test_data[test_name]
  33. data = discoverdata.fillTemplate(
  34. test_name, template, base_url, discoverdata.example_xrds)
  35. out_file_name = os.path.join(out_dir, test_name)
  36. out_file = file(out_file_name, 'w')
  37. out_file.write(data)
  38. manifest = [manifest_header]
  39. for success, input_name, id_name, result_name in discoverdata.testlist:
  40. if not success:
  41. continue
  42. writeTestFile(input_name)
  43. input_url = urlparse.urljoin(base_url, input_name)
  44. id_url = urlparse.urljoin(base_url, id_name)
  45. result_url = urlparse.urljoin(base_url, result_name)
  46. manifest.append('\t'.join((input_url, id_url, result_url)))
  47. manifest.append('\n')
  48. manifest_file_name = os.path.join(out_dir, 'manifest.txt')
  49. manifest_file = file(manifest_file_name, 'w')
  50. for chunk in manifest:
  51. manifest_file.write(chunk)
  52. manifest_file.close()
  53. if __name__ == '__main__':
  54. import sys
  55. buildDiscover(*sys.argv[1:])