-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement admin button for refreshing hyperparams
- Loading branch information
1 parent
dad9bd2
commit c3db9db
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
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
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 @@ | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
from django.contrib.messages import get_messages | ||
from django.test import Client | ||
from pytest_mock import MockerFixture | ||
|
||
from bittensor_panel.core.services import HyperParameterRefreshFailed | ||
|
||
|
||
@pytest.fixture | ||
def mock_refresh_hyperparams(mocker: MockerFixture): | ||
return mocker.patch("bittensor_panel.core.admin.refresh_hyperparams") | ||
|
||
|
||
def test_refresh_hyperparams_view( | ||
admin_client: Client, mock_refresh_hyperparams: MagicMock | ||
): | ||
response = admin_client.post("/admin/core/hyperparameter/refresh-hyperparams/") | ||
|
||
mock_refresh_hyperparams.assert_called_once() | ||
|
||
assert response.status_code == 302 | ||
assert response.url == "/admin/core/hyperparameter/" | ||
|
||
|
||
def test_refresh_hyperparams_view_exception( | ||
admin_client: Client, mock_refresh_hyperparams: MagicMock | ||
): | ||
mock_refresh_hyperparams.side_effect = HyperParameterRefreshFailed("error") | ||
|
||
response = admin_client.post("/admin/core/hyperparameter/refresh-hyperparams/") | ||
|
||
assert response.status_code == 302 | ||
assert response.url == "/admin/core/hyperparameter/" | ||
|
||
messages = list(get_messages(response.wsgi_request)) | ||
assert len(messages) == 1 |
10 changes: 10 additions & 0 deletions
10
app/src/bittensor_panel/templates/admin/core/hyperparameter/change_list.html
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,10 @@ | ||
{% extends "admin/change_list.html" %} {% load i18n %} | ||
{% block object-tools-items %} | ||
{{ block.super }} | ||
<div> | ||
<form action="{% url 'admin:refresh_hyperparams' %}" method="POST"> | ||
{% csrf_token %} | ||
<button type="submit" onclick="return confirm('Are you sure want to refresh hyperparams from subtensor?\nExisting data will be overwritten')">Refresh from subtensor</button> | ||
</form> | ||
</div> | ||
{% endblock %} |