def test_project_id_not_exists(self):
        """Test for project id which does not exists."""
        archive_project.archive_project(["tuna"])

        fb_db = auth.firebaseDB()
        ref = fb_db.reference("v2/groups/")
        self.assertIsNotNone(ref.get(shallow=True))

        ref = fb_db.reference("v2/tasks/")
        self.assertIsNotNone(ref.get(shallow=True))

        ref = fb_db.reference("v2/results/")
        self.assertIsNotNone(ref.get(shallow=True))
    def test_project_id_not_exists(self):
        """Test for project id which does not exists."""
        archive_project.archive_project(["tuna"])

        time.sleep(1)  # Wait for Firebase Functions to complete

        fb_db = auth.firebaseDB()
        ref = fb_db.reference("v2/groups/")
        self.assertIsNotNone(ref.get(shallow=True))

        ref = fb_db.reference("v2/groupsUsers/")
        self.assertIsNotNone(ref.get(shallow=True))

        ref = fb_db.reference("v2/tasks/")
        self.assertIsNotNone(ref.get(shallow=True))

        ref = fb_db.reference("v2/results/")
        self.assertIsNotNone(ref.get(shallow=True))
    def test_changes(self):
        """Test if groups, tasks and results are deleted from Firebase."""
        archive_project.archive_project([self.project_id])

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

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

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

        pg_db = auth.postgresDB()
        sql_query = "SELECT status FROM projects WHERE project_id = '{}'".format(
            self.project_id)
        result = pg_db.retr_query(sql_query)[0][0]
        self.assertEqual(result, "archived")
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 groups, tasks and results are deleted from Firebase."""
        archive_project.archive_project([self.project_id])

        time.sleep(1)  # Wait for Firebase Functions to complete

        fb_db = auth.firebaseDB()
        ref = fb_db.reference(f"v2/groups/{self.project_id}")
        self.assertIsNone(ref.get())

        ref = fb_db.reference(f"v2/groupsUsers/{self.project_id}")
        self.assertIsNone(ref.get())

        ref = fb_db.reference(f"v2/tasks/{self.project_id}")
        self.assertIsNone(ref.get())

        ref = fb_db.reference(f"v2/results/{self.project_id}")
        self.assertIsNone(ref.get())

        pg_db = auth.postgresDB()
        sql_query = "SELECT status FROM projects WHERE project_id = %s"
        result = pg_db.retr_query(sql_query, [self.project_id])[0][0]
        self.assertEqual(result, "archived")