Skip to content

Commit

Permalink
Update PDF factory docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-fcampbell committed Oct 17, 2024
1 parent 3dd3b40 commit e90237d
Showing 1 changed file with 72 additions and 25 deletions.
97 changes: 72 additions & 25 deletions tests/nativeapp/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,27 +151,12 @@ def as_json_str(self):
return json.dumps(self.yml)


class PdfFactory(factory.DictFactory):
class _PdfFactory(factory.DictFactory):
"""
Prepare PDF dict and write to file.
Base class to prepare PDF dict and write to file.
Returns:
PdfFactoryResult
Usage:
Create a pdf dict with definition_version: "1", native_app with faker-generated name and an empty artifacts list and
write to snowflake.yml in current directory:
- PdfFactory()
Create snowflake.local.yml and write to file
- PdfFactory.with_filename("snowflake.local.yml")(native_app__name="my_local_name")
Build and return yml but do not write to file:
- PdfFactory.build(
native_app__name="my_app",
native_app__artifacts=["setup.sql", "README.md"],
native_app__package__role="pkg_role"
)
"""

env = factory.SubFactory(FactoryNoEmptyDict)
Expand All @@ -180,10 +165,10 @@ class PdfFactory(factory.DictFactory):
# for snowflake.local.yml
@classmethod
def with_filename(cls, filename):
class PdfFactoryWithFilename(cls):
class _PdfFactoryWithFilename(cls):
_filename = filename

return PdfFactoryWithFilename
return _PdfFactoryWithFilename

@classmethod
def _build(cls, model_class, *args, **kwargs):
Expand All @@ -207,16 +192,78 @@ def _create(cls, model_class, *args, **kwargs) -> PdfFactoryResult:
)


class PdfV10Factory(PdfFactory):
class PdfV10Factory(_PdfFactory):
"""
Prepare PDF 1.0 dict and write to file.
Returns:
PdfFactoryResult
Usage:
Create a PDF dict with definition_version: "1", native_app with faker-generated name and an empty artifacts list and
write to snowflake.yml in current directory:
- PdfV10Factory()
Create snowflake.local.yml and write to file
- PdfV10Factory.with_filename("snowflake.local.yml")(native_app__name="my_local_name")
Build and return yml but do not write to file:
- PdfV10Factory.build(
native_app__name="my_app",
native_app__artifacts=["setup.sql", "README.md"],
native_app__package__role="pkg_role"
)
"""

definition_version = "1"
native_app = factory.SubFactory(NativeAppFactory)


class PdfV11Factory(PdfV10Factory):
"""Override of Pdfv10Factory to set definition_version to 1.1"""

definition_version = "1.1"


class PdfV2Factory(PdfFactory):
class PdfV2Factory(_PdfFactory):
"""
Prepare PDF 2 dict and write to file.
Returns:
PdfFactoryResult
Usage:
Create a PDF dict with definition_version: "2" with empty list of entities and
write to snowflake.yml in current directory:
- PdfV2Factory()
Create snowflake.local.yml with some entities and write to file
- PdfV2Factory.with_filename("snowflake.local.yml")(
entities=dict(
pkg=ApplicationPackageEntityModelFactory(
identifier="myapp_pkg",
),
app=ApplicationEntityModelFactory(
identifier="myapp",
fromm__target="pkg",
),
)
)
Build and return yml but do not write to file:
- PdfV2Factory.build(
entities=dict(
pkg=ApplicationPackageEntityModelFactory(
identifier="myapp_pkg",
),
app=ApplicationEntityModelFactory(
identifier="myapp",
fromm__target="pkg",
),
)
)
"""

definition_version = "2"
entities = factory.Dict({})
env = factory.Dict({})
Expand Down Expand Up @@ -259,15 +306,15 @@ class ProjectFactoryModel:
ProjectFiles = dict[str | Path, str]


class ProjectFactory(factory.Factory):
class _ProjectFactory(factory.Factory):
"""
Factory to create PDF dict, and write in working directory PDF to snowflake.yml file, and other optional files.
"""

class Meta:
model = ProjectFactoryModel

pdf = factory.SubFactory(PdfFactory)
pdf = factory.SubFactory(_PdfFactory)
files: ProjectFiles = {}

@classmethod
Expand All @@ -277,13 +324,13 @@ def _create(cls, model_class, *args, **kwargs):
return super()._create(model_class, *args, **kwargs)


class ProjectV10Factory(ProjectFactory):
class ProjectV10Factory(_ProjectFactory):
pdf = factory.SubFactory(PdfV10Factory)


class ProjectV11Factory(ProjectV10Factory):
pdf = factory.SubFactory(PdfV11Factory)


class ProjectV2Factory(ProjectFactory):
class ProjectV2Factory(_ProjectFactory):
pdf = factory.SubFactory(PdfV2Factory)

0 comments on commit e90237d

Please sign in to comment.