class TestAtomFeedManager(unittest.TestCase): def setUp(self): self.session = sessionmaker(bind=engine)() self.atom_feed_manager = AtomFeedManager(self.session, fixture_directory, Feed, FeedEntry) self.files_to_clean = [] def tearDown(self): for file_to_clean in self.files_to_clean: if os.path.isfile(file_to_clean): os.remove(file_to_clean) self.session.rollback() self.session.close() def test_current_feed(self): current_feed_id = self.session.query(func.max(Feed.id)).scalar() self.assertEqual(current_feed_id, self.atom_feed_manager.current_feed.id) def test_get_from_archive(self): feed_id = self.atom_feed_manager.current_feed.id archive_content = 'some xml string' feed_path = fixture_directory + '/' + str(feed_id) + '.xml' with open(feed_path, 'w') as rec_file: rec_file.write(archive_content) self.files_to_clean.append(feed_path) response = self.atom_feed_manager.get_from_archive(feed_id) self.assertEqual(archive_content, response) def test_fail_to_not_existing_from_archive(self): feed_id = '999' with self.assertRaises(FeedArchiveNotFound): self.atom_feed_manager.get_from_archive(feed_id)
def setUp(self): self.session = sessionmaker(bind=engine)() self.atom_feed_manager = AtomFeedManager(self.session, fixture_directory, Feed, FeedEntry) self.files_to_clean = []