def cache(repo): """Cache the given repository to reuse later Args: repo: A repository instance """ repositories = get_repo_collection() repo.update_last_latest_hash() repositories.replace_one({'url': repo.url}, repo.to_document(), upsert=True)
def is_cached(repo): """Check if the repository was cached Args: repo: A repository instance Returns: Whether if there is cached one or not """ repositories = get_repo_collection() repo_doc = repositories.find_one({'url': repo.url}) if not repo_doc: return False if repo_doc['last_latest_hash'] != repo.latest_hash: return False return True
def setUp(self): self.repositories = get_repo_collection() self.repo = create_repository('github.com/mingrammer/awesome-finder')