def test_happy_path(self): """ Ensure the default load/id generation pattern works. """ e = englids.Englids() self.assertEquals(e(), "RuddierJackknivesMap")
def test_custom_files(self): """ Make sure loading our own files works properly. """ e = englids.Englids(nouns=dict_path("four_entries_proper_nouns"), verbs=dict_path("four_entries_proper_nouns"), adjectives=dict_path("four_entries_proper_nouns")) self.assertEquals(e(), 'BobbyJulianJulian')
def test_cycling(self): """ Make sure calling the generator repeatedly will loop back around to the beginning. """ e = englids.Englids(nouns=dict_path("four_entries_proper_nouns"), verbs=dict_path("four_entries_proper_nouns"), adjectives=dict_path("four_entries_proper_nouns")) self.assertEquals(e(), 'BobbyJulianJulian') self.assertEquals(e(), 'VirgilBobbyBuddy') self.assertEquals(e(), 'BuddyVirgilBobby') self.assertEquals(e(), 'JulianBuddyVirgil') self.assertEquals(e(), 'BobbyJulianJulian') self.assertEquals(e(), 'VirgilBobbyBuddy')
def __init__(self, data_dir="./tmp", redis_url="redis://localhost:6379/0", queue_name="exifcleaner", ttl=600): """ Configure the service. data_dir - string, path where files will be stored once they are uploaded. redis_url - string, connection details for the redis server. queue_name - string, name of the RQ queue ttl - integer, number of seconds to keep images around after they are processed. """ config = { # location where files are stored 'data_dir': os.path.abspath(data_dir), # url for connecting to the redis server 'redis_url': redis_url, # a name for the RQ job queue 'queue_name': queue_name, # the number of seconds an image will exist after its processed. 'ttl': ttl, # how long to keep ids around before they expire, in seconds # default is ~ 1 year 'id_lifespan': 31536000 } self._check_config(config) self.config = config self.redis = redis.StrictRedis.from_url(redis_url) self.queue_name = queue_name self.queue = Queue(self.config['queue_name'], connection=self.redis) self.data_dir = self.config['data_dir'] self.id_generator = englids.Englids()
def test_stats(self): """ Check the stats() method """ e = englids.Englids(nouns=dict_path("four_entries_proper_nouns"), verbs=dict_path("four_entries_proper_nouns"), adjectives=dict_path("four_entries_proper_nouns")) expected = { 'nouns': 4, 'adjectives': 4, 'verbs': 4, 'combinations': 64, 'last': None } self.assertEqual(e.stats, expected) expected['last'] = 'BobbyJulianJulian' e() self.assertEqual(e.stats, expected)