Starting point

Change-Id: I86dab2674688f6d818ce2fb0861ea893d6841df3
diff --git a/test/test_tosca_parser.py b/test/test_tosca_parser.py
new file mode 100644
index 0000000..eb31ed1
--- /dev/null
+++ b/test/test_tosca_parser.py
@@ -0,0 +1,74 @@
+import sys, os
+import unittest
+from mock import patch, MagicMock
+from tosca.parser import TOSCA_Parser
+
+class FakeObj:
+    new = None
+    filter = None
+
+class FakeResource:
+    objects = FakeObj
+
+class FakeModel:
+    save = None
+
+class TOSCA_Parser_Create_or_update_Test(unittest.TestCase):
+
+    @patch.object(FakeResource.objects, "filter")
+    @patch.object(FakeResource.objects, "new", MagicMock(return_value=FakeModel))
+    @patch.object(FakeModel, "save")
+    def test_new_model(self, mock_save, mock_filter):
+        """
+        [TOSCA_Parser] create_or_update: should create a new model
+        """
+        data = {
+            "name": "test"
+        }
+
+        TOSCA_Parser.creat_or_update(FakeResource, data)
+        mock_filter.assert_called_with(name="test")
+        mock_save.assert_called_once()
+
+    @patch.object(FakeResource.objects, "filter", MagicMock(return_value=[FakeModel]))
+    @patch.object(FakeModel, "save")
+    def test_existing_model(self, mock_save):
+        """
+        [TOSCA_Parser] create_or_update: should update an existing model
+        """
+        data = {
+            "name": "test"
+        }
+
+        TOSCA_Parser.creat_or_update(FakeResource, data)
+        mock_save.assert_called_once()
+
+    @patch.object(FakeResource.objects, "filter", MagicMock(return_value=['a', 'b']))
+    def test_multiple_models(self):
+        """
+        [TOSCA_Parser] create_or_update: should raise an exception if multiple instances are found
+        """
+        data = {
+            "name": "test"
+        }
+        with self.assertRaises(Exception) as e:
+            TOSCA_Parser.creat_or_update(FakeResource, data)
+        self.assertEqual(e.exception.message, "[XOS-Tosca] Model test has multiple instances, I can't handle it")
+
+    @patch.object(FakeResource.objects, "new", MagicMock(return_value=FakeModel))
+    @patch.object(FakeResource.objects, "filter")
+    @patch.object(FakeModel, "save")
+    def test_find_model_without_name_property(self, mock_save, mock_filter):
+        """
+        [TOSCA_Parser] create_or_update: should lookup a model by the first property
+        """
+        data = {
+            'foo': 'bar',
+            'something': 'else'
+        }
+        TOSCA_Parser.creat_or_update(FakeResource, data)
+        mock_filter.assert_called_with(foo="bar")
+        mock_save.assert_called_once()
+
+if __name__ == '__main__':
+    unittest.main()
\ No newline at end of file