summaryrefslogtreecommitdiff
path: root/ishtar_common/tests.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-01-29 17:33:45 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-01-29 17:33:45 +0100
commit478befbbf1705b8547f8e88a4b5822d3bad52200 (patch)
treedd6c2f8bff2ffb12c210f13090ecf845ef182560 /ishtar_common/tests.py
parent019f483daeb9fca526ef5f46fda650f01c551fc0 (diff)
downloadIshtar-478befbbf1705b8547f8e88a4b5822d3bad52200.tar.bz2
Ishtar-478befbbf1705b8547f8e88a4b5822d3bad52200.zip
Fix performance issues for shortcut menu
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r--ishtar_common/tests.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index 10584e4f2..cdf6ce330 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -334,6 +334,70 @@ class MergeTest(TestCase):
init_mc)
+class ShortMenuTest(TestCase):
+ def setUp(self):
+ from archaeological_operations.models import OperationType
+ self.username = 'username666'
+ self.password = 'dcbqj7xnjkxnjsknx!@%'
+ self.user = User.objects.create_superuser(
+ self.username, "nomail@nomail.com", self.password)
+ self.other_user = User.objects.create_superuser(
+ 'John', "nomail@nomail.com", self.password)
+ self.ope_type = OperationType.objects.create()
+
+ def testNotConnected(self):
+ c = Client()
+ response = c.get(reverse('shortcut-menu'))
+ # no content if not logged
+ self.assertFalse("shortcut-menu" in response.content)
+ c = Client()
+ c.login(username=self.username, password=self.password)
+ # no content because the user owns no object
+ response = c.get(reverse('shortcut-menu'))
+ self.assertFalse("shortcut-menu" in response.content)
+ from archaeological_operations.models import Operation
+ Operation.objects.create(
+ operation_type=self.ope_type,
+ history_modifier=self.user)
+ # content is here
+ response = c.get(reverse('shortcut-menu'))
+ self.assertTrue("shortcut-menu" in response.content)
+
+ def testOperation(self):
+ from archaeological_operations.models import Operation
+ c = Client()
+ c.login(username=self.username, password=self.password)
+ ope = Operation.objects.create(
+ operation_type=self.ope_type,
+ history_modifier=self.other_user,
+ year=2042, operation_code=54
+ )
+ # not available at first
+ response = c.get(reverse('shortcut-menu'))
+ self.assertFalse(str(ope.cached_label) in response.content)
+
+ # available because is the creator
+ ope.history_creator = self.user
+ ope.save()
+ response = c.get(reverse('shortcut-menu'))
+ self.assertTrue(str(ope.cached_label) in response.content)
+
+ # available because is in charge
+ ope.history_creator = self.other_user
+ ope.in_charge = self.user.ishtaruser.person
+ ope.save()
+ response = c.get(reverse('shortcut-menu'))
+ self.assertTrue(str(ope.cached_label) in response.content)
+
+ # available because is the scientist
+ ope.history_creator = self.other_user
+ ope.in_charge = None
+ ope.scientist = self.user.ishtaruser.person
+ ope.save()
+ response = c.get(reverse('shortcut-menu'))
+ self.assertTrue(str(ope.cached_label) in response.content)
+
+
class ImportTest(TestCase):
def testDeleteRelated(self):
town = models.Town.objects.create(name='my-test')