|
1 |
| -from __future__ import absolute_import |
2 |
| - |
3 |
| -import plotly.tools as tls |
4 |
| - |
5 |
| - |
6 |
| -def test_reset_config_file(): |
7 |
| - tls.reset_config_file() |
8 |
| - config = tls.get_config_file() |
9 |
| - assert config['plotly_domain'] == 'https://plot.ly' |
10 |
| - assert config['plotly_streaming_domain'] == 'stream.plot.ly' |
11 |
| - |
12 |
| - |
13 |
| -def test_set_config_file(): |
14 |
| - pd, ps = 'this', 'thing' |
15 |
| - ssl_verify, proxy_auth = True, True |
16 |
| - tls.set_config_file(plotly_domain=pd, plotly_streaming_domain=ps, |
17 |
| - plotly_ssl_verification=ssl_verify, |
18 |
| - plotly_proxy_authorization=proxy_auth) |
19 |
| - config = tls.get_config_file() |
20 |
| - assert config['plotly_domain'] == pd |
21 |
| - assert config['plotly_streaming_domain'] == ps |
22 |
| - assert config['plotly_ssl_verification'] == ssl_verify |
23 |
| - assert config['plotly_proxy_authorization'] == proxy_auth |
24 |
| - tls.reset_config_file() # else every would hate me :) |
25 |
| - |
26 |
| - |
27 |
| -def test_credentials_tools(): |
28 |
| - original_creds = tls.get_credentials_file() |
29 |
| - expected = ['username', 'stream_ids', 'api_key', 'proxy_username', |
30 |
| - 'proxy_password'] |
31 |
| - assert all(x in original_creds for x in expected) |
32 |
| - |
33 |
| - # now, if that worked, we can try this! |
34 |
| - tls.reset_credentials_file() |
35 |
| - reset_creds = tls.get_credentials_file() |
36 |
| - tls.set_credentials_file(**original_creds) |
37 |
| - assert all(x in reset_creds for x in expected) |
38 |
| - creds = tls.get_credentials_file() |
39 |
| - assert all(x in creds for x in expected) |
40 |
| - assert original_creds == creds |
| 1 | +from plotly import tools, session |
| 2 | +from plotly.tests.utils import PlotlyTestCase |
| 3 | + |
| 4 | + |
| 5 | +class FileToolsTest(PlotlyTestCase): |
| 6 | + |
| 7 | + def test_set_config_file_all_entries(self): |
| 8 | + |
| 9 | + # Check set_config and get_config return the same values |
| 10 | + |
| 11 | + domain, streaming_domain, api = 'this', 'thing', 'that' |
| 12 | + ssl_verify, proxy_auth, readable = True, True, True |
| 13 | + tools.set_config_file(plotly_domain=domain, |
| 14 | + plotly_streaming_domain=streaming_domain, |
| 15 | + plotly_api_domain=api, |
| 16 | + plotly_ssl_verification=ssl_verify, |
| 17 | + plotly_proxy_authorization=proxy_auth, |
| 18 | + world_readable=readable) |
| 19 | + config = tools.get_config_file() |
| 20 | + self.assertEqual(config['plotly_domain'], domain) |
| 21 | + self.assertEqual(config['plotly_streaming_domain'], streaming_domain) |
| 22 | + self.assertEqual(config['plotly_api_domain'], api) |
| 23 | + self.assertEqual(config['plotly_ssl_verification'], ssl_verify) |
| 24 | + self.assertEqual(config['plotly_proxy_authorization'], proxy_auth) |
| 25 | + self.assertEqual(config['world_readable'], readable) |
| 26 | + tools.reset_config_file() |
| 27 | + |
| 28 | + def test_set_config_file_two_entries(self): |
| 29 | + |
| 30 | + # Check set_config and get_config given only two entries return the |
| 31 | + # same values |
| 32 | + |
| 33 | + domain, streaming_domain = 'this', 'thing' |
| 34 | + tools.set_config_file(plotly_domain=domain, |
| 35 | + plotly_streaming_domain=streaming_domain) |
| 36 | + config = tools.get_config_file() |
| 37 | + self.assertEqual(config['plotly_domain'], domain) |
| 38 | + self.assertEqual(config['plotly_streaming_domain'], streaming_domain) |
| 39 | + tools.reset_config_file() |
| 40 | + |
| 41 | + def test_session_plot_option(self): |
| 42 | + |
| 43 | + # Check if the session_plot_option and config_plot_optin return the |
| 44 | + # same value |
| 45 | + |
| 46 | + readable = False |
| 47 | + tools.set_config_file(world_readable=readable) |
| 48 | + session_plot_option = session.get_session_plot_options() |
| 49 | + self.assertEqual(session_plot_option['world_readable'], readable) |
| 50 | + tools.reset_config_file() |
| 51 | + |
| 52 | + def test_set_config_file_world_readable(self): |
| 53 | + |
| 54 | + # Return TypeError when world_readable type is not a dict |
| 55 | + |
| 56 | + kwargs = {'world_readable': 'True'} |
| 57 | + self.assertRaises(TypeError, tools.set_config_file, **kwargs) |
| 58 | + |
| 59 | + def test_reset_config_file(self): |
| 60 | + |
| 61 | + # Check reset_config and get_config return the same values |
| 62 | + |
| 63 | + tools.reset_config_file() |
| 64 | + config = tools.get_config_file() |
| 65 | + self.assertEqual(config['plotly_domain'], 'https://plot.ly') |
| 66 | + self.assertEqual(config['plotly_streaming_domain'], 'stream.plot.ly') |
| 67 | + |
| 68 | + def test_get_credentials_file(self): |
| 69 | + |
| 70 | + # Check get_credentials returns all the keys |
| 71 | + |
| 72 | + original_creds = tools.get_credentials_file() |
| 73 | + expected = ['username', 'stream_ids', 'api_key', 'proxy_username', |
| 74 | + 'proxy_password'] |
| 75 | + self.assertTrue(all(x in original_creds for x in expected)) |
| 76 | + |
| 77 | + def test_reset_credentials_file(self): |
| 78 | + |
| 79 | + # Check get_cred return all the keys |
| 80 | + |
| 81 | + tools.reset_credentials_file() |
| 82 | + reset_creds = tools.get_credentials_file() |
| 83 | + expected = ['username', 'stream_ids', 'api_key', 'proxy_username', |
| 84 | + 'proxy_password'] |
| 85 | + self.assertTrue(all(x in reset_creds for x in expected)) |
0 commit comments