from secrets import token_hex

from pytest import main

from app.schemas import *
from database.models import *
from tests import client


def test_registration():
    user = {
        "full_name": "Bilal Balaperdida",
        "email": "oyvey@hotmail.com",
        "password": "lifeisabitch",
        "gender": 1,
        "mobile": "+212655778899",
        "user_type": 1,
        "lang_type": 1,
        "device_type": 1,
        "device_id": token_hex(16),
        "city_id": 5,
    }
    response = client.post("/register", json=user)
    assert response.status_code == 200


def test_otp_verification(get_test_db):
    user = get_test_db.query(Users).filter(Users.email == "oyvey@hotmail.com").first()
    data = {"access_key": user.access_key, "otp": user.otp}
    response = client.post("/otpVerification", json=data)
    assert response.status_code == 200


def test_login():
    user = {
        "email": "testorganizer@odyfo.com",
        "password": "odyfo2020",
        "device_id": "0",
        "lang_type": 1,
        "user_type": 2,
    }
    response = client.post("/login", json=user)
    assert response.status_code == 200


def test_resend_otp():
    data = {"email": "testorganizer@odyfo.com"}
    response = client.post("/resendOTP", json=data)
    assert response.status_code == 200


def test_forgot_password():
    data = {"email": "oyvey@hotmail.com"}
    response = client.post("/forgot_password", json=data)
    assert response.status_code == 200


def test_reset_password(get_test_db):
    test_otp_verification(get_test_db)
    data = {"email": "oyvey@hotmail.com", "password": "vivashviva"}
    response = client.post("/reset_password", json=data)
    assert response.status_code == 200