aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorgan Richomme <morgan.richomme@orange.com>2016-11-17 15:43:03 +0100
committerMorgan Richomme <morgan.richomme@orange.com>2016-11-21 17:31:34 +0100
commit23fa2fcb5517fafafe6e5263088ceddbb51c3d55 (patch)
tree44ccdb9ff64a5e23f31521d12cb5a8bb53661c5d /tests
parent9de1ded9cf18dfce75d1a85c54242c74e3133fcd (diff)
Add Exceptions and Constants in opnfv module
JIRA: FUNCTEST-497 Change-Id: I4bc0d545058c4778b632911bb317789110de29d1 Signed-off-by: Morgan Richomme <morgan.richomme@orange.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/unit/__init__.py0
-rw-r--r--tests/unit/utils/__init__.py0
-rw-r--r--tests/unit/utils/test_OPNFVExceptions.py74
4 files changed, 74 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/__init__.py
diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/unit/__init__.py
diff --git a/tests/unit/utils/__init__.py b/tests/unit/utils/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/unit/utils/__init__.py
diff --git a/tests/unit/utils/test_OPNFVExceptions.py b/tests/unit/utils/test_OPNFVExceptions.py
new file mode 100644
index 0000000..fca927b
--- /dev/null
+++ b/tests/unit/utils/test_OPNFVExceptions.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2016 Orange and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0import requests
+import unittest
+import requests
+
+from opnfv.utils import OPNFVExceptions
+
+
+def base_function():
+ raise OPNFVExceptions.TestDbNotReachable('Test database is not reachable')
+
+
+def base_function_wrong():
+ raise OPNFVExceptions.NotSelfDefinedException
+
+
+def db_connectivity():
+ url = 'http://testresults.opnfv2.org/test/api/v1/projects/functest/cases'
+ r = requests.get(url)
+ if r.status_code is not 200:
+ raise OPNFVExceptions.TestDbNotReachable('Database not found')
+
+
+def project_unknown():
+ url = 'http://testresults.opnfv.org/test/api/v1/projects/functest2/cases'
+ r = requests.get(url)
+ if len(r.json()['testcases']) is 0:
+ raise OPNFVExceptions.UnknownProject
+
+
+class TestBasicRaise(unittest.TestCase):
+ def test(self):
+ with self.assertRaises(Exception) as context:
+ base_function()
+ self.assertTrue('Test database is not reachable' in context.exception)
+
+
+class TestWrongRaise(unittest.TestCase):
+ def test(self):
+ try:
+ base_function_wrong()
+ except OPNFVExceptions.OPNFVException:
+ assert(False)
+ except AttributeError:
+ assert(True)
+
+
+class TestCaseDBNotReachable(unittest.TestCase):
+ def test(self):
+ with self.assertRaises(Exception) as context:
+ db_connectivity()
+ self.assertTrue('Database not found' in context.exception)
+
+
+class TestUnkownProject(unittest.TestCase):
+ def test(self):
+ try:
+ project_unknown()
+ except OPNFVExceptions.TestDashboardError:
+ # should not be there
+ assert(False)
+ except OPNFVExceptions.UnknownProject:
+ assert(True)
+ except Exception:
+ assert(False)
+
+if __name__ == '__main__':
+ unittest.main()