Exemplo n.º 1
0
def main():
    """
    Starts the flask application
    :return: None
    """
    load_env_file()
    init_flask("otaku_info", sentry_dsn, root_path, Config, models,
               blueprint_generators)

    start_server(Config, bg_tasks)
Exemplo n.º 2
0
 def test_missing_environment_variables(self):
     """
     Tests if missing environment variables are detected correctly
     :return: None
     """
     os.environ.pop("FLASK_SECRET")
     try:
         init_flask("jerrycan", "", "", self.config, [], [])
         self.fail()
     except SystemExit:
         pass
Exemplo n.º 3
0
 def test_missing_required_template(self):
     """
     Tests if missing template files are detected correctly
     :return: None
     """
     for required in self.config.REQUIRED_TEMPLATES.values():
         path = os.path.join(self.temp_templates_dir, required)
         os.remove(path)
         try:
             init_flask("jerrycan", "", "", self.config, [], [])
             self.fail()
         except SystemExit:
             with open(path, "w") as f:
                 f.write("")
Exemplo n.º 4
0
    def setUp(self):
        """
        Sets up the flask application and a temporary database to test with
        :return: None
        """
        self.user_cred_count = 0
        self.api_cred_count = 0

        self.temp_templates_dir = "templates"
        self.templates_sample_dir = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), "templates")
        os.environ["FLASK_TESTING"] = "1"
        os.environ["DB_MODE"] = "sqlite"
        os.environ["FLASK_SECRET"] = generate_random(20)

        self.cleanup(True)
        if self.module_name == "jerrycan":
            shutil.copytree(self.templates_sample_dir, self.temp_templates_dir)
            os.environ["RECAPTCHA_SITE_KEY"] = ""
            os.environ["RECAPTCHA_SECRET_KEY"] = ""
            os.environ["SMTP_HOST"] = ""
            os.environ["SMTP_PORT"] = "0"
            os.environ["SMTP_ADDRESS"] = ""
            os.environ["SMTP_PASSWORD"] = ""
            os.environ["TELEGRAM_API_KEY"] = ""
        else:
            load_env_file()

        self.config.load_config(self.root_path, self.module_name, "")
        self.db_path = Config.DB_URI.split("sqlite:///")[1]
        self.cleanup(False)

        self.app = app
        self.db = db

        init_flask(self.module_name, "", self.root_path, self.config,
                   self.models, self.blueprint_generators,
                   self.extra_jinja_vars)
        self.app.app_context().push()

        self.client = self.app.test_client()
        self.context = self.app.test_request_context()
Exemplo n.º 5
0
    def test_db_connection_error(self):
        """
        Tests if a database connection error is handled correctly
        :return: None
        """
        class MockDb:
            @staticmethod
            def create_all():
                raise OperationalError("a", "a", "a")

            @staticmethod
            def init_app(app):
                pass

        with patch("jerrycan.initialize.db", MockDb):
            try:
                init_flask("jerrycan", "", "", self.config, [], [])
                self.fail()
            except SystemExit:
                pass
Exemplo n.º 6
0
 def test_no_extra_jinja(self):
     """
     Tests if not providing any additional jinja variables works as intended
     :return: None
     """
     init_flask("jerrycan", "", "", self.config, [], [])