-
Notifications
You must be signed in to change notification settings - Fork 348
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
Sascha Ißbrücker
committed
Feb 14, 2021
1 parent
f555bba
commit 256084f
Showing
10 changed files
with
167 additions
and
4 deletions.
There are no files selected for viewing
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,18 @@ | ||
# Generated by Django 2.2.13 on 2021-02-14 09:08 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('bookmarks', '0005_auto_20210103_1212'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='bookmark', | ||
name='is_archived', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
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
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
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
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
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,47 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.test import TestCase | ||
from django.utils import timezone | ||
|
||
from bookmarks.models import Bookmark | ||
from bookmarks.services.bookmarks import archive_bookmark, unarchive_bookmark | ||
|
||
User = get_user_model() | ||
|
||
|
||
class BookmarkServiceTestCase(TestCase): | ||
|
||
def setUp(self) -> None: | ||
self.user = User.objects.create_user('testuser', '[email protected]', 'password123') | ||
|
||
def test_archive(self): | ||
bookmark = Bookmark( | ||
url='https://example.com', | ||
date_added=timezone.now(), | ||
date_modified=timezone.now(), | ||
owner=self.user | ||
) | ||
bookmark.save() | ||
|
||
self.assertFalse(bookmark.is_archived) | ||
|
||
archive_bookmark(bookmark) | ||
|
||
updated_bookmark = Bookmark.objects.get(id=bookmark.id) | ||
|
||
self.assertTrue(updated_bookmark.is_archived) | ||
|
||
def test_unarchive(self): | ||
bookmark = Bookmark( | ||
url='https://example.com', | ||
date_added=timezone.now(), | ||
date_modified=timezone.now(), | ||
owner=self.user, | ||
is_archived=True, | ||
) | ||
bookmark.save() | ||
|
||
unarchive_bookmark(bookmark) | ||
|
||
updated_bookmark = Bookmark.objects.get(id=bookmark.id) | ||
|
||
self.assertFalse(updated_bookmark.is_archived) |
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,48 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.test import TestCase | ||
from django.utils import timezone | ||
from django.utils.crypto import get_random_string | ||
from bookmarks.models import Bookmark | ||
from bookmarks.queries import query_bookmarks, query_archived_bookmarks | ||
|
||
User = get_user_model() | ||
|
||
|
||
class QueriesTestCase(TestCase): | ||
|
||
def setUp(self) -> None: | ||
self.user = User.objects.create_user('testuser', '[email protected]', 'password123') | ||
|
||
def setup_bookmark(self, is_archived: bool = False): | ||
unique_id = get_random_string(length=32) | ||
bookmark = Bookmark( | ||
url='https://example.com/' + unique_id, | ||
date_added=timezone.now(), | ||
date_modified=timezone.now(), | ||
owner=self.user, | ||
is_archived=is_archived | ||
) | ||
bookmark.save() | ||
return bookmark | ||
|
||
def test_query_bookmarks_should_not_return_archived_bookmarks(self): | ||
bookmark1 = self.setup_bookmark() | ||
bookmark2 = self.setup_bookmark() | ||
self.setup_bookmark(is_archived=True) | ||
self.setup_bookmark(is_archived=True) | ||
self.setup_bookmark(is_archived=True) | ||
|
||
query = query_bookmarks(self.user, '') | ||
|
||
self.assertCountEqual([bookmark1, bookmark2], list(query)) | ||
|
||
def test_query_archived_bookmarks_should_not_return_unarchived_bookmarks(self): | ||
bookmark1 = self.setup_bookmark(is_archived=True) | ||
bookmark2 = self.setup_bookmark(is_archived=True) | ||
self.setup_bookmark() | ||
self.setup_bookmark() | ||
self.setup_bookmark() | ||
|
||
query = query_archived_bookmarks(self.user, '') | ||
|
||
self.assertCountEqual([bookmark1, bookmark2], list(query)) |
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
User = get_user_model() | ||
|
||
|
||
class TagTestCase(TestCase): | ||
class TagServiceTestCase(TestCase): | ||
|
||
def setUp(self) -> None: | ||
self.user = User.objects.create_user('testuser', '[email protected]', 'password123') | ||
|
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
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