core_test.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. @pytest.fixture(autouse=True,scope='session')
  17. def fixture2():
  18. def run() :
  19. main_func.init()
  20. persistence.wipeout_database()
  21. persistence.init()
  22. model_manager.init()
  23. main_func.main()
  24. t1 = threading.Thread(target=run)
  25. t1.start()
  26. while(not main_func.isRunning()) :
  27. sleep(1)
  28. yield
  29. main_func.stop()
  30. t1.join()
  31. # Perform cleanup on the data when the test function exits
  32. def test_login() :
  33. s = requests.Session()
  34. r = s.post("http://127.0.0.1:8000/api/login",json={'username' : 'admin','password': 'aseqzdwxc'})
  35. print(r.__dict__)
  36. assert r.status_code == 200
  37. r = s.get("http://127.0.0.1:8000/tab")
  38. print(r.__dict__)
  39. assert r.status_code == 200