002-apikey.py 918 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import pathlib
  2. import sys
  3. current = pathlib.Path(__file__)
  4. test_dir = current.parent
  5. project_dir = test_dir.parent
  6. source_dir = project_dir / pathlib.Path("source")
  7. sys.path.append(str(source_dir))
  8. import cx_apikey as apikey
  9. test_count = 0
  10. def test(tag: str, result: bool) -> None:
  11. global test_count
  12. test_count += 1
  13. print("Running test " + tag + " (" + str(test_count) + "):", end = " ")
  14. if result:
  15. print("Valid")
  16. return
  17. print("FAIL!!!")
  18. exit(-1)
  19. factory = apikey.apikey_factory("test").set_size(64)
  20. sample_1 = factory.generate()
  21. sample_2 = factory.generate()
  22. sample_1_string = sample_1.content
  23. test("compare different", sample_1 != sample_2)
  24. test("compare different string", sample_1 != str(sample_2))
  25. test("compare self", sample_1 == sample_1)
  26. test("compare self as content", sample_1 == sample_1_string)
  27. test("compare self as string", sample_1 == str(sample_1))