Skip to content

Commit

Permalink
pull latest and run pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-nork committed Jul 11, 2023
1 parent b0ccb84 commit a5d4b20
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ cython_debug/
#.idea/

.vscode/launch.json
.vscode/settings.json

chirps/erl_crash.dump
*.dump
7 changes: 0 additions & 7 deletions .vscode/settings.json

This file was deleted.

74 changes: 37 additions & 37 deletions chirps/target/templates/target/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,45 +63,45 @@ <h5 class="my-auto ml-0 mr-auto">{{ target.name }}</h5>
{% endfor %}
</div>

<!-- Toast notification -->
<div aria-live="polite" aria-atomic="true" style="position: fixed; top: 0; right: 0; z-index: 1000; min-height: 200px; min-width: 500px;">
<div class="toast" id="toast-notification" style="position: absolute; top: 10px; right: 10px;" data-bs-autohide="true" data-bs-delay="5000">
<div class="toast-header">
<strong class="me-auto">Notification</strong>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
<!-- Toast message will be added here -->
</div>
</div>
</div>
<!-- End of Toast notification -->
<!-- Toast notification -->
<div aria-live="polite" aria-atomic="true" style="position: fixed; top: 0; right: 0; z-index: 1000; min-height: 200px; min-width: 500px;">
<div class="toast" id="toast-notification" style="position: absolute; top: 10px; right: 10px;" data-bs-autohide="true" data-bs-delay="5000">
<div class="toast-header">
<strong class="me-auto">Notification</strong>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
<!-- Toast message will be added here -->
</div>
</div>
</div>
<!-- End of Toast notification -->

<script>
document.addEventListener('DOMContentLoaded', function () {
const pingButtons = document.querySelectorAll('.ping-btn');
pingButtons.forEach(btn => {
btn.addEventListener('click', async function () {
const targetId = btn.getAttribute('data-target-id');
const response = await fetch(`/target/ping/${targetId}/`, { headers: { 'X-Requested-With': 'XMLHttpRequest' } });
if (response.status === 200) {
showToast('Success: Connection established', 'success');
} else {
showToast('Ping failed: Failed to establish connection', 'danger');
}
});
});
});
function showToast(message, type) {
const toastElement = document.getElementById("toast-notification");
toastElement.querySelector(".toast-body").innerHTML = message;
toastElement.classList.remove("bg-success", "bg-danger");
toastElement.classList.add("bg-" + type);
const toast = new bootstrap.Toast(toastElement);
toast.show();
}
document.addEventListener('DOMContentLoaded', function () {
const pingButtons = document.querySelectorAll('.ping-btn');
pingButtons.forEach(btn => {
btn.addEventListener('click', async function () {
const targetId = btn.getAttribute('data-target-id');
const response = await fetch(`/target/ping/${targetId}/`, { headers: { 'X-Requested-With': 'XMLHttpRequest' } });
if (response.status === 200) {
showToast('Success: Connection established', 'success');
} else {
showToast('Ping failed: Failed to establish connection', 'danger');
}
});
});
});

function showToast(message, type) {
const toastElement = document.getElementById("toast-notification");
toastElement.querySelector(".toast-body").innerHTML = message;
toastElement.classList.remove("bg-success", "bg-danger");
toastElement.classList.add("bg-" + type);

const toast = new bootstrap.Toast(toastElement);
toast.show();
}
</script>

{% include 'pagination.html' with page_obj=page_obj %}
Expand Down
13 changes: 7 additions & 6 deletions chirps/target/tests.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Test cases for the target application."""
from unittest import mock

import fakeredis
import pytest
from django.contrib.auth.models import User # noqa: E5142
from django.test import TestCase
from django.urls import reverse
import fakeredis
import pytest
from redis.exceptions import ConnectionError
from target.providers.mantium import MantiumTarget
from target.providers.redis import RedisTarget

from redis.exceptions import ConnectionError


class TargetTests(TestCase):
"""Test the target application."""
Expand Down Expand Up @@ -119,6 +119,7 @@ class RedisTargetTests(TestCase):
"""Test the RedisTarget"""

def setUp(self):
"""Set up the RedisTarget tests"""
# Login the user before performing any tests
self.client.post(reverse('login'), {'username': 'admin', 'password': 'admin'})
self.server = fakeredis.FakeServer()
Expand All @@ -127,15 +128,15 @@ def setUp(self):
def test_ping__success(self):
"""Test that connectivity check works"""
self.server.connected = True

with mock.patch('target.providers.redis.Redis', return_value=self.redis):
target = RedisTarget(host='localhost', port=12000)
assert target.test_connection()

def test_ping__failure(self):
"""Test that ping raises ConnectionError if the server is not connected"""
self.server.connected = False

with mock.patch('target.providers.redis.Redis', return_value=self.redis):
target = RedisTarget(host='localhost', port=12000)
with pytest.raises(ConnectionError):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ redis==4.5.5
requests==2.31.0
pinecone-client
python-dotenv
fakeredis==2.16.0

0 comments on commit a5d4b20

Please sign in to comment.