import hypothesis.strategies as st
from hypothesis import given
from hypothesis.strategies import DataObject
from sqlmodel import Session, select

from fastapi_server.models.user import User
from fastapi_server.test.base_test import BaseTest


class TestDatabase(BaseTest):

    def test_user_add_single(self, method_session_fixture: Session):
        session = method_session_fixture
        assert isinstance(session, Session)
        username = 'asd'
        email = '<EMAIL>'
        password = '<PASSWORD>'
        assert session.exec(select(User)).all() == []
        session.add(
            User(
                username=username,
                email=email,
                password_hashed=password,
                is_admin=False,
                is_disabled=False,
                is_verified=False,
            )
        )
        session.commit()
        assert session.exec(select(User)).all() != []

    @given(data=st.data())
    def test_user_add_multiple(self, data: DataObject):
        username = data.draw(st.from_regex('[a-zA-Z0-9]{1,20}', fullmatch=True))
        email = data.draw(st.from_regex('[a-zA-Z]{1,20}@gmailcom', fullmatch=True))
        password = data.draw(st.from_regex('[a-zA-Z0-9]{1,20}', fullmatch=True))
        with self.example_session_context() as session:
            assert session.exec(select(User)).all() == []
            session.add(
                User(
                    username=username,
                    email=email,
                    password_hashed=password,
                    is_admin=False,
                    is_disabled=False,
                    is_verified=False,
                )
            )
            session.commit()
            assert session.exec(select(User)).all() != []

fastapi_server.models.user.User sqlmodel.select hypothesis.strategies.from_regex hypothesis.strategies.data
[((599, 720), 'fastapi_server.models.user.User', 'User', ([], {'username': 'username', 'email': 'email', 'password_hashed': 'password', 'is_admin': '(False)', 'is_disabled': '(False)', 'is_verified': '(False)'}), '(username=username, email=email, password_hashed=password, is_admin=\n    False, is_disabled=False, is_verified=False)\n', (603, 720), False, 'from fastapi_server.models.user import User\n'), ((1029, 1079), 'hypothesis.strategies.from_regex', 'st.from_regex', (['"""[a-zA-Z0-9]{1,20}"""'], {'fullmatch': '(True)'}), "('[a-zA-Z0-9]{1,20}', fullmatch=True)\n", (1042, 1079), True, 'import hypothesis.strategies as st\n'), ((1107, 1163), 'hypothesis.strategies.from_regex', 'st.from_regex', (['"""[a-zA-Z]{1,20}@gmailcom"""'], {'fullmatch': '(True)'}), "('[a-zA-Z]{1,20}@gmailcom', fullmatch=True)\n", (1120, 1163), True, 'import hypothesis.strategies as st\n'), ((1194, 1244), 'hypothesis.strategies.from_regex', 'st.from_regex', (['"""[a-zA-Z0-9]{1,20}"""'], {'fullmatch': '(True)'}), "('[a-zA-Z0-9]{1,20}', fullmatch=True)\n", (1207, 1244), True, 'import hypothesis.strategies as st\n'), ((933, 942), 'hypothesis.strategies.data', 'st.data', ([], {}), '()\n', (940, 942), True, 'import hypothesis.strategies as st\n'), ((1401, 1522), 'fastapi_server.models.user.User', 'User', ([], {'username': 'username', 'email': 'email', 'password_hashed': 'password', 'is_admin': '(False)', 'is_disabled': '(False)', 'is_verified': '(False)'}), '(username=username, email=email, password_hashed=password, is_admin=\n    False, is_disabled=False, is_verified=False)\n', (1405, 1522), False, 'from fastapi_server.models.user import User\n'), ((540, 552), 'sqlmodel.select', 'select', (['User'], {}), '(User)\n', (546, 552), False, 'from sqlmodel import Session, select\n'), ((890, 902), 'sqlmodel.select', 'select', (['User'], {}), '(User)\n', (896, 902), False, 'from sqlmodel import Session, select\n'), ((1334, 1346), 'sqlmodel.select', 'select', (['User'], {}), '(User)\n', (1340, 1346), False, 'from sqlmodel import Session, select\n'), ((1732, 1744), 'sqlmodel.select', 'select', (['User'], {}), '(User)\n', (1738, 1744), False, 'from sqlmodel import Session, select\n')]