2016-09-18 16:00:31 +02:00
|
|
|
from unittest import TestCase
|
2018-10-14 08:26:51 +02:00
|
|
|
from unittest.mock import patch
|
2016-09-18 16:00:31 +02:00
|
|
|
|
|
|
|
from openslides.core.models import Projector
|
|
|
|
from openslides.utils import collection
|
|
|
|
|
|
|
|
|
|
|
|
class TestGetModelFromCollectionString(TestCase):
|
|
|
|
def test_known_app(self):
|
|
|
|
projector_model = collection.get_model_from_collection_string('core/projector')
|
|
|
|
|
|
|
|
self.assertEqual(projector_model, Projector)
|
|
|
|
|
|
|
|
def test_unknown_app(self):
|
2017-04-27 15:16:07 +02:00
|
|
|
with self.assertRaises(ValueError):
|
2016-09-18 16:00:31 +02:00
|
|
|
collection.get_model_from_collection_string('invalid/model')
|
|
|
|
|
|
|
|
|
|
|
|
class TestCollectionElement(TestCase):
|
|
|
|
def test_from_values(self):
|
2017-02-12 14:09:53 +01:00
|
|
|
with patch.object(collection.CollectionElement, 'get_full_data'):
|
|
|
|
collection_element = collection.CollectionElement.from_values('testmodule/model', 42)
|
2016-09-18 16:00:31 +02:00
|
|
|
|
|
|
|
self.assertEqual(collection_element.collection_string, 'testmodule/model')
|
|
|
|
self.assertEqual(collection_element.id, 42)
|
|
|
|
|
2017-02-12 14:09:53 +01:00
|
|
|
@patch.object(collection.CollectionElement, 'get_full_data')
|
|
|
|
def test_equal(self, mock_get_full_data):
|
2016-09-30 21:43:22 +02:00
|
|
|
self.assertEqual(
|
|
|
|
collection.CollectionElement.from_values('testmodule/model', 1),
|
|
|
|
collection.CollectionElement.from_values('testmodule/model', 1))
|
|
|
|
self.assertEqual(
|
|
|
|
collection.CollectionElement.from_values('testmodule/model', 1),
|
|
|
|
collection.CollectionElement.from_values('testmodule/model', 1, deleted=True))
|
|
|
|
self.assertNotEqual(
|
|
|
|
collection.CollectionElement.from_values('testmodule/model', 1),
|
|
|
|
collection.CollectionElement.from_values('testmodule/model', 2))
|
|
|
|
self.assertNotEqual(
|
|
|
|
collection.CollectionElement.from_values('testmodule/model', 1),
|
|
|
|
collection.CollectionElement.from_values('testmodule/other_model', 1))
|