core_test.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import os
  2. from time import sleep
  3. os.chdir(os.path.dirname(__file__))
  4. import sys
  5. sys.path.append("..")
  6. sys.path.append("..\\Sources")
  7. from Sources.Modules.Inventory.inventory import * #altered
  8. import Sources.main as main_func
  9. import Sources.Model.model_manager as model_manager
  10. import requests
  11. from werkzeug.security import generate_password_hash
  12. import Sources.View.view_manager as view
  13. item_id_to_delete = 0
  14. import threading
  15. import pytest
  16. from pytest import Module, Session
  17. @pytest.fixture(autouse=True,scope='session')
  18. def fixture2():
  19. def run() :
  20. main_func.init()
  21. persistence.wipeout_database()
  22. persistence.init()
  23. model_manager.init()
  24. main_func.main()
  25. t1 = threading.Thread(target=run)
  26. t1.start()
  27. while(not main_func.isRunning()) :
  28. sleep(1)
  29. yield
  30. main_func.stop()
  31. t1.join()
  32. # Perform cleanup on the data when the test function exits
  33. def test_login() :
  34. s = requests.Session()
  35. r = s.post("http://127.0.0.1:8000/api/login",json={'username' : 'admin','password': 'aseqzdwxc'})
  36. print(r.__dict__)
  37. assert r.status_code == 200
  38. r = s.get("http://127.0.0.1:8000/tab")
  39. print(r.__dict__)
  40. assert r.status_code == 200
  41. def test_inventory() :
  42. s = requests.Session()
  43. r = s.post("http://127.0.0.1:8000/api/login",json={'username' : 'admin','password': 'aseqzdwxc'})
  44. print(r.__dict__)
  45. assert r.status_code == 200
  46. r = s.get("http://127.0.0.1:8000/tab")
  47. print(r.__dict__)
  48. assert r.status_code == 200