aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--func/fetchimg.py58
-rw-r--r--test-requirements.txt1
-rw-r--r--tests/fetchimg_test.py22
3 files changed, 51 insertions, 30 deletions
diff --git a/func/fetchimg.py b/func/fetchimg.py
index 1c621a3b..6cae426e 100644
--- a/func/fetchimg.py
+++ b/func/fetchimg.py
@@ -1,30 +1,28 @@
-##############################################################################
-# Copyright (c) 2015 Dell Inc 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.0
-##############################################################################
-
-
-
-import os
-import time
-
-
-class FetchImg:
-
- def __init__(self):
- print 'Fetching Image!'
- print 'Fetching QTIP_VM Image'
-
- def download(self):
- time.sleep(2)
- os.system(
- 'mkdir -p Temp_Img && wget http://artifacts.opnfv.org/qtip/QTIP_CentOS.qcow2 -P Temp_Img')
-
- filepath = './Temp_Img/QTIP_CentOS.qcow2'
- while not os.path.isfile(filepath):
- time.sleep(10)
- print 'Download Completed!'
+##############################################################################
+# Copyright (c) 2015 Dell Inc 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.0
+##############################################################################
+import os
+import time
+
+
+class FetchImg:
+
+ def __init__(self):
+ print 'Fetching Image!'
+ print 'Fetching QTIP_VM Image'
+
+ @staticmethod
+ def download():
+ time.sleep(2)
+ os.system(
+ 'mkdir -p Temp_Img && wget http://artifacts.opnfv.org/qtip/QTIP_CentOS.qcow2 -P Temp_Img')
+
+ filepath = './Temp_Img/QTIP_CentOS.qcow2'
+ while not os.path.isfile(filepath):
+ time.sleep(10)
+ print 'Download Completed!'
diff --git a/test-requirements.txt b/test-requirements.txt
index cdac2380..31581503 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -4,3 +4,4 @@
pytest
pykwalify
+mock
diff --git a/tests/fetchimg_test.py b/tests/fetchimg_test.py
new file mode 100644
index 00000000..683c9701
--- /dev/null
+++ b/tests/fetchimg_test.py
@@ -0,0 +1,22 @@
+import mock
+from func.fetchimg import FetchImg
+
+
+class TestClass:
+ @mock.patch('func.fetchimg.os')
+ @mock.patch('func.fetchimg.os.path')
+ def test_fetch_img_success(self, mock_path, mock_os):
+ mock_os.system.return_value = True
+ mock_path.isfile.return_value = True
+ img = FetchImg()
+ img.download()
+
+ @mock.patch('func.fetchimg.time')
+ @mock.patch('func.fetchimg.os.system')
+ @mock.patch('func.fetchimg.os.path')
+ def test_fetch_img_fail(self, mock_path, mock_system, mock_time):
+ img = FetchImg()
+ mock_system.return_value = True
+ mock_path.isfile.side_effect = [False, True]
+ img.download()
+ assert mock_time.sleep.call_count == 2