|
| 1 | +classdef testsaveplotlycredentials < matlab.unittest.TestCase |
| 2 | + |
| 3 | + properties |
| 4 | + creds = loadplotlycredentials; |
| 5 | + config = loadplotlyconfig; |
| 6 | + username = 'test_user_name'; |
| 7 | + api_key = 'test_api_key'; |
| 8 | + stream_ids = {'test_stream_key1','test_stream_key2'}; |
| 9 | + plotly_domain = 'test_plotly_domain'; |
| 10 | + plotly_streaming_domain = 'test_plotly_streaming_domain'; |
| 11 | + end |
| 12 | + |
| 13 | + methods(TestMethodTeardown) |
| 14 | + function setCredentials(testCase) |
| 15 | + saveplotlycredentials(testCase.creds.username,testCase.creds.api_key,testCase.creds.stream_ids); |
| 16 | + end |
| 17 | + function setConfig(testCase) |
| 18 | + saveplotlyconfig(testCase.config.plotly_domain,testCase.config.plotly_streaming_domain); |
| 19 | + end |
| 20 | + end |
| 21 | + |
| 22 | + methods (Test) |
| 23 | + |
| 24 | + function testWrongNumberOfInputs(testCase) |
| 25 | + |
| 26 | + % both username and api_key must be specified. |
| 27 | + message = ''; |
| 28 | + |
| 29 | + try |
| 30 | + saveplotlycredentials('test'); |
| 31 | + catch exception |
| 32 | + message = exception.message; |
| 33 | + end |
| 34 | + |
| 35 | + expected_message = ... |
| 36 | + ['Incorrect number of inputs. Please save your credentials ', ... |
| 37 | + 'as follows: >> saveplotlycredentials(username, api_key,', ... |
| 38 | + '[optional]stream_ids)']; |
| 39 | + |
| 40 | + testCase.verifyEqual(expected_message, message); |
| 41 | + end |
| 42 | + |
| 43 | + function testSigninUsernameAPIKey(testCase) |
| 44 | + |
| 45 | + % the user is signed in using the specified username and api_key. |
| 46 | + |
| 47 | + % signin as test user |
| 48 | + signin(testCase.username, testCase.api_key) |
| 49 | + |
| 50 | + saveplotlycredentials('new_username', 'new_api_key'); |
| 51 | + [expected_username, expected_api_key] = signin; |
| 52 | + |
| 53 | + testCase.verifyEqual(expected_username, 'new_username'); |
| 54 | + testCase.verifyEqual(expected_api_key, 'new_api_key'); |
| 55 | + end |
| 56 | + |
| 57 | + function testSigninUsernameAPIKeyandStream(testCase) |
| 58 | + |
| 59 | + % the user is signed in using the specified username and api_key |
| 60 | + % even when the streaming tokens are provided. |
| 61 | + |
| 62 | + % signin as test user |
| 63 | + signin(testCase.username, testCase.api_key) |
| 64 | + |
| 65 | + saveplotlycredentials('new_username', 'new_api_key', {'new_stream_token'}); |
| 66 | + [expected_username, expected_api_key] = signin; |
| 67 | + |
| 68 | + testCase.verifyEqual(expected_username, 'new_username'); |
| 69 | + testCase.verifyEqual(expected_api_key, 'new_api_key'); |
| 70 | + end |
| 71 | + end |
| 72 | +end |
0 commit comments