Skip to content

Instantly share code, notes, and snippets.

@njamaleddine
Last active October 29, 2015 19:31
Show Gist options
  • Select an option

  • Save njamaleddine/9b5729e33413285e2cc9 to your computer and use it in GitHub Desktop.

Select an option

Save njamaleddine/9b5729e33413285e2cc9 to your computer and use it in GitHub Desktop.
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