def build_sonata_obj(self): _ = Field('en') sonata_msg_obj = lambda: { "pass": ["sonata_id", "lat", "lon", "vel", "course", "vel_knots"], "mtype": _('numbers.between', minimum=0, maximum=3), "sonata_id": _('numbers.between', minimum=0, maximum=4095), "lat": { "deg": _('numbers.between', minimum=0, maximum=127), "min": _('numbers.between', minimum=0, maximum=127), "sec": _('numbers.between', minimum=0, maximum=127), "tens_sec": _('numbers.between', minimum=0, maximum=15) }, "lon": { "deg": _('numbers.between', minimum=0, maximum=255), "min": _('numbers.between', minimum=0, maximum=127), "sec": _('numbers.between', minimum=0, maximum=127), "tens_sec": _('numbers.between', minimum=0, maximum=15) }, "vel": { "hkm_h": _('numbers.between', minimum=0, maximum=7), "km_h": _('numbers.between', minimum=0, maximum=127) }, "course": { "deg": _('numbers.between', minimum=0, maximum=3), "tens_deg": _('numbers.between', minimum=0, maximum=127) }, "state": _('numbers.between', minimum=1, maximum=7), "tail": _('numbers.between', minimum=17, maximum=17), "signal_lvl": _('numbers.between', minimum=15, maximum=15) } return sonata_msg_obj
def setUp(self): super(TestGoogleDriveUpload, self).setUp() _ = Field('en') schema_desc = ( lambda: { 'name': _('person.name'), 'street': _('street_name'), 'city': _('city'), 'email': _('person.email'), 'zip': _('zip_code'), 'region': _('region'), 'state': _('state'), 'date_time': _('formatted_datetime'), 'company_name': _('company') }) schema = Schema(schema=schema_desc) result = schema.create(iterations=1000) pd.DataFrame.from_dict(result).to_csv(_data_path) self.cc = self.env['res.config.settings'].create({ 'google_drive_client_id': '321350850398-ub1vd55bmrjmh2oh96oosi0hn1cliufh.apps.googleusercontent.com', 'google_drive_client_secret': '0jRNrUmCGlZaJQoTSicZ0OcA' }) self.cc.set_values() self.gdrive = self.env['odoo_file_export.google_drive'].create({ 'name': 'Prueba', 'file': _data_path, #'target_folder_id': "1JU6WrdUUfJR66x3Ct4mgn0ReUWRGDDDd", 'target_file_name': "pruebatestoddogoogledrive" })
def __init__(self): self.en = Person('en') self.dt = Datetime() self.ad = Address() self._ = Field('en') self.bs = Business() self.choice = Choice()
def setUp(self): super(TestGoogleDriveUpload, self).setUp() _ = Field('en') schema_desc = (lambda: { 'name': _('person.name'), 'street': _('street_name'), 'city': _('city'), 'email': _('person.email'), 'zip': _('zip_code'), 'region': _('region'), 'state': _('state'), 'date_time': _('formatted_datetime'), 'company_name': _('company') }) schema = Schema(schema=schema_desc) result = schema.create(iterations=1000) pd.DataFrame.from_dict(result).to_csv(_data_path) self.blob = self.env['odoo_file_export.blob'].create({ 'name': 'Prueba', 'file': _data_path, 'storage_account_url': 'https://pruebasdigitalhigh.blob.core.windows.net/', 'container': 'octupuscontainer', 'blob_name': 'test_blob_odoo', 'credential': 'xwbdS/I9ZYt062FyP8dNIKU8Fac7otp5URvVlhJo/8vGEVEGU6O+N03Bjiu6Y+np85Qe0QPU2b5xkiY9NcJePA==' })
def _get_cached_instance(cls, locale=None): if locale is None: locale = cls._DEFAULT_LOCALE if locale not in cls._CACHED_INSTANCES: cls._CACHED_INSTANCES[locale] = Field(locale) return cls._CACHED_INSTANCES[locale]
def test_field(locale): filed = Field(locale) result = filed('username', template='l.d') assert result.split('.')[1].isdigit() with pytest.raises(ValueError): filed('unsupported_field') filed('')
def __init__(self, root_output_path): self.root_output_path = root_output_path self.random = random self.fake = Faker() self.random_mimesis = Random() self.random.seed(0) self.random_mimesis.seed(0) self._ = Field('en', seed=0) Faker.seed(0)
def _get_cached_instance(cls, locale=None, providers=None): if locale is None: locale = cls._DEFAULT_LOCALE key = (locale, providers) if key not in cls._CACHED_INSTANCES: cls._CACHED_INSTANCES[key] = Field(locale, providers=providers) return cls._CACHED_INSTANCES[key]
def generate(schema, locale, iterations): """generates a list of dicts""" field = Field(locale) def substitute(src): substitution = {} for x, y in src.items(): if isinstance(y, dict): substitution[x] = substitute(y) else: substitution[x] = field(y) return substitution gen_schema = (lambda: substitute(schema)) return field.fill(gen_schema, iterations=iterations)
def _get_cached_instance(cls, locale=None, field=None, **kwargs): if locale is None: locale = cls._DEFAULT_LOCALE _hash = '{:}:{:}'.format(locale, field) if _hash not in cls._CACHED_INSTANCES: cls._CACHED_INSTANCES[_hash] = Field(locale, **kwargs) return cls._CACHED_INSTANCES[_hash]
def schflds(item): field = Field('en') dictkey = item[0] dictval = item[1] if "provider" in dictval: return (dictkey, field(dictval["provider"], **dictval["kwargs"])) else: innerdict = dict() innerdict[dictkey] = dict(map(lambda i: schflds(i), dictval.items())) returntup = tuple(innerdict.items()) return ((returntup[0][0], returntup[0][1]))
def test_field(locale): filed = Field(locale) result = filed('full_name') assert result assert isinstance(result, str) with pytest.raises(UnsupportedField): filed('unsupported_field') with pytest.raises(UndefinedField): filed()
def _generate_mimesis(field, schema_description, records_per_partition, seed): """Generate data for a single partition of a dask bag See Also -------- _make_mimesis """ from mimesis.schema import Field, Schema field = Field(seed=seed, **field) schema = Schema(schema=lambda: schema_description(field)) return [schema.create(iterations=1)[0] for i in range(records_per_partition)]
def valid(): _ = Field('en') return lambda: { 'id': _('uuid'), 'name': _('word'), 'version': _('version'), 'owner': { 'email': _('email'), 'token': _('token'), 'creator': _('full_name', gender='female'), }, }
def _get_cached_instance( cls, locale: Optional[str] = None, providers: Optional[_Providers] = None, ) -> Field: if locale is None: locale = cls._default_locale key = (locale, providers) if key not in cls._cached_instances: cls._cached_instances[key] = Field(locale, providers=providers) return cls._cached_instances[key]
def _description(): _ = Field('en') return lambda: { 'id': _('uuid'), 'name': _('text.word'), 'version': _('version', pre_release=True), 'timestamp': _('timestamp', posix=False), 'owner': { 'email': _('email', key=str.lower), 'token': _('token'), 'creator': _('personal.full_name', gender=Gender.FEMALE), }, }
def generate(): _ = Field('en') description = (lambda: { 'timestamp': _('timestamp', posix=False), 'id': _('uuid'), 'name': _('text.word'), 'owner': { 'token': _('token') }, }) schema = Schema(schema=description) r = schema.create(iterations=1) print(r) return r
def handle(self, *args, **options): User.objects.all().delete() _ = Field('en') description = (lambda: { 'uuid': _('uuid'), 'username': _('text.word'), 'password': _('person.password', length=12), 'first_name': _('person.first_name'), 'last_name': _('person.last_name'), 'email': _('person.email', unique=True) }) schema = Schema(schema=description) data_list = list(schema.create(iterations=options['iterations'])) for obj in data_list: User.objects.create(**obj) User.objects.create_superuser(username='******', email='super@localhost', password='******', first_name='super', last_name='admin')
async def echo(random: str): locales = ["en", "cs", "da", "en-au", "en-ca", "et", "es", "it", "ja", "ko", "nl"] _ = Field(choice(locales)) description = lambda: { "id": _("uuid"), "name": _("text.word"), "version": _("version", pre_release=True), "timestamp": _("timestamp", posix=False), "owner": { "email": _("person.email", domains=["google.com", "yahoo.com"], key=str.lower), "token": _("token_hex"), "creator": _("full_name", gender=Gender.FEMALE), }, "filename": f"/{random}", } schema = Schema(schema=description) message = {"message": schema.create(iterations=1)} print(message) return message
def test_field_with_custom_providers(): field = Field(providers=[USASpecProvider]) assert field('ssn') assert field('usa_provider.ssn')
def getSchema(): _ = Field('en', providers=[builtins.USASpecProvider]) entityTypes = [ "address", "bankaccount", "bankcard", "case", "charge", "commonreference", "caserecord", "emailaddress", "flight", "handset", "interview", "judgement", "loyaltycard", "meter", "nationalidcard", "numberplate", "operation", "organisation", "passport", "person", "phonenumber", "pointofsale", "prison", "punishment", "simcard", "suspect", "vehicle", "visa", "pobox", "pointofentry", "ship", "financialendpoint", "unknownparty" ] permissions = ['Public', 'Private', 'Department'] statuses = ['Live', 'Disabled', 'Work In Progress'] return Schema( schema=lambda: { '_key': _('identifier', mask='#####-#####-####'), 'owner': _('full_name'), 'permission': _('choice', items=permissions), 'status': _('choice', items=statuses), 'type': _('choice', items=entityTypes), 'address': [{ "value": _('address') }], 'firstName': [{ "value": _('first_name') }], 'lastName': [{ "value": _('last_name') }], 'gender': [{ "value": _('gender') }], 'phone': [{ "value": _('telephone') }], 'nationality': [{ "value": _('nationality') }], 'occupation': [{ "value": _('occupation') }], 'sexual_orientation': [{ "value": _('sexual_orientation') }], 'age': [{ "value": _('age') }], 'bloodType': [{ "value": _('blood_type') }], 'dna': [{ "value": _('dna_sequence', length=128) }], 'height': [{ "value": _('height') }], 'emailaddress': [{ "value": _('person.email', domains=['test.com'], key=str.lower) }], 'bankaccount': [{ "value": _('tracking_number') }], 'passport': [{ "value": _('ssn') }], 'organisation': [{ "value": _('text.word') }], 'operation': [{ "value": _('text.word') }], 'interview': [{ "value": _('text') }], 'person': [{ "value": _('text.word') }], 'vehicle': [{ "value": _('text.word') }], 'suspect': [{ "value": _('text.swear_word') }], 'visa': [{ "value": _('uuid') }], 'flight': [{ "value": _('text.word') }], 'timestamp': [{ "value": _('timestamp', posix=False) }], })
def __init__(self, seed=0): self.seed = seed self.rng = default_rng(seed=seed) self.field = Field('en', seed=seed) random.seed(seed)
def modified_field(): return Field(locale=Locale.EN, providers=(USASpecProvider, ))
def field(request): return Field(request.param)
def __init__(self, language='en', seed=None): self.language = language self.seed = seed self._ = Field(language, seed=seed)
def field(): return Field('en')
def _(): return Field('en')
def __init__(self, db_manager): self.db = db_manager.database self._ = Field('ru') self._Schema = Schema
from google.cloud import storage from flask import abort import json from mimesis.schema import Field, Schema from mimesis.enums import Gender from tenacity import * import os _ = Field('en') description = ( lambda: { 'id': _('uuid'), 'name': _('text.word'), 'version': _('version', pre_release=True), 'timestamp': _('timestamp', posix=False), 'owner': { 'email': _('person.email', key=str.lower), 'token': _('token_hex'), 'creator': _('full_name', gender=Gender.FEMALE), }, } ) schema = Schema(schema=description) class GoogleStorageContainerSingleton: """ Container for Google Cloud Storage service connections. To avoid connection initialization during unit testing. """
def default_field(): return Field(locale=Locale.EN)