Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1907.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add management command for finding newest Argus release
17 changes: 17 additions & 0 deletions docs/development/management-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -577,3 +577,20 @@ the command `rqworker`:
.. code:: console

$ python manage.py rqworker

Look for new Argus release
==========================
To check if there is a new release of Argus available one can use the command `check_version`:

.. code:: console

$ python manage.py check_version

To also save the latest version in the database, use the `--save` flag:

.. code:: console

$ python manage.py check_version --save

This will currently not do anything, but in the future you will be able to get
a notification in the frontend if there is a new release registered in the database that you haven't seen yet.
Comment on lines +595 to +596

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make sure to note in #1882 to remove this comment when it is implemented

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍

21 changes: 21 additions & 0 deletions src/argus/dev/management/commands/check_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.core.management.base import BaseCommand

from argus.versioncheck.models import LastSeenVersion
from argus.versioncheck.tasks import get_latest_version


class Command(BaseCommand):
help = "Look for a new Argus version"

def add_arguments(self, parser):
parser.add_argument("-s", "--save", action="store_true", help="Save the new version to the database")

def handle(self, *args, **options):
latest_version = get_latest_version()
self.stdout.write(f"Latest version of Argus is: {latest_version}")
if options["save"]:
_, created = LastSeenVersion.objects.get_or_create(version=latest_version)
if created:
self.stdout.write("Saved to database.")
else:
self.stdout.write("This version is already in the database.")
39 changes: 39 additions & 0 deletions tests/dev/test_version_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from unittest.mock import patch

from django.test import TestCase, tag

from argus.versioncheck.models import LastSeenVersion
from django.core.management import call_command
from argus.util.testing import connect_signals, disconnect_signals


@tag("database")
class TestTaskRegisterLatestVersion(TestCase):
def setUp(self):
disconnect_signals()

def tearDown(self):
connect_signals()

@patch("argus.versioncheck.tasks.get_latest_version")
def test_when_new_version_is_not_already_registered_then_register_new_version(self, get_latest_version):
get_latest_version.return_value = "1.2.3"
assert not LastSeenVersion.objects.filter(version="1.2.3").exists()
call_command("check_version", "--save")
assert LastSeenVersion.objects.filter(version="1.2.3").exists()

@patch("argus.versioncheck.tasks.get_latest_version")
def test_when_new_version_is_already_registered_then_do_not_register_it_again(self, get_latest_version):
get_latest_version.return_value = "1.2.3"
LastSeenVersion.objects.create(version="1.2.3")
assert LastSeenVersion.objects.filter(version="1.2.3").count() == 1
call_command("check_version", "--save")
# Still only one instance of this version in the database
assert LastSeenVersion.objects.filter(version="1.2.3").count() == 1

@patch("argus.versioncheck.tasks.get_latest_version")
def test_when_save_flag_is_not_set_then_do_not_register_new_version(self, get_latest_version):
get_latest_version.return_value = "1.2.3"
assert not LastSeenVersion.objects.filter(version="1.2.3").exists()
call_command("check_version")
assert not LastSeenVersion.objects.filter(version="1.2.3").exists()
Loading