Skip to content

Commit

Permalink
Merge pull request #69 from barseghyanartur/dev
Browse files Browse the repository at this point in the history
Feature/add makefile commands for django migrations (#68)
  • Loading branch information
barseghyanartur committed Jan 15, 2024
2 parents c893ec0 + 779d4cf commit 4adb9a3
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ are used for versioning (schema follows below):
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.6.6
-----
2024-01-15

- Add ``image_url`` provider.

0.6.5
-----
2023-12-18
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Update version ONLY here
VERSION := 0.6.5
VERSION := 0.6.6
SHELL := /bin/bash
# Makefile for project
VENV := ~/.virtualenvs/fake.py/bin/activate
Expand Down Expand Up @@ -89,6 +89,12 @@ django-shell:
django-runserver:
source $(VENV) && python examples/django/manage.py runserver 0.0.0.0:8000 --traceback -v 3

django-makemigrations:
source $(VENV) && python examples/django/manage.py makemigrations

django-apply-migrations:
source $(VENV) && python examples/django/manage.py migrate

lazyfuzzy-shell:
source $(VENV) && cd examples/lazyfuzzy/ && python manage.py shell

Expand Down
24 changes: 24 additions & 0 deletions docs/recipes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,30 @@ Arguments:
- ``suffixes`` (type: ``Optional[Tuple[str]]``, default value: ``None``) is
an optional argument.

----
**image_url**

Returns a valid random image URL.

.. code-block:: python
FAKER.image_url()
Arguments:

- ``width`` (type: ``int``, default value: ``800``) is
a required argument.
- ``height`` (type: ``int``, default value: ``600``) is
an required argument.
- ``service_url`` (type: ``Optional[str]``, default value: ``None``) is
an optional argument.

Example with arguments (alternative dimensions):

.. code-block:: python
FAKER.image_url(width=640, height=480)
----

**pyint**
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jeepney==0.8.0
# via
# keyring
# secretstorage
jinja2==3.1.2
jinja2==3.1.3
# via sphinx
keyring==24.3.0
# via twine
Expand Down
47 changes: 45 additions & 2 deletions fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
)

__title__ = "fake.py"
__version__ = "0.6.5"
__version__ = "0.6.6"
__author__ = "Artur Barseghyan <artur.barseghyan@gmail.com>"
__copyright__ = "2023 Artur Barseghyan"
__copyright__ = "2023-2024 Artur Barseghyan"
__license__ = "MIT"
__all__ = (
"AuthorshipData",
Expand Down Expand Up @@ -842,6 +842,13 @@ def create(
return docx_bytes.getvalue()


IMAGE_SERVICES = (
"https://picsum.photos/{width}/{height}",
"https://dummyimage.com/{width}x{height}",
"https://placekitten.com/{width}/{height}",
"https://loremflickr.com/{width}/{height}",
)

# Global registry for provider methods
UID_REGISTRY: Dict[str, "Faker"] = {}
ALIAS_REGISTRY: Dict[str, "Faker"] = {}
Expand Down Expand Up @@ -1087,6 +1094,18 @@ def url(
suffix = random.choice(suffixes or (".html", ".php", ".go", "", "/"))
return f"{protocol}://{domain}.{tld}/{self.word().lower()}{suffix}"

@provider
def image_url(
self,
width: int = 800,
height: int = 600,
service_url: Optional[str] = None,
) -> str:
"""Image URL."""
if service_url is None:
service_url = random.choice(IMAGE_SERVICES)
return service_url.format(width=width, height=height)

@provider
def pyint(self, min_value: int = 0, max_value: int = 9999) -> int:
return random.randint(min_value, max_value)
Expand Down Expand Up @@ -2700,6 +2719,30 @@ def test_url(self) -> None:
url.endswith(suffix) or url.endswith(f"{suffix}/")
)

def test_image_url(self) -> None:
params = (
(None, None, None, {"width": 800, "height": 600}),
(640, 480, None, {"width": 640, "height": 480}),
(
None,
None,
"https://example.com/{width}x{height}",
{"width": 800, "height": 600},
),
)
for width, height, service_url, expected in params:
kwargs = {}
if width:
kwargs["width"] = width
if height:
kwargs["height"] = height
if service_url:
kwargs["service_url"] = service_url
image_url = self.faker.image_url(**kwargs)
self.assertIn(str(expected["width"]), image_url)
self.assertIn(str(expected["height"]), image_url)
self.assertTrue(image_url.startswith("https://"))

def test_pyint(self) -> None:
ranges = [
(None, None, 0, 9999),
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "fake.py"
description = "Minimalistic, standalone alternative fake data generator with no dependencies."
readme = "README.rst"
version = "0.6.5"
version = "0.6.6"
dependencies = []
authors = [
{name = "Artur Barseghyan", email = "artur.barseghyan@gmail.com"},
Expand Down Expand Up @@ -143,7 +143,7 @@ ignore-path = [
]

[tool.pytest.ini_options]
minversion = "0.6.5"
minversion = "0.6.6"
addopts = [
"-ra",
"-vvv",
Expand Down

0 comments on commit 4adb9a3

Please sign in to comment.