Beispiel #1
0
def setUpModule():
    """Test module setup."""
    global TEST_CLIENT, TEST_OBJECT_COUNTS

    test_db = ExampleDbSQLite()
    with patch.dict("os.environ", {ENV_CONFIG_FILE: TEST_EXAMPLE_GRAMPS_AUTH_CONFIG}):
        test_app = create_app(db_manager=test_db)
    test_app.config["TESTING"] = True
    TEST_CLIENT = test_app.test_client()
    sqlauth = test_app.config["AUTH_PROVIDER"]
    sqlauth.create_table()
    for role in TEST_USERS:
        sqlauth.add_user(
            name=TEST_USERS[role]["name"],
            password=TEST_USERS[role]["password"],
            role=role,
        )

    db_state = test_app.config["DB_MANAGER"].get_db()
    TEST_OBJECT_COUNTS = {
        "people": db_state.db.get_number_of_people(),
        "families": db_state.db.get_number_of_families(),
        "events": db_state.db.get_number_of_events(),
        "places": db_state.db.get_number_of_places(),
        "citations": db_state.db.get_number_of_citations(),
        "sources": db_state.db.get_number_of_sources(),
        "repositories": db_state.db.get_number_of_repositories(),
        "media": db_state.db.get_number_of_media(),
        "notes": db_state.db.get_number_of_notes(),
        "tags": db_state.db.get_number_of_tags(),
    }
    db_state.db.close()
Beispiel #2
0
 def setUpClass(cls):
     cls.name = "Test Web API"
     cls.dbman = CLIDbManager(DbState())
     _, _name = cls.dbman.create_new_db_cli(cls.name, dbid="sqlite")
     with patch.dict("os.environ", {ENV_CONFIG_FILE: TEST_CONFIG}):
         cls.app = create_app()
     cls.app.config["TESTING"] = True
     cls.client = cls.app.test_client()
Beispiel #3
0
 def setUpClass(cls):
     cls.name = "Test Web API"
     cls.dbman = CLIDbManager(DbState())
     _, _name = cls.dbman.create_new_db_cli(cls.name, dbid="sqlite")
     with patch.dict("os.environ", {ENV_CONFIG_FILE: TEST_AUTH_CONFIG}):
         cls.app = create_app()
     cls.app.config["TESTING"] = True
     cls.client = cls.app.test_client()
     sqlauth = cls.app.config["AUTH_PROVIDER"]
     sqlauth.create_table()
     sqlauth.add_user(name="user", password="******")
 def setUp(self):
     self.name = "Test Web API"
     self.dbman = CLIDbManager(DbState())
     _, _name = self.dbman.create_new_db_cli(self.name, dbid="sqlite")
     with patch.dict("os.environ", {ENV_CONFIG_FILE: TEST_AUTH_CONFIG}):
         self.app = create_app()
     self.app.config["TESTING"] = True
     self.client = self.app.test_client()
     sqlauth = self.app.config["AUTH_PROVIDER"]
     sqlauth.create_table()
     self.ctx = self.app.test_request_context()
     self.ctx.push()
 def setUpClass(cls):
     cls.name = "Test Web API"
     cls.dbman = CLIDbManager(DbState())
     cls.dbman.create_new_db_cli(cls.name, dbid="sqlite")
     with patch.dict("os.environ", {ENV_CONFIG_FILE: TEST_AUTH_CONFIG}):
         cls.app = create_app()
     cls.app.config["TESTING"] = True
     cls.media_base_dir = tempfile.mkdtemp()
     cls.app.config["MEDIA_BASE_DIR"] = cls.media_base_dir
     cls.client = cls.app.test_client()
     sqlauth = cls.app.config["AUTH_PROVIDER"]
     sqlauth.create_table()
     sqlauth.add_user(name="user", password="******", role=ROLE_GUEST)
     sqlauth.add_user(name="admin", password="******", role=ROLE_OWNER)
 def setUpClass(cls):
     cls.name = "Test Web API"
     cls.dbman = CLIDbManager(DbState())
     cls.dbman.create_new_db_cli(cls.name, dbid="sqlite")
     with patch.dict("os.environ", {ENV_CONFIG_FILE: TEST_AUTH_CONFIG}):
         cls.app = create_app()
     cls.app.config["TESTING"] = True
     cls.client = cls.app.test_client()
     sqlauth = cls.app.config["AUTH_PROVIDER"]
     sqlauth.create_table()
     sqlauth.add_user(name="user", password="******", role=ROLE_GUEST)
     sqlauth.add_user(name="contributor", password="******", role=ROLE_CONTRIBUTOR)
     sqlauth.add_user(name="admin", password="******", role=ROLE_OWNER)
     sqlauth.add_user(name="editor", password="******", role=ROLE_EDITOR)
     sqlauth.add_user(name="member", password="******", role=ROLE_MEMBER)
