core_test.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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
  49. r = s.post("http://127.0.0.1:8000/inventory/item",json={"assign_date_epoch": 5000, "assigned": True, "brand": "Mikrotik", "name": "RB2011", "note": "saline RT 2, chez ashvin", "owned": True, "serial_number": "12345678", "tags": "#router #mikrotik #saline", "type": "router", "wear_score": 100})
  50. print(r.__dict__)
  51. assert r.status_code == 200
  52. r = s.get("http://127.0.0.1:8000/inventory/items")
  53. print(r.__dict__)
  54. assert r.status_code == 200