def test_release(self, mock_get_version): vpn = VPN(host='localhost', port=1234) self.assertIsNone(vpn._release) release_string = 'OpenVPN 2.4.4 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Sep 5 2018' mock_get_version.return_value = release_string self.assertEqual(vpn.release, release_string) self.assertEqual(vpn._release, release_string) mock_get_version.assert_called_once_with() mock_get_version.reset_mock() vpn._release = 'asd' self.assertEqual(vpn.release, 'asd') mock_get_version.assert_not_called()
def test_version(self, mock_get_version): vpn = VPN(host='localhost', port=1234) vpn._release = 'OpenVPN 2.4.4 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Sep 5 2018' self.assertEqual(vpn.version, '2.4.4') vpn._release = 'OpenVPN 1.2.3 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Sep 5 2018' self.assertEqual(vpn.version, '1.2.3') vpn._release = 'OpenVPN 11.22.33 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Sep 5 2018' self.assertEqual(vpn.version, '11.22.33') vpn._release = None mock_get_version.assert_not_called( ) # Check mock hasn't been triggered up to this point mock_get_version.return_value = None self.assertIsNone(vpn.version) mock_get_version.assert_called_once() mock_get_version.reset_mock() vpn._release = 'asd' with self.assertRaises(ParseError) as ctx: vpn.version() self.assertEqual('Unable to parse version from release string.', str(ctx.exception)) mock_get_version.assert_not_called()
def test_cache(self, release_mock, state_mock): """Test caching VPN metadata works and clears correctly. """ vpn = VPN(host='localhost', port=1234) vpn.cache_data() release_mock.assert_called_once() state_mock.assert_called_once() vpn._release = 'asd' vpn._state = 'qwe' vpn.clear_cache() self.assertIsNone(vpn._release) self.assertIsNone(vpn._state)