Skip to content

Commit 2b6e1ec

Browse files
authored
Merge pull request #167 from nationalarchives/improve-test-fixtures
Add more feedback to test fixtures load script
2 parents 85dd0fc + 77aba81 commit 2b6e1ec

File tree

4 files changed

+24
-93
lines changed

4 files changed

+24
-93
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ You'll then need to deploy the configuration (see Deployment, above)
4343

4444
Ensure that `MARKLOGIC_HOST` in `.env` in the editor and public ui is set to `host.docker.internal` in `.env` and that the username and password are both `admin` if you want to use them with the local instance.
4545

46-
### 4. (Optional) Populate data in the local database
46+
### 4. (Optional) Populate test fixtures in the local database
4747

48-
To get some example documents onto the local database, there are `development_scripts/populate_top_judgments_and_neighbours.py` and `development_scripts/populate_from_caselaw.py` which copy documents from the live caselaw site (they don't import or fake properties) into your local database. (Check https://caselaw.nationalarchives.gov.uk/terms-of-use and get in touch if you intend to download many more than these.)
48+
To load test fixtures, run `development_scripts/populate_from_caselaw.py`. This will load a variety of documents.
4949

5050
There are also other ways other importing data as detailed further down the readme but haven't been tested for a while.
5151

development_scripts/populate_from_caselaw.py

+22-5
Original file line numberDiff line numberDiff line change
@@ -33,43 +33,55 @@ def test_response(response):
3333
try:
3434
response.raise_for_status()
3535
except Exception:
36+
print("🔴 EXCEPTION")
3637
print("Content of server response:")
3738
print(response.content)
3839
raise
3940

4041

4142
def load_fixture_from_url(url: str) -> None:
43+
print(f"> Loading {url} from URL…")
44+
4245
ml_url = f"/{url}.xml"
43-
print(url)
46+
4447
response = requests.get(f"https://caselaw.nationalarchives.gov.uk/{url}/data.xml")
4548
test_response(response)
4649
xml = response.content
47-
print("got xml")
50+
print(">> Downloaded XML…")
4851

4952
response = requests.put(
5053
f"http://admin:admin@localhost:8011/LATEST/documents?uri={ml_url}&collection=judgment",
5154
data=xml,
5255
)
5356
test_response(response)
54-
print("added to local Marklogic db")
57+
print(">> ✅ Saved to MarkLogic")
5558

5659

5760
def load_fixture_from_files(file_prefix: str) -> None:
61+
print(f"> Loading {filename} from filesystem…")
62+
5863
ml_url = "/" + filename.replace("-", "/") + ".xml"
64+
5965
with Path("development_scripts", "fixture_data", f"{filename}-content.xml").open() as f:
6066
content = f.read()
6167
with Path("development_scripts", "fixture_data", f"{filename}-properties.xml").open() as f:
6268
properties = f.read()
69+
70+
print(">> Source files read to memory…")
71+
6372
response = requests.put(
6473
f"http://admin:admin@localhost:8011/LATEST/documents?uri={ml_url}&collection=judgment",
6574
data=content,
6675
)
6776
test_response(response)
77+
print(">> Saved source document to MarkLogic…")
78+
6879
response = requests.put(
6980
f"http://admin:admin@localhost:8011/LATEST/documents?uri={ml_url}&category=properties",
7081
data=properties,
7182
)
7283
test_response(response)
84+
print(">> Saved properties document to MarkLogic…")
7385

7486
xquery = f"""
7587
xquery version "1.0-ml";
@@ -78,13 +90,18 @@ def load_fixture_from_files(file_prefix: str) -> None:
7890
"""
7991

8092
response = requests.post("http://admin:admin@localhost:8011/LATEST/eval", data={"xquery": xquery})
93+
test_response(response)
94+
print(">> Set as managed document…")
95+
96+
print(">> ✅ Saved to MarkLogic")
8197

82-
print(response.content)
83-
print(f"added {filename} to local Marklogic db")
8498

99+
print("Beginning fixture import…")
85100

101+
print("Loading fixtures from URLs…")
86102
for url in URLS_TO_IMPORT:
87103
load_fixture_from_url(url)
88104

105+
print("Loading fixtures from files…")
89106
for filename in FIXTURE_FILES_TO_IMPORT:
90107
load_fixture_from_files(file_prefix=filename)

development_scripts/populate_top_judgments_and_neighbours.py

-85
This file was deleted.

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,3 @@ unfixable = ["ERA"]
4545
"S113", # requests no timeout : TODO
4646
]
4747
"tests/*" = ["S101"] # assert fine in tests
48-
"development_scripts/populate_top_judgments_and_neighbours.py" = ["S314", "C400"] # TODO

0 commit comments

Comments
 (0)