1
0

tests.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. import json
  3. import os
  4. import sys
  5. REQUIRED_FIELDS = ['publicKey', 'password', 'contact']
  6. RED = '\x1b[01;31m'
  7. GREEN = '\x1b[01;32m'
  8. END = '\x1b[0m'
  9. def validate(path):
  10. print("Validating %s" % path)
  11. try:
  12. creds = open(path).read()
  13. peers = json.loads("{%s}" % creds)
  14. hosts = peers.keys()
  15. for host in hosts:
  16. for field in REQUIRED_FIELDS:
  17. if not field in peers[host]:
  18. print(" %sHost %s is missing the %s field!%s" % (RED, host, field, END))
  19. return False
  20. print(" %sSuccess!%s" % (GREEN, END))
  21. return True
  22. except ValueError:
  23. print(" %sInvalid JSON!%s" % (RED, END))
  24. return False
  25. success = True
  26. for directory, subdirs, files in os.walk('.'):
  27. if len(files) > 0:
  28. for f in files:
  29. if f.endswith('.k'):
  30. result = validate("%s/%s" % (directory, f))
  31. if not result:
  32. success = False
  33. if not success:
  34. sys.exit(1)