Exemple #1
0
    def test__task_init_with_no_params__runs_when_params_passed_to_run(
            self, db):
        task = tasks.SQLiteExecuteMany(db=db)
        with Flow(name="Flow") as f:
            query = (
                "INSERT INTO RawDayData (userid, date, rawdaydata) VALUES (?, ?, ?);"
            )
            data = [
                ("*****@*****.**", "2020-12-30", "[{}]"),
                ("*****@*****.**", "2020-12-31", "[{}]"),
            ]
            task_result = task(query=query, data=data)
            select_result = SQLiteQuery(
                db=db,
                query=
                "SELECT * FROM RawDayData WHERE userid = '*****@*****.**';",
            )()

        out = f.run()

        assert out.is_successful()
        result = out.result[select_result].result
        assert result == [
            ("*****@*****.**", "2020-12-30", "[{}]"),
            ("*****@*****.**", "2020-12-31", "[{}]"),
        ]
Exemple #2
0
    def test__run__when_query_not_provided_and_not_available__raises_ValueError(
            self, db):
        data = [("*****@*****.**", "2020-12-01", 0.0)]
        task = tasks.SQLiteExecuteMany(db=db, data=data)

        with pytest.raises(ValueError,
                           match="A query string must be provided"):
            task.run()
Exemple #3
0
    def test__task_run_with_enforce_fk__cascade_deletes_data(self, db):
        task = tasks.SQLiteExecuteMany(db=db)
        query = "DELETE FROM RawDayData WHERE userid = ? AND date = ?;"
        data = [
            ("*****@*****.**", "2021-01-01"),
            ("*****@*****.**", "2021-01-02"),
        ]
        with Flow(name="Flow") as f:
            task_result = task(query=query, data=data, enforce_fk=True)
            select_result = SQLiteQuery(
                db=db,
                query="SELECT * FROM Water WHERE userid = '*****@*****.**';",
            )()

        out = f.run()

        assert out.is_successful()
        result = out.result[select_result].result
        assert result == [
            ("*****@*****.**", "2021-01-03", 2230.5),
        ]
Exemple #4
0
 def test__init__with_no_params__initializes_task(self):
     task = tasks.SQLiteExecuteMany()
     assert task
Exemple #5
0
 def test__run__when_data_not_provided_and_not_available__raises_ValueError(
         self, db):
     query = "INSERT INTO Water (userid, date, quantity) VALUES ('*****@*****.**', '2020-12-01', 1.1);"
     task = tasks.SQLiteExecuteMany(db=db, query=query)
     with pytest.raises(ValueError, match="A data list must be provided"):
         task.run()