Skip to content

Commit e0ae92a

Browse files
committed
first saveplotlyconfig/credentials tests
1 parent db2eb46 commit e0ae92a

File tree

2 files changed

+144
-0
lines changed

2 files changed

+144
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
classdef testsaveplotlyconfig < 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+
% the basedomain must be specified.
27+
message = '';
28+
29+
try
30+
saveplotlyconfig;
31+
catch exception
32+
message = exception.message;
33+
end
34+
35+
expected_message = ...
36+
['Incorrect number of inputs. Please save your configuration ', ...
37+
'as follows: >> saveplotlyconfig(plotly_domain,', ...
38+
'[optional]plotly_streaming_domain)'];
39+
40+
testCase.verifyEqual(expected_message, message);
41+
end
42+
43+
function testSigninDomain(testCase)
44+
45+
% the user is signed in using the specified base domain.
46+
47+
% signin as test user
48+
signin(testCase.username,testCase.api_key, testCase.plotly_domain)
49+
50+
saveplotlyconfig('new_domain');
51+
[~, ~, expected_domain] = signin;
52+
53+
testCase.verifyEqual(expected_domain, 'new_domain');
54+
end
55+
56+
function testSigninDomainwithStream(testCase)
57+
58+
% the user is signed in using the specified base domain even
59+
% when both base and streaming domains are provided.
60+
61+
% signin as test user
62+
signin(testCase.username,testCase.api_key, testCase.plotly_domain)
63+
64+
saveplotlyconfig('new_domain', 'stream_domain');
65+
[~, ~, expected_domain] = signin;
66+
67+
testCase.verifyEqual(expected_domain, 'new_domain');
68+
end
69+
end
70+
end
71+
72+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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

Comments
 (0)