123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import os
- from time import sleep
- from flask import request
- os.chdir(os.path.dirname(__file__))
- import sys
- sys.path.append("..")
- sys.path.append("..\\Sources")
- from Sources.Modules.Inventory.inventory import * #altered
- import Sources.main as main_func
- import Sources.Model.model_manager as model_manager
- import requests
- from werkzeug.security import generate_password_hash
- import Sources.View.view_manager as view
- item_id_to_delete = 0
- import threading
- import pytest
- import json
- from requests.auth import AuthBase
- class TokenAuth(AuthBase):
- """Implements a custom authentication scheme."""
- def __init__(self, token):
- self.token = token
- def __call__(self, r):
- """Attach an API token to a custom auth header."""
- r.headers['x-Auth-Token'] = f'{self.token}' # Python 3.6+
- return r
- @pytest.fixture(autouse=True,scope='session')
- def fixture2():
- def run() :
- main_func.init()
- persistence.wipeout_database()
- persistence.init()
- model_manager.init()
- main_func.main()
- t1 = threading.Thread(target=run)
- t1.start()
- while(not main_func.isRunning()) :
- sleep(1)
- yield
- main_func.stop()
- t1.join()
- # Perform cleanup on the data when the test function exits
- def test_login() :
- token = None
- r = requests.post("http://127.0.0.1:8000/api/login",json={'username' : 'admin','password': 'aseqzdwxc'})
- print(r.__dict__)
- data = json.loads(r.content)
- token = data["token"]
- assert token is not None
- assert r.status_code == 200
- r = requests.get("http://127.0.0.1:8000/api/me",auth=TokenAuth(token))
- print(r.__dict__)
- assert r.status_code == 200
|