def test_load_file_no_bucket(self): fortunes = FortuneFileImporter(FORTUNE_FILE) i = 0 for f in fortunes.process(): self.assertEqual(f.content, EXPECTED_FORTUNE[i]) #logger.debug(f" e is {f}") self.assertEqual(f.bucket.name, "fishes_fortune") i += 1
def test_load_file_with_bucket(self): bucket_name = "test_data" bucket = Bucket(bucket_id=400, name=bucket_name) fortunes = FortuneFileImporter(FORTUNE_FILE, bucket=bucket) i = 0 for f in fortunes.process(): self.assertEqual(f.content, EXPECTED_FORTUNE[i]) self.assertEqual(f.bucket.name, bucket_name) i += 1
def test_load_directory(self): fortunes = FortuneFileImporter(FORTUNE_FILE_DIR) i = 0 for f in fortunes.process(): i += 1 # I actually have no idea how many fortunes there are buts its more # then 10 self.assertTrue(i > 10)
def test_impression_count_test(self): self.db.add_epigrams_via_importer( FortuneFileImporter('test_data/basic/')) for x in range(32): self.db.get_epigram() self.assertEqual(32, self.db.get_impression_count())
def test_get_buckets(self): self.db.add_epigrams_via_importer( FortuneFileImporter('test_data/basic/')) (fishes, meta) = self.db.get_buckets() self.assertEqual(fishes.name, "fishes_fortune") self.assertEqual(meta.name, "meta_fortune")
def test_add_entire_directory_with_timing(self): start = time.time() self.db.add_epigrams_via_importer( FortuneFileImporter('content/legacy_fortune/')) end = time.time() logger.info(f"Loading 13k ish epigrams took %s" % (end - start)) self.run_test_for_count(1) self.run_test_for_count(10) self.run_test_for_count(100)
def test_multiline_re(self): fishes = ['redfish', 'bluefish', 'onefish\ntwofish', 'something else'] i = 0 for (parsed_message) in \ FortuneFileImporter.process_fortune_file(sample_fortune_file): print("--", parsed_message, "\n") self.assertEqual(fishes[i], parsed_message) i += 1 self.assertEqual(i, 4)
def test_impression_count_meta(self): self.db.add_epigrams_via_importer( FortuneFileImporter('test_data/basic/')) for x in range(1): e: Epigram = self.db.get_epigram(bucket_name="meta_fortune") self.assertEqual(e.bucket_id, 2) self.assertEqual(self.db.get_impression_count(), 1) self.assertEqual( self.db.get_impression_count(bucket_name="meta_fortune"), 1)
def test_unimpressioned(self): self.db.add_epigrams_via_importer( FortuneFileImporter('test_data/basic/')) for x in range(13): self.db.get_epigram() self.assertEqual(13, self.db.get_impression_count()) no_impressions = self.db._session.query(Epigram).filter( Epigram.last_impression_date == None).count() self.assertEqual(1, no_impressions)
def test_impression_count_categories(self): self.db.add_epigrams_via_importer( FortuneFileImporter('test_data/basic/')) for x in range(2): self.db.get_epigram(bucket_name="meta_fortune") for x in range(1): self.db.get_epigram(bucket_name="fishes_fortune") self.assertEqual(3, self.db.get_impression_count()) self.assertEqual( 2, self.db.get_impression_count(bucket_name="meta_fortune")) self.assertEqual( 1, self.db.get_impression_count(bucket_name="fishes_fortune"))
def test_impression_count_meta(self): self.db.add_epigrams_via_importer( FortuneFileImporter('test_data/100pack/')) for x in range(100): e: Epigram = self.db.get_epigram() self.assertEqual(self.db.get_impression_count(bucket_name="bluefish"), 25) self.assertEqual(self.db.get_impression_count(bucket_name="pinkfish"), 25) self.assertEqual(self.db.get_impression_count(bucket_name="redfish"), 25) self.assertEqual(self.db.get_impression_count(bucket_name="greenfish"), 25)
def test_impression_count_weighted(self): self.db.add_epigrams_via_importer( FortuneFileImporter('test_data/100pack/')) bluefish_bucket: Bucket = self.db.get_bucket("bluefish") bluefish_bucket.item_weight = 2 self.db._session.add(bluefish_bucket) # decimals are strange. for x in range(101): e: Epigram = self.db.get_epigram() self.assertEqual(self.db.get_impression_count(bucket_name="bluefish"), 41) self.assertEqual(self.db.get_impression_count(bucket_name="redfish"), 20) self.assertEqual(self.db.get_impression_count(bucket_name="greenfish"), 20) self.assertEqual(self.db.get_impression_count(bucket_name="pinkfish"), 20)
def test_defined_bucket(self): bucket_name = "test_data" bucket = Bucket(bucket_id=400, name=bucket_name) fortunes = FortuneFileImporter(FORTUNE_FILE, bucket=bucket) self.assertEqual(fortunes._bucket.name, bucket.name)
def test_default_bucket(self): """ The bucket will be defined for each file, so this is None""" fortunes = FortuneFileImporter(FORTUNE_FILE) self.assertEqual(fortunes._bucket, None)
def test_nonexistent_file(self): self.assertRaises( AttributeError, lambda: FortuneFileImporter(uri='/some/fake/path/to/a/file'))
def test_get_bucket(self): self.db.add_epigrams_via_importer( FortuneFileImporter('test_data/basic/')) fishes = self.db.get_bucket("fishes_fortune") self.assertEqual(fishes.name, "fishes_fortune")