This repository was archived by the owner on Mar 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtestDataModels.py
102 lines (90 loc) · 3.02 KB
/
testDataModels.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# ***********************************************************************
# * *
# * Copyright (c) 2023 Ondsel *
# * *
# ***********************************************************************
from DataModels import ShareLinkModel, VersionModel
from PySide.QtCore import Qt
if __name__ == "__main__":
# Test the ShareLinkModel
# Create a test dataset
data = [
{
"shortName": "FirstShareLink",
"url": "https://example.com/v1",
"created": "2023-01-01",
"active": True,
},
{
"shortName": "SecondShareLink",
"url": "https://example.com/v2",
"created": "2023-02-01",
"active": False,
},
{
"shortName": "ThirdShareLink",
"url": "https://example.com/v3",
"created": "2023-03-01",
"active": True,
},
]
# Create the model
model = ShareLinkModel(data)
# Verify the model's data
for row in range(model.rowCount()):
for column in range(model.columnCount(None)):
index = model.index(row, column)
item_data = model.data(index, Qt.DisplayRole)
print(f"Data at [{row}, {column}]: {data}")
# Add a new link
new_link_data = {
"shortName": "Fourth",
"url": "https://example.com/v4",
"created": "2023-04-01",
"active": False,
}
if model.addLink(new_link_data):
print("New link added successfully.")
else:
print("Failed to add new link.")
# Update an existing link
updated_link_data = {
"shortName": "RenamedShortname",
"url": "https://example.com/v2.1",
"created": "2023-02-15",
"active": True,
}
if model.updateLink(model.index(1, 0), updated_link_data):
print("link updated successfully.")
else:
print("Failed to update link.")
# Test the VersionModel
# Create a test dataset
data = [
{
"created": "2023-01-01",
"uniqueName": "xczvmnxoiweurlsdkja3247",
},
{
"created": "2023-02-01",
"uniqueName": "wouencx,nvowodkjf",
},
{
"created": "2023-03-01",
"uniqueName": "adkjdlskajlskfsj",
},
]
# Create the model
model = VersionModel(data)
# Verify the model's data
for row in range(model.rowCount()):
for column in range(model.columnCount(None)):
index = model.index(row, column)
item_data = model.data(index, Qt.DisplayRole)
print(f"Data at [{row}, {column}]: {data}")
# Add a new version
new_version_data = {"created": "2023-04-01", "uniqueName": "aldjfljdlskjdsflkjf"}
if model.addVersion(new_version_data):
print("New version added successfully.")
else:
print("Failed to add new version.")