inventory_api_test.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_api() :
  33. sleep(2)
  34. s = requests.Session()
  35. print("CREATE")
  36. r = s.post("http://127.0.0.1:8000/api/login",json={'username' : 'admin','password': 'aseqzdwxc'})
  37. print(r.__dict__)
  38. assert r.status_code == 200
  39. print("CREATE")
  40. r = s.get("http://127.0.0.1:8000/tab")
  41. print(r.__dict__)
  42. assert r.status_code == 200
  43. print("CREATE")
  44. r = s.post("http://127.0.0.1:8000/api/inventory/item",json={"assign_date_epoch": 5000, "assigned": True, "brand": "Mikrotik", "name": "RB2011", "note": "saline 2 RT 2, chez ashvin", "owned": True, "serial_number": "12345678", "tags": "#router #mikrotik #saline", "type": "router", "wear_score": 100})
  45. print(r.__dict__)
  46. assert r.status_code == 200
  47. print("CREATE")
  48. r = s.post("http://127.0.0.1:8000/api/inventory/item",json={"assign_date_epoch": 10000, "assigned": True, "brand": "Mikrotik", "name": "HEX S 1", "note": "saline 2 RT 3, chez ashvin", "owned": True, "serial_number": "12345678", "tags": "#router #mikrotik #saline", "type": "router", "wear_score": 100})
  49. print(r.__dict__)
  50. assert r.status_code == 200
  51. print("CREATE")
  52. r = s.post("http://127.0.0.1:8000/api/inventory/item",json={"assign_date_epoch": 10000, "assigned": True, "brand": "Mikrotik", "name": "HEX S 1", "note": "saline 2 RT 3, chez ashvin", "owned": True, "serial_number": "12345678", "tags": "#router #mikrotik #saline", "type": "router", "wear_score": 100})
  53. print(r.__dict__)
  54. assert r.status_code == 200
  55. print("CREATE")
  56. r = s.post("http://127.0.0.1:8000/api/inventory/item",json={"assign_date_epoch": 10000, "assigned": True, "brand": "Mikrotik", "name": "HEX S 1", "note": "saline 2 RT 3, chez ashvin", "owned": True, "serial_number": "12345678", "tags": "#router #mikrotik #saline", "type": "router", "wear_score": 100})
  57. print(r.__dict__)
  58. assert r.status_code == 200
  59. print("GET")
  60. r = s.get("http://127.0.0.1:8000/api/inventory/items")
  61. print(r.__dict__)
  62. assert r.status_code == 200
  63. print("DELETE")
  64. r = s.delete("http://127.0.0.1:8000/api/inventory/item/2")
  65. print(r.__dict__)
  66. assert r.status_code == 200
  67. print("CREATE SITE")
  68. r = s.post("http://127.0.0.1:8000/api/inventory/site",json={"assign_date_epoch": 5000, "assigned": True, "brand": "Mikrotik", "name": "RB2011", "note": "saline 2 RT 2, chez ashvin", "owned": True, "serial_number": "12345678", "tags": "#router #mikrotik #saline", "type": "router", "wear_score": 100})
  69. print(r.__dict__)
  70. assert r.status_code == 200