Skip to content

Commit

Permalink
modify conftest.py and fixtures.sql to insert data to every table for…
Browse files Browse the repository at this point in the history
… fixture
  • Loading branch information
Mustaballer committed Jul 22, 2023
1 parent 644c83a commit 653e785
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
37 changes: 33 additions & 4 deletions assets/fixtures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,36 @@

-- Insert sample recordings
INSERT INTO recording (timestamp, monitor_width, monitor_height, double_click_interval_seconds, double_click_distance_pixels, platform, task_description)
VALUES
('2023-06-28 10:15:00', 1920, 1080, 0.5, 10, 'Windows', 'Task 1'),
('2023-06-29 14:30:00', 1366, 768, 0.3, 8, 'Mac', 'Task 2'),
('2023-06-30 09:45:00', 2560, 1440, 0.7, 12, 'Linux', 'Task 3');
VALUES
(1689889605.9053426, 1920, 1080, 0.5, 4, 'win32', 'type l');

-- Insert sample action_events
INSERT INTO action_event (name, timestamp, recording_timestamp, screenshot_timestamp, window_event_timestamp, mouse_x, mouse_y, mouse_dx, mouse_dy, mouse_button_name, mouse_pressed, key_name, key_char, key_vk, canonical_key_name, canonical_key_char, canonical_key_vk, parent_id, element_state)
VALUES
('press', 1690049582.7713714, 1689889605.9053426, 1690049582.7686925, 1690049556.2166219, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'l', '76', NULL, 'l', NULL, NULL, 'null'),
('release', 1690049582.826782, 1689889605.9053426, 1690049582.7686925, 1690049556.2166219, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'l', '76', NULL, 'l', NULL, NULL, 'null');

-- Insert sample screenshots
INSERT INTO screenshot (recording_timestamp, timestamp, png_data)
VALUES
(1689889605.9053426, 1690042711.774856, x'89504E470D0A1A0A0000000D49484452000000010000000108060000009077BF8A0000000A4944415408D7636000000005000000008D2B4233000000000049454E44AE426082');
-- PNG data represents a 1x1 pixel image with a white pixel

-- Insert sample window_events
INSERT INTO window_event (recording_timestamp, timestamp, state, title, left, top, width, height, window_id)
VALUES
(1689889605.9053426, 1690042703.7413292, '{"title": "recording.txt - openadapt - Visual Studio Code", "left": -9, "top": -9, "width": 1938, "height": 1048, "meta": {"class_name": "Chrome_WidgetWin_1", "control_id": 0, "rectangle": {"left": 0, "top": 0, "right": 1920, "bottom": 1030}, "is_visible": true, "is_enabled": true, "control_count": 0}}', 'recording.txt - openadapt - Visual Studio Code', -9, -9, 1938, 1048, '0');

-- Insert sample performance_stats
INSERT INTO performance_stat (recording_timestamp, event_type, start_time, end_time, window_id)
VALUES
(1689889605.9053426, 'action', 1690042703, 1690042711, 1),
(1689889605.9053426, 'action', 1690042712, 1690042720, 1);
-- Add more rows as needed for additional performance_stats

-- Insert sample memory_stats
INSERT INTO memory_stat (recording_timestamp, memory_usage_bytes, timestamp)
VALUES
(1689889605.9053426, 524288, 1690042703),
(1689889605.9053426, 1048576, 1690042711);
-- Add more rows as needed for additional memory_stats
24 changes: 14 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import os
import pytest

from sqlalchemy import create_engine, text
import pytest

from openadapt.config import ROOT_DIRPATH
from openadapt.config import RECORDING_DIRECTORY_PATH, ROOT_DIRPATH
from openadapt.models import db


@pytest.fixture(scope="session")
def setup_database(request):
# Create a new database or connect to an existing one
db_url = ROOT_DIRPATH / "temp.db"
engine = create_engine(
f"sqlite:///{db_url}"
)
db_url = RECORDING_DIRECTORY_PATH / "recording.db"
engine = create_engine(f"sqlite:///{db_url}")

# Create the database tables (if necessary)
db.Base.metadata.create_all(bind=engine)

# Read the SQL file and execute the statements to seed the database
with open(ROOT_DIRPATH / 'assets/fixtures.sql', 'r') as file:
statements = file.read()
# Read the SQL file and split the content into individual statements
with open(ROOT_DIRPATH / "assets/fixtures.sql", "r") as file:
statements = file.read().split(";")

# Remove any empty statements from the list
statements = [stmt.strip() for stmt in statements if stmt.strip()]

# Execute each statement one at a time
with engine.connect() as connection:
connection.execute(text(statements))
for statement in statements:
connection.execute(text(statement))

# Define the teardown function
def teardown():
Expand Down

0 comments on commit 653e785

Please sign in to comment.