Skip to content

Commit

Permalink
[tests] Flagged tests that should not be run on production env
Browse files Browse the repository at this point in the history
These tests depends on the static storage backend of the project.
In prod environment, the filenames could get changed due to
static minification and cache invalidation. Hence, these tests
should not be run on prod environment because they'll fail.

(cherry picked from commit b2079fa)
  • Loading branch information
pandafy authored and nemesifier committed Jul 14, 2022
1 parent dec40f5 commit 301e7ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ Run tests with:
# tests for the sample app
SAMPLE_APP=1 ./runtests.py
# If you running tests on PROD environment
./runtests.py --exclude skip_prod
When running the last line of the previous example, the environment variable ``SAMPLE_APP`` activates
the sample app in ``/tests/openwisp2/`` which is a simple django app that extends ``openwisp-notifications``
with the sole purpose of testing its extensibility, for more information regarding this concept,
Expand Down
11 changes: 10 additions & 1 deletion openwisp_notifications/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.contrib.auth.models import Permission
from django.core.cache import cache
from django.forms.widgets import MediaOrderConflictWarning
from django.test import TestCase, override_settings
from django.test import TestCase, override_settings, tag
from django.urls import reverse

from openwisp_notifications import settings as app_settings
Expand Down Expand Up @@ -113,13 +113,20 @@ def test_cached_invalidation(self):
self.client.get(self._url)
self.assertEqual(cache.get(cache_key), 1)

@tag('skip_prod')
# This tests depends on the static storage backend of the project.
# In prod environment, the filenames could get changed due to
# static minification and cache invalidation. Hence, these tests
# should not be run on prod environment because they'll fail.
def test_default_notification_setting(self):
res = self.client.get(self._url)
self.assertContains(
res, '/static/openwisp-notifications/audio/notification_bell.mp3'
)
self.assertContains(res, 'window.location')

@tag('skip_prod')
# For more info, look at TestAdmin.test_default_notification_setting
@patch.object(
app_settings,
'OPENWISP_NOTIFICATIONS_SOUND',
Expand Down Expand Up @@ -233,6 +240,8 @@ def test_ignore_notification_widget_add_view(self):
self.assertNotContains(response, 'owIsChangeForm')


@tag('skip_prod')
# For more info, look at TestAdmin.test_default_notification_setting
class TestAdminMedia(BaseTestAdmin):
"""
Tests notifications admin media
Expand Down

0 comments on commit 301e7ba

Please sign in to comment.