<s> import logging <EOL> import json <EOL> import datetime <EOL> import random <EOL> import operator <EOL> import uuid <EOL> try : <EOL> from . test_config import test_config <EOL> except SystemError : <EOL> from test_config import test_config <EOL> except ImportError : <EOL> from test_config import test_config <EOL> from time import sleep <EOL> class RandomTestData : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self ) : <EOL> self . logger = logging . getLogger ( __package__ ) <EOL> self . fields = test_config [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . fields . append ( { '<STR_LIT:name>' : '<STR_LIT:id>' , '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> to_delete = [ ] <EOL> for i , field in enumerate ( self . fields ) : <EOL> if field [ '<STR_LIT:name>' ] == '<STR_LIT>' : <EOL> field [ '<STR_LIT:type>' ] = '<STR_LIT>' <EOL> elif field [ '<STR_LIT:name>' ] . endswith ( '<STR_LIT>' ) : <EOL> to_delete . append ( i ) <EOL> [ self . fields . pop ( i ) for i in to_delete ] <EOL> self . lorem = '''<STR_LIT>''' <EOL> self . lorem_words = self . lorem . split ( ) <EOL> self . date_signs = [ operator . add , operator . sub ] <EOL> def _get_random_solr_date ( self ) : <EOL> date = random . choice ( self . date_signs ) ( datetime . datetime . now ( ) , datetime . timedelta ( days = random . random ( ) * <NUM_LIT:10> ) ) <EOL> return date . utcnow ( ) . isoformat ( ) + '<STR_LIT>' <EOL> def _get_random_words ( self , count = <NUM_LIT:5> ) : <EOL> out = [ ] <EOL> for _ in range ( count ) : <EOL> out . append ( random . choice ( self . lorem_words ) ) <EOL> return out <EOL> def _get_random_string ( self , count = <NUM_LIT:5> ) : <EOL> return "<STR_LIT:U+0020>" . join ( self . _get_random_words ( ) ) <EOL> def _get_random_int ( self , max = <NUM_LIT:100> ) : <EOL> return int ( random . uniform ( <NUM_LIT:1> , max ) ) <EOL> def _get_id_string ( self ) : <EOL> return str ( uuid . uuid4 ( ) ) <EOL> def _get_facet_string ( self ) : <EOL> return str ( random . choice ( self . lorem_words [ : <NUM_LIT:5> ] ) ) <EOL> def get_doc ( self ) : <EOL> doc = { } <EOL> MAP = { <EOL> '<STR_LIT:int>' : self . _get_random_int , <EOL> '<STR_LIT>' : self . _get_random_solr_date , <EOL> '<STR_LIT>' : self . _get_random_string , <EOL> '<STR_LIT:string>' : self . _get_random_string , <EOL> '<STR_LIT>' : self . _get_id_string , <EOL> '<STR_LIT>' : self . _get_facet_string <EOL> } <EOL> for field in self . fields : <EOL> try : <EOL> doc [ field [ '<STR_LIT:name>' ] ] = MAP [ field [ '<STR_LIT:type>' ] ] ( ) <EOL> except KeyError : <EOL> doc [ field [ '<STR_LIT:name>' ] ] = MAP [ '<STR_LIT:string>' ] ( ) <EOL> return doc <EOL> def get_docs ( self , num_docs = <NUM_LIT:50> ) : <EOL> docs = [ ] <EOL> for x in range ( num_docs ) : <EOL> docs . append ( self . get_doc ( ) ) <EOL> return docs </s>
