-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.py
173 lines (170 loc) · 9.56 KB
/
deploy.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import json
import os
import sys
from playwright.sync_api import expect, Page, TimeoutError as PlaywrightTimeoutError
def test_deploy(page: Page):
page.goto("/libapps/login.php")
page.fill("#s-libapps-email", os.environ.get("USERNAME"))
page.fill("#s-libapps-password", os.environ.get("PASSWORD"))
page.click("#s-libapps-login-button")
libapps_menu = page.locator("#s-lib-app-anchor")
libapps_menu.wait_for()
for item in os.scandir("artifacts"):
page.goto("/libapps/admin")
page.click("#s-lib-app-anchor")
page.click("#s-lib-app-anchor + .s-lib-spring-to-menu a:text('LibGuides')")
if item.name.endswith(".css") or item.name.endswith(".js"):
page.click("#s-lg-admin-command-bar a:text('Admin')")
page.click("#s-lg-admin-command-bar a:text('Look & Feel')")
page.click("#s-lib-admin-tabs a:text('Custom JS/CSS')")
page.click("#s-lg-include-files_link")
page.set_input_files("#include_file", item.path)
elif item.name.endswith(".html"):
target = item.name.split("-")[0]
with open(item) as f:
html = f.read()
if target == "template":
page.click("#s-lg-admin-command-bar a:text('Admin')")
page.click("#s-lg-admin-command-bar a:text('Look & Feel')")
page.click("#s-lib-admin-tabs a:text('Page Layout')")
if item.name.split("-")[1] == "guide":
page.click("#s-lib-admin-tabs a:text('Guide')")
page.click("#s-lg-guide-templates_link")
page.click("#select2-chosen-2")
# NOTE template must already exist
# TODO account for template not found condition
page.fill("#s2id_autogen2_search", item.name.split(".")[0])
page.press("#s2id_autogen2_search", "Enter")
# NOTE template takes time to load after select
page.wait_for_load_state("networkidle")
page.fill("#template_code", html)
page.click("#btn-save-template")
# NOTE must wait for success before moving on
page.wait_for_selector("#btn-save-template.btn-success")
if item.name.split("-")[1] == "search":
page.click("#s-lib-admin-tabs a:text('Search')")
page.click("#s-lg-tpl_link")
page.click("#select2-chosen-3")
# NOTE template must already exist
# TODO account for template not found condition
page.fill("#s2id_autogen3_search", item.name.split(".")[0])
page.press("#s2id_autogen3_search", "Enter")
# NOTE template takes time to load after select
page.wait_for_load_state("networkidle")
page.fill("#template_code", html)
page.click("#btn-save-template")
# NOTE must wait for success before moving on
page.wait_for_selector("#btn-save-template.btn-success")
elif target == "widget":
page.click("#s-lg-admin-command-bar a:text('Content')")
page.click("#s-lg-admin-command-bar a:text('Assets')")
page.fill("#name", item.name.split("-", maxsplit=2)[-1].split(".")[0])
page.click("#lg-admin-asset-filter .datatable-filter__button--submit")
try:
page.wait_for_selector(
"#s-lg-admin-datatable-content_info:text('showing 1 to 1 of 1 entries')"
)
page.click("#s-lg-admin-datatable-content a i.fa-edit")
except PlaywrightTimeoutError:
page.click("#s-lg-page-content button:text('Add Content Item')")
page.click("#s-lg-page-content a:text('Media / Widget')")
page.fill(
"#widget_name",
item.name.split("-", maxsplit=2)[-1].split(".")[0],
)
page.fill("#embed_code", html)
page.click("#s-lib-alert-btn-first")
page.wait_for_selector(
"td:text('"
+ item.name.split("-", maxsplit=2)[-1].split(".")[0]
+ "')"
)
elif target == "head":
variant = item.name.split(".")[0].split("-")[-1]
if variant == "system":
page.goto("/libguides/lookfeel.php?action=1")
page.fill("#jscss_code", html)
page.click("#s-lg-btn-save-jscss")
# NOTE must wait for success before moving on
page.wait_for_selector("#s-lg-btn-save-jscss.btn-success")
elif variant == "libanswers":
# NOTE JS/CSS files are uploaded in LibGuides
page.click("#s-lib-app-anchor")
page.click("#s-lib-app-menu a:text('LibAnswers')")
page.click("#s-la-cmd-bar-collapse a:text('Admin')")
page.click("#s-la-cmd-bar-collapse a:text('System Settings')")
page.click(".nav-tabs a:text('Look & Feel')")
page.fill("#instmetafield", html)
page.click("#instmetabut")
# NOTE must wait for success before moving on
page.wait_for_selector("#s-ui-notification :text('Success')")
elif variant == "libcal":
# NOTE JS/CSS files are uploaded in LibGuides
page.click("#s-lib-app-anchor")
page.click("#s-lib-app-menu a:text('LibCal')")
page.click("#s-lc-app-menu-adm a") # Admin
page.click("#s-lc-app-menu-adm a:text('Look & Feel')")
page.fill("#instmeta", html)
page.click("#instmeta ~ button")
else:
for group in json.loads(os.environ.get("GROUPS"))["groups"]:
if variant == group["slug"]:
page.goto(
f'/libguides/groups.php?action=3&group_id={group["id"]}'
)
page.fill("#jscss_code", html)
page.click("#s-lg-btn-save-jscss")
# NOTE must wait for success before moving on
page.wait_for_selector("#s-lg-btn-save-jscss.btn-success")
elif target == "header":
variant = item.name.split(".")[0].split("-")[-1]
if variant == "system":
page.goto("/libguides/lookfeel.php?action=0")
page.fill("#banner_html", html)
page.click("#banner_html + .btn-primary")
# NOTE must wait for success before moving on
expect(page.locator("#jquery-notification-message")).to_have_text("Success!")
# TODO LibAnswers & LibCal
else:
for group in json.loads(os.environ.get("GROUPS"))["groups"]:
if variant == group["slug"]:
page.goto(
f'/libguides/groups.php?action=2&group_id={group["id"]}'
)
page.fill("#banner_html", html)
page.click("#banner_html + .btn-primary")
# NOTE must wait for success before moving on
page.wait_for_selector("#banner_html + .btn-success")
elif target == "footer":
variant = item.name.split(".")[0].split("-")[-1]
if variant == "system":
page.goto("/libguides/lookfeel.php?action=0")
page.click("#s-lg-footer_link")
page.fill("#footer_code", html)
page.click("#s-lg-btn-save-footer")
# NOTE LibAnswers uses the same system footer
page.click("#s-lib-app-anchor")
page.click("#s-lib-app-menu a:text('LibAnswers')")
page.click("#s-la-cmd-bar-collapse a:text('Admin')")
page.click("#s-la-cmd-bar-collapse a:text('System Settings')")
page.click(".nav-tabs a:text('Look & Feel')")
page.fill("#instfooterfield", html)
page.click("#instfooterbut")
# NOTE LibCal uses the same system footer
page.click("#s-la-app-anchor")
page.click("#s-la-app-menu a:text('LibCal')")
page.click("#s-lc-app-menu-adm a") # Admin
page.click("#s-lc-app-menu-adm a:text('Look & Feel')")
page.fill("#footerCode", html)
page.click("#s-lc-code-save")
else:
for group in json.loads(os.environ.get("GROUPS"))["groups"]:
if variant == group["slug"]:
page.goto(
f'/libguides/groups.php?action=2&group_id={group["id"]}'
)
page.click("#s-lg-footer_link")
page.fill("#footer_code", html)
page.click("#s-lg-btn-save-footer")
# NOTE must wait for success before moving on
page.wait_for_selector("#s-lg-btn-save-footer.btn-success")