Skip to content

Commit

Permalink
✅ fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse committed Nov 26, 2023
1 parent 9b05341 commit abb8aa8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

import factory

from . import models
from . import faker_providers, models


factory.Faker.add_provider(faker_providers.DateTimeProviders)


class AuthorFactory(factory.Factory):
Expand Down Expand Up @@ -37,7 +40,7 @@ class Meta:
boolean_field: factory.Faker = factory.Faker("boolean")
char_field: factory.Faker = factory.Faker("text", max_nb_chars=255)
date_field: factory.Faker = factory.Faker("date_this_decade")
date_time_field: factory.Faker = factory.Faker("date_time_this_century")
date_time_field: factory.Faker = factory.Faker("date_time_this_century_without_microseconds")
decimal_field: factory.Faker = factory.Faker("pydecimal", left_digits=8, right_digits=2)
float_field: factory.Faker = factory.Faker("pyfloat", left_digits=8, right_digits=4)
integer_field: factory.Faker = factory.Faker("pyint", min_value=-(2**31), max_value=2**31 - 1)
Expand All @@ -50,10 +53,10 @@ class Meta:
small_integer_field: factory.Faker = factory.Faker("pyint", min_value=-(2**15), max_value=2**15 - 1)
string_field: factory.Faker = factory.Faker("text", max_nb_chars=255)
text_field: factory.Faker = factory.Faker("text", max_nb_chars=1024)
time_field: factory.Faker = factory.Faker("time_object")
time_field: factory.Faker = factory.Faker("time_object_without_microseconds")
varbinary_field: factory.Faker = factory.Faker("binary", length=255)
varchar_field: factory.Faker = factory.Faker("text", max_nb_chars=255)
timestamp_field: factory.Faker = factory.Faker("date_time_this_century")
timestamp_field: factory.Faker = factory.Faker("date_time_this_century_without_microseconds")


class ArticleFactory(factory.Factory):
Expand Down
22 changes: 22 additions & 0 deletions tests/faker_providers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import datetime
from typing import Optional

from faker.providers import BaseProvider, date_time
from faker.typing import DateParseType


class DateTimeProviders(BaseProvider):
def time_object_without_microseconds(self, end_datetime: Optional[DateParseType] = None) -> datetime.time:
return date_time.Provider(self.generator).time_object(end_datetime).replace(microsecond=0)

def date_time_this_century_without_microseconds(
self,
before_now: bool = True,
after_now: bool = False,
tzinfo: Optional[datetime.tzinfo] = None,
) -> datetime.datetime:
return (
date_time.Provider(self.generator)
.date_time_this_century(before_now, after_now, tzinfo)
.replace(microsecond=0)
)

0 comments on commit abb8aa8

Please sign in to comment.