Skip to content

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Posselt committed Feb 4, 2018
1 parent 5d39f28 commit 35201a5
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import json
from typing import Any, Dict
from unittest.mock import patch

from django.core.management import call_command
from django.test import TestCase
from django.utils.six import StringIO

from nextcloudappstore.core.facades import read_relative_file
from nextcloudappstore.core.github import GitHubClient
from nextcloudappstore.core.models import NextcloudRelease


class SyncNextcloudReleasesTest(TestCase):

@patch.object(GitHubClient, 'get_tags')
def test_sync(self, get_tags):
get_tags.side_effect = self._get_tags
call_command('syncnextcloudreleases', '--oldest-supported=11.0.0',
stdout=StringIO())

latest = NextcloudRelease.objects.get(version='12.0.5')
self.assertEquals(True, latest.is_current)
self.assertEquals(True, latest.has_release)

def _get_tags(self, page: int, size: int = 100) -> Dict[Any, Any]:
return json.loads(self._read('tags_page_%d.json' % page))

def _read(self, path: str) -> str:
return read_relative_file(__file__, '../../../tests/data/%s' % path)
36 changes: 36 additions & 0 deletions nextcloudappstore/core/tests/test_caching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from urllib.request import Request

from django.contrib.auth.models import User
from django.test import TestCase

from nextcloudappstore.core.caching import nextcloud_release_etag, \
categories_etag, app_ratings_etag
from nextcloudappstore.core.models import NextcloudRelease, Category, \
AppRating, App


class CachingTest(TestCase):

def test_cache_nextcloud_release_etag_empty(self):
etag = nextcloud_release_etag(Request('https://'))
self.assertEquals('0-', etag)

def test_cache_nextcloud_release_etag(self):
NextcloudRelease.objects.create(version='12.0.2')
NextcloudRelease.objects.create(version='12.0.1')

etag = nextcloud_release_etag(Request('https://'))
self.assertEquals('2-12.0.2', etag)

def test_categories_etag(self):
category = Category.objects.create(pk='test')
etag = categories_etag(Request('https://'))
self.assertEquals(str(category.last_modified), etag)

def test_app_ratings_etag(self):
user = User.objects.create(username='hi')
app = App.objects.create(id='test', owner=user)
rating = AppRating.objects.create(app=app, user=user)

etag = app_ratings_etag(Request('https://'))
self.assertEquals(str(rating.rated_at), etag)
2 changes: 1 addition & 1 deletion nextcloudappstore/core/tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from nextcloudappstore.core.models import NextcloudRelease


class RatingTest(TestCase):
class GitHubTest(TestCase):

def test_parse_tags(self):
client = MagicMock(spec=GitHubClient)
Expand Down

0 comments on commit 35201a5

Please sign in to comment.