Skip to content

Commit

Permalink
fix tests and export table
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin-Sun-tts committed Feb 4, 2025
1 parent 71dd1b3 commit 6031096
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 95 deletions.
24 changes: 18 additions & 6 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,18 +749,30 @@ def download_harvest_errors_by_job(job_id, error_type):
]
]
case "record":
errors = db._to_list(
db.get_harvest_record_errors_by_job(
errors = [
[
error.id,
identifier,
json.loads(source_raw).get("title", None) if source_raw else None,
error.harvest_record_id,
error.type,
error.message,
error.date_created

]
for error, identifier, source_raw in db.get_harvest_record_errors_by_job(
job_id, skip_pagination=True
).all()
)
)
]
header = [
[
"record_error_id",
"identifier",
"title",
"harvest_record_id",
"date_created",
"record_error_type",
"message",
"record_error_id",
"date_created"
]
]

Expand Down
91 changes: 5 additions & 86 deletions app/templates/view_job_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,14 @@ <h2>Record Error Details</h2>
{% if not data.record_errors %}
<p>No record errors found</p>
{% else %}
<button id="toggleViewBtn" onclick="toggleView()">Switch to Table View</button>
{% set error_type = "record" %}
<a href="{{ url_for('harvest.download_harvest_errors_by_job', job_id=data.harvest_job_id, error_type=error_type)}}">
<button class="btn btn-primary">download record errors as .csv</button>
</a>
<div class="usa-table-container--scrollable" tabindex="0">
{% block record_errors_table %}
<div id="error_results_pagination">
<div id="blockView" class="error-list">
<div class="error-list">
{% for record_error in data.record_errors %}
<div class="error-block">
<h3>{{ record_error.error.id }}</h3>
Expand All @@ -97,96 +100,12 @@ <h3>{{ record_error.error.id }}</h3>
<p><strong>Error Message:</strong> {{ record_error.error.message }}</p>
<p><strong>Type:</strong> {{ record_error.error.type }}</p>
<p><strong>Date Created:</strong> {{ record_error.error.date_created }}</p>

</div>
{% endfor %}
</div>
<table id="tableView" class="usa-table usa-table--striped" style="display: none;">
{% set error_type = "record" %}
<a href="{{ url_for('harvest.download_harvest_errors_by_job', job_id=data.harvest_job_id, error_type=error_type)}}">
<button class="btn btn-primary">download record errors as .csv</button>
</a>
<caption> Harvest Record Errors for {{data.harvest_job_id}}</caption>
<thead>
<tr>
<th data-sortable scope="col" role="columnheader">Date Created</th>
<th data-sortable scope="col" role="columnheader">ID</th>
<th data-sortable scope="col" role="columnheader">Title</th>
<th data-sortable scope="col" role="columnheader">Identifier</th>
<th data-sortable scope="col" role="columnheader">Harvest Record Id</th>
<th data-sortable scope="col" role="columnheader">Message</th>
<th data-sortable scope="col" role="columnheader">Type</th>
</tr>
</thead>
<tbody>
{% for record_error in data.record_errors %}
<tr>
<td data-sort-value="{{ record_error.error.date_created }}"> {{ record_error.error.date_created }}</td>
<td>{{ record_error.error.id }}</td>
<td>{{ record_error.title }}</td>
<td>{{ record_error.identifier }}</td>
<td data-sort-value="{{ record_error.error.harvest_record_id }}">
<a href="{{ url_for('harvest.get_harvest_record', record_id=record_error.error.harvest_record_id) }}">
{{ record_error.error.harvest_record_id }}
</a>
</td>
<td data-sort-value="{{ record_error.error.message }}"> {{ record_error.error.message }}</td>
<td data-sort-value="{{ record_error.error.type }}"> {{ record_error.error.type }}</td>
</tr>
{% endfor %}
{% if pagination.per_page > data.record_errors|count and pagination.count > data.record_errors|count %}
{% for number in range(pagination.per_page - data.record_errors|count) %}
<tr>
{% for number in range(5) %}
<td>&nbsp;</td>
{% endfor %}
</tr>
{% endfor %}
{% endif %}
</tbody>
</table>
{% if pagination.count > data.record_errors|count %}
{% include '/components/pagination/pagination.html' %}
{%endif%}
<script>
document.addEventListener("DOMContentLoaded", function() {
setTimeout(function() {
let savedView = localStorage.getItem("errorView");
console.log("Applying saved view:", savedView);
if (!savedView) {
localStorage.setItem("errorView", "block");
}
applyView(savedView || "block");
}, 100);
});

function toggleView() {
var currentView = localStorage.getItem("errorView") === "table" ? "block" : "table";
localStorage.setItem("errorView", currentView);
console.log("View changed to:", currentView);
applyView(currentView);
}

function applyView(view) {
console.log("Applying view:", view);

var blockView = document.getElementById("blockView");
var tableView = document.getElementById("tableView");
var toggleBtn = document.getElementById("toggleViewBtn");

if (view === "table") {
blockView.style.display = "none";
tableView.style.display = "block";
toggleBtn.textContent = "Switch to Block View";
} else {
blockView.style.display = "block";
tableView.style.display = "none";
toggleBtn.textContent = "Switch to Table View";
}
}
</script>


<style>
.error-list {
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_harvest_record_errors_reported(
assert harvest_job.status == "complete"
assert len(interface_errors) == harvest_job.records_errored
assert len(interface_errors) == len(job_errors)
assert interface_errors[0].harvest_record_id == job_errors[0].harvest_record_id
assert interface_errors[0][0].harvest_record_id == job_errors[0].harvest_record_id

@patch("harvester.harvest.ckan")
@patch("harvester.utils.ckan_utils.uuid")
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/harvest_job_flows/test_harvest_job_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def test_harvest_job_sync(

assert len(job_err) == 0
assert len(record_err) == 1
assert record_err[0].type == "SynchronizeException"
assert record_err[0][0].type == "SynchronizeException"
## assert it's the second record that threw the exception, which validates our package_create mock
assert record_err[0].harvest_record_id == harvest_job.records[1].id
assert record_err[0][0].harvest_record_id == harvest_job.records[1].id

# pkg create called three times
assert CKANMock.action.package_create.call_count == 3
Expand Down

1 comment on commit 6031096

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title Coverage Tests Skipped Failures Errors Time
Unit tests Coverage 39 0 💤 0 ❌ 0 🔥 0.94s ⏱️
Integration Tests Coverage 70 0 💤 0 ❌ 0 🔥 4.309s ⏱️
Functional Tests Coverage 2 0 💤 0 ❌ 0 🔥 7.817s ⏱️

Please sign in to comment.