Beispiel #7
0
    def setUpClass(cls):
        cls.name = "Test Web API"
        cls.dbman = CLIDbManager(DbState())
        _, _name = cls.dbman.create_new_db_cli(cls.name, dbid="sqlite")
        cls.config_file = tempfile.NamedTemporaryFile(delete=False)
        cls.user_db = tempfile.NamedTemporaryFile(delete=False)
        config = """TREE="Test Web API"
SECRET_KEY="C2eAhXGrXVe-iljXTjnp4paeRT-m68pq"
USER_DB_URI="sqlite:///{}"
""".format(cls.user_db.name)
        with open(cls.config_file.name, "w") as f:
            f.write(config)
        with patch.dict("os.environ", {ENV_CONFIG_FILE: cls.config_file.name}):
            cls.app = create_app()
        cls.app.config["TESTING"] = True
        cls.client = cls.app.test_client()
        cls.runner = CliRunner()
Beispiel #8
0
 def setUpClass(cls):
     cls.name = "Test Web API"
     cls.dbman = CLIDbManager(DbState())
     _, _name = cls.dbman.create_new_db_cli(cls.name, dbid="sqlite")
     with patch.dict("os.environ", {ENV_CONFIG_FILE: TEST_AUTH_CONFIG}):
         cls.app = create_app()
     cls.app.config["TESTING"] = True
     cls.client = cls.app.test_client()
     sqlauth = cls.app.config["AUTH_PROVIDER"]
     sqlauth.create_table()
     sqlauth.add_user(name="user", password="******", role=ROLE_GUEST)
     sqlauth.add_user(name="admin", password="******", role=ROLE_OWNER)
     dbstate = cls.app.config["DB_MANAGER"].get_db(force_unlock=True)
     with DbTxn("Add test objects", dbstate.db) as trans:
         _add_person(Person.MALE, "John", "Allen", trans, dbstate.db)
         _add_person(
             Person.FEMALE, "Jane", "Secret", trans, dbstate.db, private=True
         )
     dbstate.db.close()
Beispiel #9
0
 def setUp(self):
     self.name = "Test Web API"
     self.dbman = CLIDbManager(DbState())
     _, _name = self.dbman.create_new_db_cli(self.name, dbid="sqlite")
     with patch.dict("os.environ", {ENV_CONFIG_FILE: TEST_AUTH_CONFIG}):
         self.app = create_app()
     self.app.config["TESTING"] = True
     self.client = self.app.test_client()
     sqlauth = self.app.config["AUTH_PROVIDER"]
     sqlauth.create_table()
     sqlauth.add_user(name="user",
                      password="******",
                      email="*****@*****.**",
                      role=ROLE_MEMBER)
     sqlauth.add_user(name="owner",
                      password="******",
                      email="*****@*****.**",
                      role=ROLE_OWNER)
     self.assertTrue(self.app.testing)
     self.ctx = self.app.test_request_context()
     self.ctx.push()
 def setUpClass(cls):
     """Test class setup."""
     cls.name = "empty"
     cls.dbman = CLIDbManager(DbState())
     _, _name = cls.dbman.create_new_db_cli(cls.name, dbid="sqlite")
     cls.dbman.create_new_db_cli(cls.name, dbid="sqlite")
     with patch.dict(
         "os.environ",
         {
             ENV_CONFIG_FILE: TEST_EMPTY_GRAMPS_AUTH_CONFIG,
             "TREE": "empty",
         },
     ):
         cls.test_app = create_app()
     cls.test_app.config["TESTING"] = True
     cls.client = cls.test_app.test_client()
     sqlauth = cls.test_app.config["AUTH_PROVIDER"]
     sqlauth.create_table()
     for role in TEST_USERS:
         sqlauth.add_user(
             name=TEST_USERS[role]["name"],
             password=TEST_USERS[role]["password"],
             role=role,
         )
Beispiel #11
0
 def setUp(self):
     self.name = "Test Web API"
     self.dbman = CLIDbManager(DbState())
     _, _name = self.dbman.create_new_db_cli(self.name, dbid="sqlite")
     with patch.dict("os.environ", {ENV_CONFIG_FILE: TEST_AUTH_CONFIG}):
         self.app = create_app()
     self.app.config["TESTING"] = True
     self.client = self.app.test_client()
     sqlauth = self.app.config["AUTH_PROVIDER"]
     sqlauth.create_table()
     sqlauth.add_user(name="user",
                      password="******",
                      email="*****@*****.**",
                      role=ROLE_MEMBER)
     sqlauth.add_user(name="admin",
                      password="******",
                      email="*****@*****.**",
                      role=ROLE_OWNER)
     self.ctx = self.app.test_request_context()
     self.ctx.push()
     rv = self.client.post(BASE_URL + "/token/",
                           json={
                               "username": "******",
                               "password": "******"
                           })
     self.header_member = {
         "Authorization": f"Bearer {rv.json['access_token']}"
     }
     rv = self.client.post(BASE_URL + "/token/",
                           json={
                               "username": "******",
                               "password": "******"
                           })
     self.header_owner = {
         "Authorization": f"Bearer {rv.json['access_token']}"
     }