Beispiel #1
0
from django.views.decorators.cache import cache_page
from django.views.i18n import JavaScriptCatalog

from comment import _get_version
from comment.views import (CreateComment, UpdateComment, DeleteComment,
                           SetReaction, SetFlag, ChangeFlagState,
                           ConfirmComment)

app_name = 'comment'

urlpatterns = [
    path('create/', CreateComment.as_view(), name='create'),
    path('edit/<int:pk>/', UpdateComment.as_view(), name='edit'),
    path('delete/<int:pk>/', DeleteComment.as_view(), name='delete'),
    path('<int:pk>/react/<str:reaction>/', SetReaction.as_view(),
         name='react'),
    path('<int:pk>/flag/', SetFlag.as_view(), name='flag'),
    path('<int:pk>/flag/state/change/',
         ChangeFlagState.as_view(),
         name='flag-change-state'),
    re_path(r'^confirm/(?P<key>[^/]+)/$',
            ConfirmComment.as_view(),
            name='confirm-comment'),
    # javascript translations
    # The value returned by _get_version() must change when translations change.
    path('jsi18n/',
         cache_page(86400, key_prefix='js18n-%s' % _get_version())(
             JavaScriptCatalog.as_view()),
         name='javascript-catalog'),
]
Beispiel #2
0
 def test_get_version(self):
     self.assertEqual(_get_version(), MANIFEST_VERSION)
 def test_when_versions_startswith_v(self):
     with patch('builtins.open', mock_open(read_data='v2.0.0'),
                create=True):
         self.assertEqual('2.0.0', _get_version())
Beispiel #4
0
from unittest import skipIf
from unittest.mock import patch

from django.test import TestCase

from comment import __version__, _get_version, check_release

SKIP = False
try:
    MANIFEST_VERSION = _get_version()
except FileNotFoundError:
    SKIP = True


class TestVersion(TestCase):
    @skipIf(SKIP, 'Test skipped: development purpose only')
    def test_get_version(self):
        self.assertEqual(_get_version(), MANIFEST_VERSION)

    @skipIf(SKIP, 'Test skipped: development purpose only')
    def test_manifest_matches_init_version(self):
        self.assertEqual(__version__, MANIFEST_VERSION)

    @patch('comment._get_version', side_effect=[FileNotFoundError])
    def test_check_release_file_not_found(self, mocked_get_version):
        self.assertIsNone(check_release())
        mocked_get_version.assert_called_once()

    @skipIf(SKIP, 'Test skipped: development purpose only')
    @patch('comment.__version__', return_value='not_match')
    def test_check_release_raise_assertion_error_when_versions_does_not_match(