Open lclpedro opened 2 years ago
Resolved with code, in head of the test..
datetime.now().__class__.__name__ = "datetime"
datetime.now().date().__class__.__name__ = "date"
@pytest.fixture
@freeze_time("2021-12-04")
def fake_base_another_day(client: TestClient, with_body: dict):
datetime.now().__class__.__name__ = "datetime"
datetime.now().date().__class__.__name__ = "date"
with_body["personalData"]["cpf"] = "08697524300" # Fake
with_body["personalData"]["firstName"] = "lalala Ferreira"
with_body["personalData"]["lastName"] = "da Conceição"
with_body["personalData"]["email"] = "lalala@teleworm.us"
with_body["personalData"]["phone"] = "123123123123"
with_body["personalData"]["address"]["city"] = "Curitiba"
with_body["personalData"]["address"]["state"] = "PR"
with_body["placeDetails"]["addressType"] = "residential"
client.post(
URL_REGISTRATION, json=with_body, headers={"authorization": pytest.TOKEN}
)
WIth Django, the same thing here.
@pytest.mark.django_db
def test_purge_old_data_success(user_01, user_02, freezer):
"""Test if notification are purged as expected."""
origin = NotificationOrigin.FROM_GROUP.value
subject = "subject"
body = "body"
now = timezone.now()
# datetime.now().__class__.__name__ = "datetime"
# datetime.now().date().__class__.__name__ = "date"
freezer.move_to(now - timedelta(days=30))
for _ in range(5):
Notification.objects.create(
user_receiver=user_02, origin=origin, subject=subject, body=body,
created_at=str(datetime.now()),
updated_at=str(datetime.now())
)
This is the message:
self = <mysql.connector.django.base.DjangoMySQLConverter object at 0xffff8ce99ae0>, value = FakeDatetime(2022, 9, 1, 23, 5, 0, 127073)
def to_mysql(self, value):
"""Convert Python data type to MySQL"""
type_name = value.__class__.__name__.lower()
try:
return getattr(self, f"_{type_name}_to_mysql")(value)
except AttributeError:
if self.str_fallback:
return str(value).encode()
> raise TypeError(
f"Python '{type_name}' cannot be converted to a MySQL type"
) from None
E TypeError: Python 'fakedatetime' cannot be converted to a MySQL type
I'm getting this error with the mysql connector, does anyone know why this is happening, if there is any specific reason?
Error occurred:
Test..