0.2.3 #99

Merged
sonny merged 112 commits from development into master 2020-05-23 16:58:42 +02:00
4 changed files with 55 additions and 62 deletions
Showing only changes of commit 06ce82bf0c - Show all commits

View file

@ -3,22 +3,73 @@ from django.urls import reverse
from newsreader.accounts.tests.factories import UserFactory
from newsreader.news.collection.tests.factories import CollectionRuleFactory
from newsreader.news.core.models import Category
from newsreader.news.core.tests.factories import CategoryFactory
class CategoryUpdateViewTestCase(TestCase):
class CategoryViewTestCase:
def setUp(self):
self.user = UserFactory(password="test")
self.client.login(email=self.user.email, password="test")
self.category = CategoryFactory(name="category", user=self.user)
self.url = reverse("category-update", args=[self.category.pk])
def test_simple(self):
response = self.client.get(self.url)
self.assertEquals(response.status_code, 200)
class CategoryCreateViewTestCase(CategoryViewTestCase, TestCase):
def setUp(self):
super().setUp()
self.url = reverse("category-create")
def test_creation(self):
rules = CollectionRuleFactory.create_batch(size=4, user=self.user)
data = {"name": "new-category", "rules": [rule.pk for rule in rules]}
response = self.client.post(self.url, data)
self.assertEquals(response.status_code, 302)
category = Category.objects.get(name="new-category")
self.assertCountEqual(category.rule_ids, [rule.pk for rule in rules])
def test_collection_rules_only_from_user(self):
other_user = UserFactory()
other_rules = CollectionRuleFactory.create_batch(size=4, user=other_user)
response = self.client.get(self.url)
for rule in other_rules:
self.assertNotContains(response, rule.name)
def test_creation_with_other_user_rules(self):
other_user = UserFactory()
other_rules = CollectionRuleFactory.create_batch(
size=4, user=other_user, category=None
)
user_rules = CollectionRuleFactory.create_batch(
size=3, user=self.user, category=None
)
data = {"name": "new-category", "rules": [rule.pk for rule in other_rules]}
response = self.client.post(self.url, data)
self.assertContains(response, "not one of the available choices")
self.assertEquals(Category.objects.count(), 0)
class CategoryUpdateViewTestCase(CategoryViewTestCase, TestCase):
def setUp(self):
super().setUp()
self.category = CategoryFactory(name="category", user=self.user)
self.url = reverse("category-update", args=[self.category.pk])
def test_name_change(self):
data = {"name": "durp"}
self.client.post(self.url, data)

View file

@ -1,58 +0,0 @@
from django.test import Client, TestCase
from django.urls import reverse
from newsreader.accounts.tests.factories import UserFactory
from newsreader.news.collection.tests.factories import CollectionRuleFactory
from newsreader.news.core.models import Category
from newsreader.news.core.tests.factories import CategoryFactory
class CategoryCreateViewTestCase(TestCase):
def setUp(self):
self.user = UserFactory(password="test")
self.client.login(email=self.user.email, password="test")
self.url = reverse("category-create")
def test_simple(self):
response = self.client.get(self.url)
self.assertEquals(response.status_code, 200)
def test_creation(self):
rules = CollectionRuleFactory.create_batch(size=4, user=self.user)
data = {"name": "new-category", "rules": [rule.pk for rule in rules]}
response = self.client.post(self.url, data)
self.assertEquals(response.status_code, 302)
category = Category.objects.get(name="new-category")
self.assertCountEqual(category.rule_ids, [rule.pk for rule in rules])
def test_collection_rules_only_from_user(self):
other_user = UserFactory()
other_rules = CollectionRuleFactory.create_batch(size=4, user=other_user)
response = self.client.get(self.url)
for rule in other_rules:
self.assertNotContains(response, rule.name)
def test_creation_with_other_user_rules(self):
other_user = UserFactory()
other_rules = CollectionRuleFactory.create_batch(
size=4, user=other_user, category=None
)
user_rules = CollectionRuleFactory.create_batch(
size=3, user=self.user, category=None
)
data = {"name": "new-category", "rules": [rule.pk for rule in other_rules]}
response = self.client.post(self.url, data)
self.assertContains(response, "not one of the available choices")
self.assertEquals(Category.objects.count(), 0)