Last active
October 29, 2015 19:31
-
-
Save njamaleddine/9b5729e33413285e2cc9 to your computer and use it in GitHub Desktop.
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
| import random | |
| from faker import Faker | |
| from factory import fuzzy | |
| class FuzzyJSON(fuzzy.BaseFuzzyAttribute): | |
| """ | |
| Fuzzy json class for json data stored in a django JSONField | |
| """ | |
| def __init__(self, json_object={}, randomize=False): | |
| if not randomize: | |
| if len(json_object) > 0: | |
| self.json_object = json.dumps(json_object, indent=4) | |
| else: | |
| self.json_object = json.dumps({}, indent=4) | |
| else: | |
| words = fake.words(nb=random.randint(1, 5)) | |
| self.json_object = {str(index): i for index, i in enumerate(words)} | |
| def fuzz(self): | |
| return self.json_object | |
| def evaluate(self, sequence, obj, create, extra=None, containers=()): | |
| return self.fuzz() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment