Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Jul 27, 2023
1 parent 54a37df commit 422f4a5
Show file tree
Hide file tree
Showing 21 changed files with 166 additions and 83 deletions.
46 changes: 46 additions & 0 deletions docs/recipes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,52 @@ AWS S3 storage
txt_file = FAKER.txt_file(storage=AWS_S3_STORAGE)
Depending on the ORM or framework you're using, you might want to tweak the
``root_path`` and ``rel_path`` values. Especially if you store files in
directories (like ``your-bucket-name/path/to/the/file.ext``).

For instance, if you use ``Django`` and ``django-storages``, and want to
store the files inside ``/user/uploads`` directory the following would be
correct:

.. code-block:: python
AWS_S3_STORAGE = AWSS3Storage(
bucket_name="your-bucket-name",
root_path="",
rel_path="/user/uploads",
)
Google Cloud Storage
^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
from faker import Faker
from faker_file.providers.txt_file import TxtFileProvider
from faker_file.storages.google_cloud_storage import GoogleCloudStorage
FAKER = Faker()
GC_STORAGE = GoogleCloudStorage(
bucket_name="your-bucket-name",
root_path="",
rel_path="",
)
FAKER.add_provider(TxtFileProvider)
txt_file = FAKER.txt_file(storage=GC_STORAGE)
Similarly to ``AWSS3Storage``, if you use ``Django`` and ``django-storages``,
and want to store the files inside ``/user/uploads`` directory the following
would be correct:

.. code-block:: python
GC_STORAGE = GoogleCloudStorage(
bucket_name="your-bucket-name",
root_path="",
rel_path="/user/uploads",
)
SFTP storage
^^^^^^^^^^^^
.. code-block:: python
Expand Down
11 changes: 7 additions & 4 deletions src/faker_file/providers/bin_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ class BinFileProvider(BaseProvider, FileMixin):
from faker import Faker
from faker_file.providers.bin_file import BinFileProvider
file = BinFileProvider(Faker()).bin_file()
FAKER = Faker()
FAKER.add_provider(BinFileProvider)
file = FAKER.bin_file()
Usage example with options:
file = BinFileProvider(Faker()).bin_file(
file = FAKER.bin_file(
prefix="zzz",
length=1024**2,
)
Expand All @@ -35,7 +38,7 @@ class BinFileProvider(BaseProvider, FileMixin):
from django.conf import settings
from faker_file.storages.filesystem import FileSystemStorage
file = BinFileProvider(Faker()).bin_file(
file = FAKER.bin_file(
storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT,
rel_path="tmp",
Expand All @@ -48,7 +51,7 @@ class BinFileProvider(BaseProvider, FileMixin):
from faker_file.storages.aws_s3 import AWSS3Storage
file = BinFileProvider(Faker()).bin_file(
file = FAKER.bin_file(
storage=AWSS3Storage(bucket_name="My-test-bucket"),
prefix="zzz",
length=1024**2,
Expand Down
10 changes: 5 additions & 5 deletions src/faker_file/providers/eml_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ class EmlFileProvider(BaseProvider, FileMixin):
from faker_file.providers.eml_file import EmlFileProvider
FAKER = Faker()
FAKER.add_provider(EmlFileProvider)
file = EmlFileProvider(FAKER).eml_file()
file = FAKER.eml_file()
Usage example with attachments:
from faker_file.providers.helpers.inner import create_inner_docx_file
from faker_file.providers.eml_file import EmlFileProvider
file = EmlFileProvider(FAKER).eml_file(
file = FAKER.eml_file(
prefix="zzz_email_",
options={
"count": 5,
Expand All @@ -60,7 +60,7 @@ class EmlFileProvider(BaseProvider, FileMixin):
from faker_file.providers.helpers.inner import create_inner_eml_file
file = EmlFileProvider(FAKER).eml_file(
file = FAKER.eml_file(
options={
"create_inner_file_func": create_inner_eml_file,
"create_inner_file_args": {
Expand Down Expand Up @@ -199,7 +199,7 @@ def eml_file(
"""
A complex case. Could be initialized as follows:
eml_file = EmlFileProvider(FAKER).eml_file(
eml_file = FAKER.eml_file(
prefix="zzz_email_",
options={
"count": 5,
Expand Down
9 changes: 6 additions & 3 deletions src/faker_file/providers/epub_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ class EpubFileProvider(BaseProvider, FileMixin):
from faker import Faker
from faker_file.providers.epub_file import EpubFileProvider
file = EpubFileProvider(Faker()).epub_file()
FAKER = Faker()
FAKER.add_provider(EpubFileProvider)
file = FAKER.epub_file()
Usage example with options:
file = EpubFileProvider(Faker()).epub_file(
file = FAKER.epub_file(
prefix="zzz",
max_nb_chars=100_000,
wrap_chars_after=80,
Expand All @@ -43,7 +46,7 @@ class EpubFileProvider(BaseProvider, FileMixin):
from django.conf import settings
from faker_file.storages.filesystem import FileSystemStorage
file = EpubFileProvider(Faker()).epub_file(
file = FAKER.epub_file(
storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT,
rel_path="tmp",
Expand Down
12 changes: 6 additions & 6 deletions src/faker_file/providers/file_from_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ class FileFromPathProvider(BaseProvider, FileMixin):
Usage example:
from faker import Faker
from faker_file.providers.file_from_path import (
FileFromPathProvider,
)
file = FileFromPathProvider(None).file_from_path(
FAKER = Faker()
FAKER.add_provider(FileFromPathProvider)
file = FAKER.file_from_path(
path="/path/to/file.pdf",
)
Usage example with options:
from faker_file.providers.file_from_path import (
FileFromPathProvider,
)
file = FileFromPathProvider(None).file_from_path(
file = FAKER.file_from_path(
path="/path/to/file.pdf",
prefix="zzz",
)
Expand Down
11 changes: 7 additions & 4 deletions src/faker_file/providers/generic_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ class GenericFileProvider(BaseProvider, FileMixin):
from faker import Faker
from faker_file.providers.generic_file import GenericFileProvider
file = GenericFileProvider(Faker()).generic_file(
FAKER = Faker()
FAKER.add_provider(GenericFileProvider)
file = FAKER.generic_file(
content="<html><body><p>{{text}}</p></body></html>",
extension="html",
)
Usage example with options:
file = GenericFileProvider(Faker()).generic_file(
file = FAKER.generic_file(
content="<html><body><p>{{text}}</p></body></html>",
extension="html",
prefix="zzz",
Expand All @@ -41,7 +44,7 @@ class GenericFileProvider(BaseProvider, FileMixin):
from django.conf import settings
from faker_file.storages.filesystem import FileSystemStorage
file = GenericFileProvider(Faker()).generic_file(
file = FAKER.generic_file(
content="<html><body><p>{{text}}</p></body></html>",
extension="html",
basename="index",
Expand All @@ -55,7 +58,7 @@ class GenericFileProvider(BaseProvider, FileMixin):
from faker_file.storages.aws_s3 import AWSS3Storage
file = GenericFileProvider(Faker()).generic_file(
file = FAKER.generic_file(
storage=AWSS3Storage(bucket_name="My-test-bucket"),
content="<html><body><p>{{text}}</p></body></html>",
extension="html",
Expand Down
9 changes: 6 additions & 3 deletions src/faker_file/providers/ico_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ class IcoFileProvider(BaseProvider, ImageMixin):
from faker import Faker
from faker_file.providers.ico_file import IcoFileProvider
file = IcoFileProvider(Faker()).ico_file()
FAKER = Faker()
FAKER.add_provider(IcoFileProvider)
file = FAKER.ico_file()
Usage example with options:
file = IcoFileProvider(Faker()).ico_file(
file = FAKER.ico_file(
prefix="zzz",
max_nb_chars=100_000,
wrap_chars_after=80,
Expand All @@ -54,7 +57,7 @@ class IcoFileProvider(BaseProvider, ImageMixin):
from django.conf import settings
from faker_file.storages.filesystem import FileSystemStorage
file = IcoFileProvider(Faker()).ico_file(
file = FAKER.ico_file(
storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT,
rel_path="tmp",
Expand Down
9 changes: 6 additions & 3 deletions src/faker_file/providers/jpeg_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ class JpegFileProvider(BaseProvider, ImageMixin):
from faker import Faker
from faker_file.providers.jpeg_file import JpegFileProvider
file = JpegFileProvider(None).jpeg_file()
FAKER = Faker()
FAKER.add_provider(JpegFileProvider)
file = FAKER.jpeg_file()
Usage example with options:
file = JpegFileProvider(None).jpeg_file(
file = FAKER.jpeg_file(
prefix="zzz",
max_nb_chars=100_000,
wrap_chars_after=80,
Expand All @@ -54,7 +57,7 @@ class JpegFileProvider(BaseProvider, ImageMixin):
from django.conf import settings
from faker_file.storages.filesystem import FileSystemStorage
file = JpegFileProvider(Faker()).jpeg_file(
file = FAKER.jpeg_file(
storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT,
rel_path="tmp",
Expand Down
7 changes: 4 additions & 3 deletions src/faker_file/providers/odp_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ class OdpFileProvider(BaseProvider, FileMixin):
from faker_file.providers.odp_file import OdpFileProvider
FAKER = Faker()
FAKER.add_provider(OdpFileProvider)
file = OdpFileProvider(FAKER).odp_file()
file = FAKER.odp_file()
Usage example with options:
file = OdpFileProvider(FAKER).odp_file(
file = FAKER.odp_file(
prefix="zzz",
max_nb_chars=100_000,
wrap_chars_after=80,
Expand All @@ -45,7 +46,7 @@ class OdpFileProvider(BaseProvider, FileMixin):
from django.conf import settings
from faker_file.storages.filesystem import FileSystemStorage
file = OdpFileProvider(FAKER).odp_file(
file = FAKER.odp_file(
storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT,
rel_path="tmp",
Expand Down
9 changes: 6 additions & 3 deletions src/faker_file/providers/ods_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ class OdsFileProvider(BaseProvider, TabularDataMixin):
from faker import Faker
from faker_file.providers.ods_file import OdsFileProvider
file = OdsFileProvider(Faker()).ods_file()
FAKER = Faker()
FAKER.add_provider(OdsFileProvider)
file = FAKER.ods_file()
Usage example with options:
from faker import Faker
from faker_file.providers.ods_file import OdsFileProvider
file = OdsFileProvider(Faker()).ods_file(
file = FAKER.ods_file(
prefix="zzz",
num_rows=100,
data_columns={
Expand All @@ -45,7 +48,7 @@ class OdsFileProvider(BaseProvider, TabularDataMixin):
from django.conf import settings
from faker_file.storages.filesystem import FileSystemStorage
file = OdsFileProvider(Faker()).ods_file(
file = FAKER.ods_file(
storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT,
rel_path="tmp",
Expand Down
9 changes: 6 additions & 3 deletions src/faker_file/providers/png_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ class PngFileProvider(BaseProvider, ImageMixin):
from faker import Faker
from faker_file.providers.png_file import PngFileProvider
file = PngFileProvider(Faker()).png_file()
FAKER = Faker()
FAKER.add_provider(PngFileProvider)
file = FAKER.png_file()
Usage example with options:
file = PngFileProvider(Faker()).png_file(
file = FAKER.png_file(
prefix="zzz",
max_nb_chars=100_000,
wrap_chars_after=80,
Expand All @@ -54,7 +57,7 @@ class PngFileProvider(BaseProvider, ImageMixin):
from django.conf import settings
from faker_file.storages.filesystem import FileSystemStorage
file = PngFileProvider(Faker()).png_file(
file = FAKER.png_file(
storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT,
rel_path="tmp",
Expand Down
14 changes: 8 additions & 6 deletions src/faker_file/providers/pptx_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@
class PptxFileProvider(BaseProvider, FileMixin):
"""PPTX file provider.
Usage example:
Usage example:
from faker import Faker
from faker_file.providers.pptx_file import PptxFileProvider
file = PptxFileProvider(None).pptx_file()
FAKER = Faker()
FAKER.add_provider(PptxFileProvider)
Usage example with options:
file = FAKER.pptx_file()
from faker_file.providers.pptx_file import PptxFileProvider
Usage example with options:
file = PptxFileProvider(None).pptx_file(
file = FAKER.pptx_file(
prefix="zzz",
max_nb_chars=100_000,
wrap_chars_after=80,
Expand All @@ -43,7 +45,7 @@ class PptxFileProvider(BaseProvider, FileMixin):
from django.conf import settings
from faker_file.storages.filesystem import FileSystemStorage
file = PptxFileProvider(Faker()).pptx_file(
file = FAKER.pptx_file(
storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT,
rel_path="tmp",
Expand Down
Loading

0 comments on commit 422f4a5

Please sign in to comment.