def test_user_not_in_postgres(self):
        """Test if results are transfered for users which are not yet in Postgres."""
        pg_db = auth.postgresDB()

        # Make sure user and results are not yet in Postgres
        sql_query = (f"DELETE FROM results "
                     f"WHERE user_id = '{self.project_id}' "
                     f"AND project_id = '{self.project_id}'")
        pg_db.query(sql_query)
        sql_query = "DELETE FROM users WHERE user_id = '{0}'".format(
            self.project_id)
        pg_db.query(sql_query)

        transfer_results()

        sql_query = "SELECT * FROM users WHERE user_id = '{0}'".format(
            self.project_id)
        result = pg_db.retr_query(sql_query)
        self.assertIsNotNone(result)

        sql_query = (f"SELECT * "
                     f"FROM results "
                     f"WHERE project_id = '{self.project_id}' "
                     f"AND user_id = '{self.project_id}'")
        result = pg_db.retr_query(sql_query)
        self.assertIsNotNone(result)
Example #2
0
    def test_invalid_task_in_result(self):
        """Test for results that are not valid.

        In this test the results contain an additional task.
        This should raise a Database error due to a foreign key violation.
        Because results could not be stored in Postgres DB,
        they should also NOT be deleted in Firebase.
        """

        test_dir = os.path.dirname(__file__)
        fixture_name = "build_area_invalid_task.json"
        file_path = os.path.join(test_dir, "fixtures", "tile_map_service_grid",
                                 "results", fixture_name)

        with open(file_path) as test_file:
            test_data = json.load(test_file)

        fb_db = auth.firebaseDB()
        ref = fb_db.reference(f"/v2/results/{self.project_id}")
        ref.set(test_data)

        transfer_results.transfer_results(project_id_list=[self.project_id])

        fb_db = auth.firebaseDB()
        ref = fb_db.reference(
            f"v2/results/{self.project_id}/g115/test_build_area/results")
        self.assertIsNone(ref.get(shallow=True))
def run_archive_project(project_id, project_ids):
    """Archive projects in Postgres. Delete groups, tasks and results from Firebase."""
    if not project_ids and not project_id:
        click.echo("Missing argument")
        return None
    elif not project_ids:
        project_ids = [project_id]
    click.echo("Start archive")
    update_data.update_project_data(project_ids)
    transfer_results.transfer_results(project_ids)
    if archive_project.archive_project(project_ids):
        click.echo("Finished archive")
    def test_changes(self):
        """Test if results are deleted from Firebase for given project id."""
        transfer_results.transfer_results()

        fb_db = auth.firebaseDB()
        ref = fb_db.reference("v2/results/{0}".format(self.project_id))
        self.assertIsNone(ref.get())

        pg_db = auth.postgresDB()
        sql_query = "SELECT * FROM results WHERE project_id = '{0}' and user_id = '{0}'".format(
            self.project_id)
        result = pg_db.retr_query(sql_query)
        self.assertIsNotNone(result)
    def test_changes_given_project_id(self):
        """Test if results are deleted from Firebase for given project id."""
        transfer_results(project_id_list=[self.project_id])

        fb_db = auth.firebaseDB()
        ref = fb_db.reference("v2/results/{0}".format(self.project_id))
        self.assertIsNone(ref.get())

        pg_db = auth.postgresDB()
        sql_query = (f"SELECT * "
                     f"FROM results "
                     f"WHERE project_id = '{self.project_id}' "
                     f"AND user_id = '{self.project_id}'")
        result = pg_db.retr_query(sql_query)
        self.assertIsNotNone(result)
def run_firebase_to_postgres() -> list:
    """Update users and transfer results from Firebase to Postgres."""
    update_data.update_user_data()
    update_data.update_project_data()
    project_ids = transfer_results.transfer_results()
    for project_id in project_ids:
        send_progress_notification(project_id)
    return project_ids
def run_firebase_to_postgres(project_ids: list) -> list:
    """Update users and transfer results from Firebase to Postgres."""

    if len(project_ids) > 0:
        project_ids_transferred = transfer_results.transfer_results(
            project_ids)
    else:
        project_ids_transferred = transfer_results.transfer_results()

    if len(project_ids_transferred) > 0:
        for project_id in project_ids_transferred:
            update_data.set_progress_in_firebase(project_id)
            update_data.set_contributor_count_in_firebase(project_id)
            send_progress_notification(project_id)

    update_data.update_project_data()

    return project_ids