From d08a3637b3a332aeabbb6d25175200f1034732d3 Mon Sep 17 00:00:00 2001
From: thomahl <thomahl@stud.ntnu.no>
Date: Mon, 16 Mar 2020 12:46:43 +0100
Subject: [PATCH] #54 test for exception ved for store moduler

---
 test/test_soi.py | 42 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/test/test_soi.py b/test/test_soi.py
index 1c60de5..29f73a8 100644
--- a/test/test_soi.py
+++ b/test/test_soi.py
@@ -14,7 +14,7 @@ import unittest
 from PySide2.QtWidgets import QApplication, QWidget
 from PySide2 import QtGui
 from PySide2.QtGui import QPalette, QColor
-from soitool.soi import SOI
+from soitool.soi import SOI, ModuleLargerThanBinError
 from soitool.modules.module_base import ModuleBase
 
 if isinstance(QtGui.qApp, type(None)):
@@ -157,3 +157,43 @@ class TestSOI(unittest.TestCase):
         self.soi.add_reorganization_listener(listener)
         self.soi.reorganize()
         self.assertTrue(listener_was_called)
+
+    def test_reorganize_of_too_big_module(self):
+        """Test exception thrown by reorganize in case of too large modules."""
+        maximum_width = self.soi.CONTENT_WIDTH
+        maximum_height = self.soi.CONTENT_HEIGHT - self.soi.HEADER_HEIGHT
+
+        module_too_wide = {
+            "widget": TestModule("red", maximum_width + 1, 100),
+            "meta": {"x": 0, "y": 0, "page": 1, "name": "tall_module"},
+        }
+        module_too_tall = {
+            "widget": TestModule("red", 100, maximum_height + 1),
+            "meta": {"x": 0, "y": 0, "page": 1, "name": "tall_module"},
+        }
+        module_maximum_size = {
+            "widget": TestModule("red", maximum_width, maximum_height),
+            "meta": {"x": 0, "y": 0, "page": 1, "name": "tall_module"},
+        }
+
+        # too wide module should raise exception
+        self.soi.modules = [module_too_wide]
+        self.assertRaises(
+            ModuleLargerThanBinError, self.soi.reorganize,
+        )
+
+        # too tall module should raise exception
+        self.soi.modules = [module_too_tall]
+        self.assertRaises(
+            ModuleLargerThanBinError, self.soi.reorganize,
+        )
+
+        # module with maximum size shouldn't cause any exception
+        self.soi.modules = [module_maximum_size]
+        try:
+            self.soi.reorganize()
+        except ModuleLargerThanBinError:
+            self.fail(
+                "ModuleLargerThanBinError was raised even though module was "
+                "not too large"
+            )
-- 
GitLab