from django.template.defaultfilters import first
from django.urls import reverse
from django.shortcuts import render, redirect
import pytest
from apps.accounts.models import User
import json
from django.core import mail
from termcolor import colored
from apps.subscriptions.models import *
from faker import Faker


@pytest.mark.django_db
def test_sign_in_with_no_existing_user(client, user_signup_data: dict) -> None:

    username = user_signup_data["username"]
    password = user_signup_data["password"]
    email = user_signup_data["email"]
    url = client.post(
        path=reverse("accounts:signin"),
        data={"email": email, "username": username, "password": password},
    )
    response = json.loads(url.content)

    assert response["result"] == "error"
    assert (
        response["message"]
        == "Email does not exist. Kindly Try Again With A Valid Email."
    )

@pytest.mark.django_db
def test_signin_with_exiting_user(client, user_signin_data,normal_user_factory):
    new_user = normal_user_factory.create()

    url = client.post(
        path=reverse("accounts:signin"),
        data={"email": new_user.email, "username": new_user.username, "password": new_user.password},
    )
    response = json.loads(url.content)
    print(response)
    # assert User.objects.count() == 1
    # assert response["result"] == "success"
    # assert response["message"] == "You are logged in."