-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Final tranche of Toolproof Python API tests to meet Node API parity
- Loading branch information
Showing
7 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...integration_tests/python_api/py-build-a-synthetic-index-to-disk-via-the-api.toolproof.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Python API > Build a synthetic index to disk via the api | ||
platforms: | ||
- linux | ||
- mac | ||
|
||
steps: | ||
- ref: ./background.toolproof.yml | ||
- step: I have a "public/run.py" file with the content {python} | ||
python: |2- | ||
import sys | ||
sys.path.append('%repo_wd%/wrappers/python/src') | ||
import asyncio | ||
import json | ||
import logging | ||
import os | ||
from pagefind.index import PagefindIndex, IndexConfig | ||
async def main(): | ||
async with PagefindIndex() as index: | ||
await index.add_html_file( | ||
content="<html><body><h1>Testing, testing</h1></body></html>", | ||
source_path="dogs/index.html", | ||
) | ||
print("Complete") | ||
if __name__ == "__main__": | ||
asyncio.run(main()) | ||
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py" | ||
- step: stdout should contain "Complete" | ||
- step: The file "public/pagefind/pagefind.js" should not be empty | ||
- step: I serve the directory "public" | ||
- step: In my browser, I load "/" | ||
- step: In my browser, I evaluate {js} | ||
js: |- | ||
let pagefind = await import("/pagefind/pagefind.js"); | ||
let search = await pagefind.search("testing"); | ||
let data = await search.results[0].data(); | ||
toolproof.assert_eq(data.url, `/dogs/`); | ||
- step: In my browser, the console should be empty |
43 changes: 43 additions & 0 deletions
43
...hon_api/py-build-a-synthetic-index-with-overridden-urls-to-disk-via-the-api.toolproof.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Python API > Build a synthetic index with overridden urls to disk via the api | ||
|
||
platforms: | ||
- linux | ||
- mac | ||
|
||
steps: | ||
- ref: ./background.toolproof.yml | ||
- step: I have a "public/run.py" file with the content {python} | ||
python: |2- | ||
import sys | ||
sys.path.append('%repo_wd%/wrappers/python/src') | ||
import asyncio | ||
import json | ||
import logging | ||
import os | ||
from pagefind.index import PagefindIndex, IndexConfig | ||
async def main(): | ||
async with PagefindIndex() as index: | ||
await index.add_html_file( | ||
content="<html><body><h1>Testing, testing</h1></body></html>", | ||
url="/my-custom-url/", | ||
) | ||
print("Complete") | ||
if __name__ == "__main__": | ||
asyncio.run(main()) | ||
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py" | ||
- step: stdout should contain "Complete" | ||
- step: The file "public/pagefind/pagefind.js" should not be empty | ||
- step: I serve the directory "public" | ||
- step: In my browser, I load "/" | ||
- step: In my browser, I evaluate {js} | ||
js: |- | ||
let pagefind = await import("/pagefind/pagefind.js"); | ||
let search = await pagefind.search("testing"); | ||
let data = await search.results[0].data(); | ||
toolproof.assert_eq(data.url, `/my-custom-url/`); | ||
- step: In my browser, the console should be empty |
47 changes: 47 additions & 0 deletions
47
...find/integration_tests/python_api/py-build-a-true-index-to-disk-via-the-api.toolproof.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Python API > Build a true index to disk via the api | ||
platforms: | ||
- linux | ||
- mac | ||
|
||
steps: | ||
- ref: ./background.toolproof.yml | ||
- step: >- | ||
I have a "public/custom_files/real/index.html" file with the content | ||
{html} | ||
html: >- | ||
<!DOCTYPE html><html lang="en"><head></head><body> <p>A testing file that | ||
exists on disk</p></body></html> | ||
- step: I have a "public/run.py" file with the content {python} | ||
python: |2- | ||
import sys | ||
sys.path.append('%repo_wd%/wrappers/python/src') | ||
import asyncio | ||
import json | ||
import logging | ||
import os | ||
from pagefind.index import PagefindIndex, IndexConfig | ||
async def main(): | ||
async with PagefindIndex() as index: | ||
await index.add_directory( | ||
path="custom_files", | ||
) | ||
print("Complete") | ||
if __name__ == "__main__": | ||
asyncio.run(main()) | ||
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py" | ||
- step: stdout should contain "Complete" | ||
- step: The file "public/pagefind/pagefind.js" should not be empty | ||
- step: I serve the directory "public" | ||
- step: In my browser, I load "/" | ||
- step: In my browser, I evaluate {js} | ||
js: |- | ||
let pagefind = await import("/pagefind/pagefind.js"); | ||
let search = await pagefind.search("testing"); | ||
let data = await search.results[0].data(); | ||
toolproof.assert_eq(data.url, `/real/`); | ||
- step: In my browser, the console should be empty |
50 changes: 50 additions & 0 deletions
50
...on_tests/python_api/py-build-an-index-to-a-custom-disk-location-via-the-api.toolproof.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Python API > Build an index to a custom disk location via the api | ||
platforms: | ||
- linux | ||
- mac | ||
|
||
steps: | ||
- ref: ./background.toolproof.yml | ||
- step: I have a "output/index.html" file with the content {html} | ||
html: >- | ||
<!DOCTYPE html><html lang="en"><head></head><body> <p | ||
data-url>Nothing</p></body></html> | ||
- step: I have a "public/run.py" file with the content {python} | ||
python: |2- | ||
import sys | ||
sys.path.append('%repo_wd%/wrappers/python/src') | ||
import asyncio | ||
import json | ||
import logging | ||
import os | ||
from pagefind.index import PagefindIndex, IndexConfig | ||
async def main(): | ||
config = IndexConfig( | ||
output_path="../output/pagefind", | ||
) | ||
async with PagefindIndex(config=config) as index: | ||
await index.add_html_file( | ||
content="<html><body><h1>Testing, testing</h1></body></html>", | ||
source_path="dogs/index.html", | ||
) | ||
print("Complete") | ||
if __name__ == "__main__": | ||
asyncio.run(main()) | ||
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py" | ||
- step: stdout should contain "Complete" | ||
- step: The file "output/pagefind/pagefind.js" should not be empty | ||
- step: I serve the directory "output" | ||
- step: In my browser, I load "/" | ||
- step: In my browser, I evaluate {js} | ||
js: |- | ||
let pagefind = await import("/pagefind/pagefind.js"); | ||
let search = await pagefind.search("testing"); | ||
let data = await search.results[0].data(); | ||
toolproof.assert_eq(data.url, `/dogs/`); | ||
- step: In my browser, the console should be empty |
47 changes: 47 additions & 0 deletions
47
...ntegration_tests/python_api/py-force-language-takes-precedence-over-records.toolproof.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Python API > Force language takes precedence over records | ||
platforms: | ||
- linux | ||
- mac | ||
|
||
steps: | ||
- ref: ./background.toolproof.yml | ||
- step: I have a "public/run.py" file with the content {python} | ||
python: |2- | ||
import sys | ||
sys.path.append('%repo_wd%/wrappers/python/src') | ||
import asyncio | ||
import json | ||
import logging | ||
import os | ||
from pagefind.index import PagefindIndex, IndexConfig | ||
async def main(): | ||
config = IndexConfig( | ||
force_language="fr", | ||
) | ||
async with PagefindIndex(config=config) as index: | ||
await index.add_custom_record( | ||
url="/one/", | ||
content="Testing file #1", | ||
language="pt", | ||
) | ||
await index.add_html_file( | ||
source_path="two/index.html", | ||
content="<html lang='en'><body><h1>Testing file #2</h1></body></html>", | ||
) | ||
print("Complete") | ||
if __name__ == "__main__": | ||
asyncio.run(main()) | ||
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py" | ||
- step: stdout should contain "Complete" | ||
- step: The file "public/pagefind/pagefind.js" should not be empty | ||
- step: I run "ls -lh public/pagefind/wasm.unknown.pagefind" | ||
notes: "TODO: Build a file existence check into toolproof" | ||
- step: I run "ls -lh public/pagefind/wasm.fr.pagefind" | ||
notes: "TODO: Build a file existence check into toolproof" | ||
- step: I run "ls -lh public/pagefind/wasm.pt.pagefind" and expect it to fail | ||
notes: "TODO: Build a file existence check into toolproof" | ||
- step: I run "ls -lh public/pagefind/wasm.en.pagefind" and expect it to fail | ||
notes: "TODO: Build a file existence check into toolproof" |
38 changes: 38 additions & 0 deletions
38
pagefind/integration_tests/python_api/py-pagefind-empty-index-returns-assets.toolproof.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Python API > Pagefind empty index returns assets | ||
platforms: | ||
- linux | ||
- mac | ||
|
||
steps: | ||
- ref: ./background.toolproof.yml | ||
- step: I have a "public/run.py" file with the content {python} | ||
python: |2- | ||
import sys | ||
sys.path.append('%repo_wd%/wrappers/python/src') | ||
import asyncio | ||
import json | ||
import logging | ||
import os | ||
from pagefind.index import PagefindIndex, IndexConfig | ||
async def main(): | ||
async with PagefindIndex() as index: | ||
files = await index.get_files() | ||
for file in files: | ||
print(file["path"]) | ||
await index.delete_index() | ||
print("Complete") | ||
if __name__ == "__main__": | ||
asyncio.run(main()) | ||
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py" | ||
- step: stdout should contain "Complete" | ||
- step: stdout should contain "pagefind.js" | ||
- step: stdout should contain "pagefind-ui.js" | ||
- step: stdout should contain "pagefind-ui.css" | ||
- step: stdout should contain "pagefind-modular-ui.js" | ||
- step: stdout should contain "pagefind-modular-ui.css" | ||
- step: stdout should contain "wasm.unknown.pagefind" |
48 changes: 48 additions & 0 deletions
48
pagefind/integration_tests/python_api/py-pagefind-service-config.toolproof.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Python API > Pagefind service config | ||
platforms: | ||
- linux | ||
- mac | ||
|
||
steps: | ||
- ref: ./background.toolproof.yml | ||
- step: I have a "public/run.py" file with the content {python} | ||
python: |2- | ||
import sys | ||
sys.path.append('%repo_wd%/wrappers/python/src') | ||
import asyncio | ||
import json | ||
import logging | ||
import os | ||
from pagefind.index import PagefindIndex, IndexConfig | ||
async def main(): | ||
config = IndexConfig( | ||
root_selector="h1", | ||
exclude_selectors=["span"], | ||
keep_index_url=True | ||
) | ||
async with PagefindIndex(config=config) as index: | ||
await index.add_html_file( | ||
content="<h1>Testing, <span>testing</span></h1>", | ||
source_path="dogs/index.html", | ||
) | ||
print("Complete") | ||
if __name__ == "__main__": | ||
asyncio.run(main()) | ||
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py" | ||
- step: stdout should contain "Complete" | ||
- step: The file "public/pagefind/pagefind.js" should not be empty | ||
- step: I serve the directory "public" | ||
- step: In my browser, I load "/" | ||
- step: In my browser, I evaluate {js} | ||
js: |- | ||
let pagefind = await import("/pagefind/pagefind.js"); | ||
let search = await pagefind.search("testing"); | ||
let data = await search.results[0].data(); | ||
toolproof.assert_eq(data.url, `/dogs/index.html`); | ||
toolproof.assert_eq(data.content, `Testing,`); | ||
- step: In my browser, the console should be empty |