summaryrefslogtreecommitdiff
path: root/src/leap/common/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/common/tests')
-rw-r--r--src/leap/common/tests/__init__.py0
-rw-r--r--src/leap/common/tests/test_certs.py99
-rw-r--r--src/leap/common/tests/test_check.py53
-rw-r--r--src/leap/common/tests/test_http.py75
-rw-r--r--src/leap/common/tests/test_memoize.py76
5 files changed, 0 insertions, 303 deletions
diff --git a/src/leap/common/tests/__init__.py b/src/leap/common/tests/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/src/leap/common/tests/__init__.py
+++ /dev/null
diff --git a/src/leap/common/tests/test_certs.py b/src/leap/common/tests/test_certs.py
deleted file mode 100644
index 8ebc0f4..0000000
--- a/src/leap/common/tests/test_certs.py
+++ /dev/null
@@ -1,99 +0,0 @@
-# -*- coding: utf-8 -*-
-# test_certs.py
-# Copyright (C) 2013 LEAP
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-"""
-Tests for:
- * leap/common/certs.py
-"""
-import os
-import time
-
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
-
-from leap.common import certs
-from leap.common.testing.basetest import BaseLeapTest
-
-TEST_CERT_PEM = os.path.join(
- os.path.split(__file__)[0],
- '..', 'testing', "leaptest_combined_keycert.pem")
-
-# Values from the test cert file:
-# Not Before: Sep 3 17:52:16 2013 GMT
-# Not After : Sep 1 17:52:16 2023 GMT
-CERT_NOT_BEFORE = (2013, 9, 3, 17, 52, 16, 1, 246, 0)
-CERT_NOT_AFTER = (2023, 9, 1, 17, 52, 16, 4, 244, 0)
-
-
-class CertsTest(BaseLeapTest):
-
- def setUp(self):
- self.setUpEnv()
-
- def tearDown(self):
- self.tearDownEnv()
-
- def test_should_redownload_if_no_cert(self):
- self.assertTrue(certs.should_redownload(certfile=""))
-
- def test_should_redownload_if_invalid_pem(self):
- cert_path = self.get_tempfile('test_pem_file.pem')
-
- with open(cert_path, 'w') as f:
- f.write('this is some invalid data for the pem file')
-
- self.assertTrue(certs.should_redownload(cert_path))
-
- def test_should_redownload_if_before(self):
- def new_now():
- time.struct_time(CERT_NOT_BEFORE)
- self.assertTrue(certs.should_redownload(TEST_CERT_PEM, now=new_now))
-
- def test_should_redownload_if_after(self):
- def new_now():
- time.struct_time(CERT_NOT_AFTER)
- self.assertTrue(certs.should_redownload(TEST_CERT_PEM, now=new_now))
-
- def test_not_should_redownload(self):
- self.assertFalse(certs.should_redownload(TEST_CERT_PEM))
-
- def test_is_valid_pemfile(self):
- with open(TEST_CERT_PEM) as f:
- cert_data = f.read()
-
- self.assertTrue(certs.is_valid_pemfile(cert_data))
-
- def test_not_is_valid_pemfile(self):
- cert_data = 'this is some invalid data for the pem file'
-
- self.assertFalse(certs.is_valid_pemfile(cert_data))
-
- def test_get_cert_time_boundaries(self):
- """
- This test ensures us that the returned values are returned in UTC/GMT.
- """
- with open(TEST_CERT_PEM) as f:
- cert_data = f.read()
-
- valid_from, valid_to = certs.get_cert_time_boundaries(cert_data)
- self.assertEqual(tuple(valid_from), CERT_NOT_BEFORE)
- self.assertEqual(tuple(valid_to), CERT_NOT_AFTER)
-
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/src/leap/common/tests/test_check.py b/src/leap/common/tests/test_check.py
deleted file mode 100644
index cd488ff..0000000
--- a/src/leap/common/tests/test_check.py
+++ /dev/null
@@ -1,53 +0,0 @@
-# -*- coding: utf-8 -*-
-# test_check.py
-# Copyright (C) 2013 LEAP
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-"""
-Tests for:
- * leap/common/check.py
-"""
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
-
-import mock
-
-from leap.common import check
-
-
-class CheckTests(unittest.TestCase):
- def test_raises_on_false_condition(self):
- with self.assertRaises(AssertionError):
- check.leap_assert(False, "Condition")
-
- def test_raises_on_none_condition(self):
- with self.assertRaises(AssertionError):
- check.leap_assert(None, "Condition")
-
- def test_suceeds_with_good_condition(self):
- check.leap_assert(True, "")
-
- def test_raises_on_bad_type(self):
- with self.assertRaises(AssertionError):
- check.leap_assert_type(42, str)
-
- def test_succeeds_on_good_type(self):
- check.leap_assert_type(42, int)
-
- @mock.patch("traceback.extract_stack", mock.MagicMock(return_value=None))
- def test_does_not_raise_on_bug(self):
- with self.assertRaises(AssertionError):
- check.leap_assert(False, "")
diff --git a/src/leap/common/tests/test_http.py b/src/leap/common/tests/test_http.py
deleted file mode 100644
index f44550f..0000000
--- a/src/leap/common/tests/test_http.py
+++ /dev/null
@@ -1,75 +0,0 @@
-# -*- coding: utf-8 -*-
-# test_http.py
-# Copyright (C) 2013 LEAP
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-"""
-Tests for:
- * leap/common/http.py
-"""
-import os
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
-
-from leap.common import http
-from leap.common.testing.basetest import BaseLeapTest
-
-TEST_CERT_PEM = os.path.join(
- os.path.split(__file__)[0],
- '..', 'testing', "leaptest_combined_keycert.pem")
-
-
-class HTTPClientTest(BaseLeapTest):
-
- def setUp(self):
- pass
-
- def tearDown(self):
- pass
-
- def test_agents_sharing_pool_by_default(self):
- client = http.HTTPClient()
- client2 = http.HTTPClient(TEST_CERT_PEM)
- self.assertNotEquals(
- client._agent, client2._agent, "Expected dedicated agents")
- self.assertEquals(
- client._agent._pool, client2._agent._pool,
- "Pool was not reused by default")
-
- def test_agent_can_have_dedicated_custom_pool(self):
- custom_pool = http._HTTPConnectionPool(
- None,
- timeout=10,
- maxPersistentPerHost=42,
- persistent=False
- )
- self.assertEquals(custom_pool.maxPersistentPerHost, 42,
- "Custom persistent connections "
- "limit is not being respected")
- self.assertFalse(custom_pool.persistent,
- "Custom persistence is not being respected")
- default_client = http.HTTPClient()
- custom_client = http.HTTPClient(pool=custom_pool)
-
- self.assertNotEquals(
- default_client._agent, custom_client._agent,
- "No agent reuse is expected")
- self.assertEquals(
- custom_pool, custom_client._agent._pool,
- "Custom pool usage was not respected")
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/src/leap/common/tests/test_memoize.py b/src/leap/common/tests/test_memoize.py
deleted file mode 100644
index c923fc5..0000000
--- a/src/leap/common/tests/test_memoize.py
+++ /dev/null
@@ -1,76 +0,0 @@
-# -*- coding: utf-8 -*-
-# test_check.py
-# Copyright (C) 2013 LEAP
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-"""
-Tests for:
- * leap/common/decorators._memoized
-"""
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
-
-from time import sleep
-
-import mock
-
-from leap.common.decorators import _memoized
-
-
-class MemoizeTests(unittest.TestCase):
-
- def test_memoized_call(self):
- """
- Test that a memoized function only calls once.
- """
- witness = mock.Mock()
-
- @_memoized
- def callmebaby():
- return witness()
-
- for i in range(10):
- callmebaby()
- witness.assert_called_once_with()
-
- def test_cache_invalidation(self):
- """
- Test that time makes the cache invalidation expire.
- """
- witness = mock.Mock()
-
- cache_with_alzheimer = _memoized
- cache_with_alzheimer.CACHE_INVALIDATION_DELTA = 1
-
- @cache_with_alzheimer
- def callmebaby(*args):
- return witness(*args)
-
- for i in range(10):
- callmebaby()
- witness.assert_called_once_with()
-
- sleep(2)
- callmebaby("onemoretime")
-
- expected = [mock.call(), mock.call("onemoretime")]
- self.assertEqual(
- witness.call_args_list,
- expected)
-
-
-if __name__ == "__main__":
- unittest.main()