def test_settings(email, password, zip_code, languages, categories, save, file_name): with mock.patch( "builtins.input", side_effect=[email, zip_code, languages, categories, save] ): with mock.patch("getpass.getpass", return_value=password): settings_path = os.path.join(get_app_dir(), f"test_tmp/{file_name}") settings = Settings(settings_path) assert settings.email == email assert settings.password == password assert settings.zip_code == zip_code assert settings.languages == [] if languages is None else languages assert settings.categories == [] if categories is None else categories if save.upper() == "Y": yaml = YAML() with open(settings_path) as f: settings = yaml.load(f) assert settings["udemy"]["email"] == email assert settings["udemy"]["password"] == password assert settings["udemy"]["zipcode"] == zip_code assert ( settings["udemy"]["languages"] == [] if languages is None else ",".join(languages) ) assert ( settings["udemy"]["categories"] == [] if categories is None else categories ) # Load settings just created Settings(settings_path) else: assert os.path.isdir(settings_path) is False
def __init__(self, settings: Settings, cookie_file_name: str = ".cookie"): self.settings = settings self.user_has_preferences = self.settings.categories or self.settings.languages self.session = requests.Session() self.udemy_scraper = create_scraper() self._cookie_file = os.path.join(get_app_dir(), cookie_file_name) self._enrolled_course_info = [] self._currency_symbol = None self._currency = None
def __init__(self, settings_path="settings.yaml"): self.email = None self.password = None self.zip_code = None self.languages = [] self.categories = [] self._settings_path = os.path.join(get_app_dir(), settings_path) self.is_ci_build = strtobool(os.environ.get("CI_TEST", "False")) self._init_settings()
def __init__(self, delete_settings=False, delete_cookie=False, settings_path="settings.yaml"): self.email = None self.password = None self.zip_code = None self.languages = [] self.categories = [] self._settings_path = os.path.join(get_app_dir(), settings_path) self._cookies_path = os.path.join(get_app_dir(), ".cookie") self._should_store_email = False self._should_store_password = False self.is_ci_build = strtobool(os.environ.get("CI_TEST", "False")) if delete_settings: self.delete_settings() if delete_cookie: self.delete_cookie() self._init_settings()
def __init__(self, file_name="app.log", mode="a"): log_file_path = os.path.join(get_app_dir(), file_name) super(CustomFileHandler, self).__init__(log_file_path, mode)
def __init__(self, file_name=".course_cache"): self._file_name = os.path.join(get_app_dir(), file_name) self._cache = [] self._load_cache()