-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconftest.py
76 lines (60 loc) · 3.32 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import sqlite3
from pathlib import Path
import pytest
from flask.helpers import get_root_path
@pytest.fixture(scope="session")
def tests_root():
return get_root_path("tests")
@pytest.fixture(scope="session")
def searchable_db_path():
return str(Path(get_root_path("tests"), "AppData", "searchable_db"))
@pytest.fixture(autouse=True)
def create_mozilla_data(tmpdir):
db_path = str(Path(tmpdir, "test_mozilla.sqlite"))
with sqlite3.connect(db_path) as conn:
cur = conn.cursor()
try:
cur.execute(
"""CREATE TABLE IF NOT EXISTS moz_places ( id INTEGER, url LONGVARCHAR, title LONGVARCHAR, rev_host LONGVARCHAR, visit_count INTEGER DEFAULT 0, hidden INTEGER DEFAULT 0 NOT NULL, typed INTEGER DEFAULT 0 NOT NULL, frecency INTEGER DEFAULT -1 NOT NULL, last_visit_date INTEGER , guid TEXT, foreign_count INTEGER DEFAULT 0 NOT NULL, url_hash INTEGER DEFAULT 0 NOT NULL , description TEXT, preview_image_url TEXT, origin_id INTEGER REFERENCES moz_origins(id))"""
)
except sqlite3.OperationalError:
pass
cur.execute(
"""INSERT INTO moz_places VALUES ("13", "https://www.linuxmint.com/start/tessa/", "Start Page - Linux Mint", "moc.tnimxunil.www.", "7", "0", "0", "37", "1547771594938637", "FJ1OyVWgG0Zb", "0", "47360064011053", "", "", "8")"""
)
cur.execute(
"""INSERT INTO moz_places VALUES("1", "https://support.mozilla.org/en-US/products/firefox", " ", "gro.allizom.troppus.", "0", "0", "0", "20", " ", "OH2P1G22WscA", "1", "47357795150914", "", "", "1")"""
)
cur.execute(
"""INSERT INTO moz_places VALUES("1", "https://support.mozilla.org/en-US/products/firefox", " ", "gro.allizom.troppus.", "0", "0", "0", "20", " ", "OH2P1G22WscA", "1", "478687686807678876867357795150914", "", "", "1")"""
)
with sqlite3.connect(db_path) as conn:
cur = conn.cursor()
cur.execute(
"""CREATE TABLE IF NOT EXISTS moz_origins ( id INTEGER, prefix TEXT NOT NULL, host TEXT NOT NULL, frecency INTEGER NOT NULL)"""
)
cur.execute(
"""INSERT INTO moz_origins VALUES("1", "https://", "support.mozilla.org", "280")"""
)
return db_path
@pytest.fixture(autouse=True)
def create_chromium_data(tmpdir):
db_path = str(Path(tmpdir, "test_chromium"))
with sqlite3.connect(db_path) as conn:
cur = conn.cursor()
cur.execute(
"""CREATE TABLE IF NOT EXISTS urls(id INTEGER, url LONGVARCHAR,title LONGVARCHAR,visit_count INTEGER DEFAULT 0 NOT NULL,typed_count INTEGER DEFAULT 0 NOT NULL,last_visit_time INTEGER NOT NULL,hidden INTEGER DEFAULT 0 NOT NULL)"""
)
cur.execute(
"""INSERT INTO urls VALUES ("88", "https://www.google.com/search?q=chrome+linux+profile+data&oq=chrome+linux+profile+data&aqs=chrome..69i57j33l4.3443j0j7&sourceid=chrome&ie=UTF-8", "chrome linux profile data - Google Search", "1", "0", "13204503690648295", "0")"""
)
return db_path
@pytest.fixture(autouse=True)
def create_fake_non_db_file(tmpdir):
fake_nondb_path = Path(tmpdir, "fake_nondb")
fake_nondb_path.write_bytes(b"0")
return str(fake_nondb_path)
@pytest.fixture(autouse=True)
def create_invalid_filepath(tmpdir):
invalid_filepath = Path(tmpdir, "invalid_filepath")
return str(invalid_filepath)