Last active
June 8, 2023 03:21
-
-
Save whchi/43ac53031827943d15cfc94d6a67d260 to your computer and use it in GitHub Desktop.
sinple counter for data factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DataFactory: | |
| counter = count(start=1) | |
| def model(self): | |
| return ApplicationCarousel | |
| def definition(self): | |
| faker = Faker() | |
| faker.add_provider(internet) | |
| return { | |
| 'application_uuid': self.relation.get('application_uuid'), | |
| 'media_type': MediaType.IMAGE, | |
| 'media_url': faker.image_url(), | |
| 'sort_num': next(self.counter) | |
| } | |
| @classmethod | |
| def reset_counter(cls): | |
| cls.counter = count(start=1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from factory import DataFactory | |
| for i in range(6): | |
| for j in range(2): | |
| DataFactory().make() | |
| DataFactory.reset_counter() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment