-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bernhard Posselt
committed
Feb 4, 2018
1 parent
5d39f28
commit 35201a5
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
nextcloudappstore/core/management/commands/tests/test_syncnextcloudreleases.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters