epc 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/Gemfile +22 -0
- data/Rakefile +67 -0
- data/Rakefile.gem +1 -0
- data/bin/epc +10 -0
- data/lib/epc.rb +126 -0
- data/lib/epc/client/base_client.rb +80 -0
- data/lib/epc/client/http_client.rb +19 -0
- data/lib/epc/client/json_client.rb +48 -0
- data/lib/epc/command/archive_project_command.rb +24 -0
- data/lib/epc/command/archive_solution_command.rb +21 -0
- data/lib/epc/command/attach_library_command.rb +82 -0
- data/lib/epc/command/attach_libraryset_command.rb +32 -0
- data/lib/epc/command/attach_runtime_command.rb +27 -0
- data/lib/epc/command/base_command.rb +451 -0
- data/lib/epc/command/bind_service_command.rb +35 -0
- data/lib/epc/command/build_command.rb +83 -0
- data/lib/epc/command/config/create_config_command.rb +55 -0
- data/lib/epc/command/copy_deployment_command.rb +21 -0
- data/lib/epc/command/create_command.rb +13 -0
- data/lib/epc/command/create_dependency_command.rb +43 -0
- data/lib/epc/command/define_service_command.rb +37 -0
- data/lib/epc/command/delete_config_command.rb +63 -0
- data/lib/epc/command/delete_dependency_command.rb +40 -0
- data/lib/epc/command/delete_group_command.rb +40 -0
- data/lib/epc/command/delete_library_command.rb +30 -0
- data/lib/epc/command/delete_librarylanguage_command.rb +40 -0
- data/lib/epc/command/delete_libraryset_command.rb +40 -0
- data/lib/epc/command/delete_project_command.rb +54 -0
- data/lib/epc/command/delete_role_command.rb +25 -0
- data/lib/epc/command/delete_serviceversion_command.rb +52 -0
- data/lib/epc/command/delete_solution_command.rb +39 -0
- data/lib/epc/command/delete_user_command.rb +31 -0
- data/lib/epc/command/deploy_command.rb +142 -0
- data/lib/epc/command/deployment/create_deployment_command.rb +82 -0
- data/lib/epc/command/detach_library_command.rb +35 -0
- data/lib/epc/command/detach_libraryset_command.rb +8 -0
- data/lib/epc/command/group/create_group_command.rb +21 -0
- data/lib/epc/command/info_command.rb +11 -0
- data/lib/epc/command/library/create_library_command.rb +45 -0
- data/lib/epc/command/librarylanguage/create_librarylanguage_command.rb +24 -0
- data/lib/epc/command/libraryset/create_libraryset_command.rb +54 -0
- data/lib/epc/command/list_approvals_command.rb +27 -0
- data/lib/epc/command/list_attachedlibraries_command.rb +42 -0
- data/lib/epc/command/list_boundservices_command.rb +40 -0
- data/lib/epc/command/list_config_command.rb +60 -0
- data/lib/epc/command/list_dependencies_command.rb +43 -0
- data/lib/epc/command/list_deployments_command.rb +68 -0
- data/lib/epc/command/list_groups_command.rb +19 -0
- data/lib/epc/command/list_libraries_command.rb +19 -0
- data/lib/epc/command/list_librarylanguages_command.rb +19 -0
- data/lib/epc/command/list_librarysets_command.rb +26 -0
- data/lib/epc/command/list_objectroles_command.rb +25 -0
- data/lib/epc/command/list_objecttypes_command.rb +20 -0
- data/lib/epc/command/list_permissiongroups_command.rb +20 -0
- data/lib/epc/command/list_projects_command.rb +36 -0
- data/lib/epc/command/list_projecttypes_command.rb +20 -0
- data/lib/epc/command/list_rolepermissions_command.rb +21 -0
- data/lib/epc/command/list_roles_command.rb +26 -0
- data/lib/epc/command/list_runtimes_command.rb +16 -0
- data/lib/epc/command/list_service_types_command.rb +19 -0
- data/lib/epc/command/list_servicedefinitions_command.rb +19 -0
- data/lib/epc/command/list_serviceversions_command.rb +21 -0
- data/lib/epc/command/list_solutions_command.rb +25 -0
- data/lib/epc/command/list_stages_command.rb +21 -0
- data/lib/epc/command/list_users_command.rb +26 -0
- data/lib/epc/command/list_versions_command.rb +39 -0
- data/lib/epc/command/login_command.rb +32 -0
- data/lib/epc/command/logout_command.rb +20 -0
- data/lib/epc/command/objectrole/create_objectrole_command.rb +19 -0
- data/lib/epc/command/project/create_project_command.rb +78 -0
- data/lib/epc/command/pull_command.rb +209 -0
- data/lib/epc/command/push_command.rb +194 -0
- data/lib/epc/command/refresh_solution_command.rb +71 -0
- data/lib/epc/command/renew_command.rb +19 -0
- data/lib/epc/command/request_passwordchange_command.rb +23 -0
- data/lib/epc/command/role/create_role_command.rb +17 -0
- data/lib/epc/command/serviceversion/create_serviceversion_command.rb +33 -0
- data/lib/epc/command/show_deployment_command.rb +57 -0
- data/lib/epc/command/show_group_command.rb +35 -0
- data/lib/epc/command/show_libraryset_command.rb +54 -0
- data/lib/epc/command/show_project_command.rb +74 -0
- data/lib/epc/command/show_projecttype_command.rb +18 -0
- data/lib/epc/command/show_role_command.rb +46 -0
- data/lib/epc/command/show_solution_command.rb +54 -0
- data/lib/epc/command/show_user_command.rb +42 -0
- data/lib/epc/command/solution/create_solution_command.rb +34 -0
- data/lib/epc/command/solution/list_solutions_command.rb +25 -0
- data/lib/epc/command/solution/update_solution_command.rb +43 -0
- data/lib/epc/command/submit_deployment_command.rb +19 -0
- data/lib/epc/command/target_command.rb +26 -0
- data/lib/epc/command/unarchive_project_command.rb +23 -0
- data/lib/epc/command/unarchive_solution_command.rb +21 -0
- data/lib/epc/command/unbind_service_command.rb +42 -0
- data/lib/epc/command/undefine_service_command.rb +33 -0
- data/lib/epc/command/undeploy_command.rb +106 -0
- data/lib/epc/command/update_config_command.rb +62 -0
- data/lib/epc/command/update_deploymentproject_command.rb +54 -0
- data/lib/epc/command/update_group_command.rb +43 -0
- data/lib/epc/command/update_librarylanguage_command.rb +28 -0
- data/lib/epc/command/update_libraryset_command.rb +80 -0
- data/lib/epc/command/update_project_command.rb +49 -0
- data/lib/epc/command/update_role_command.rb +47 -0
- data/lib/epc/command/update_rolepermissions_command.rb +83 -0
- data/lib/epc/command/update_solution_command.rb +45 -0
- data/lib/epc/command/update_user_command.rb +57 -0
- data/lib/epc/command/user/create_user_command.rb +27 -0
- data/lib/epc/command/vote_deployment_command.rb +29 -0
- data/lib/epc/config.rb +245 -0
- data/lib/epc/error/basic_error.rb +6 -0
- data/lib/epc/error/fatal_error.rb +6 -0
- data/lib/epc/error/input_error.rb +6 -0
- data/lib/epc/error/internal_error.rb +6 -0
- data/lib/epc/help.rb +292 -0
- data/lib/epc/persistent_attributes.rb +18 -0
- data/lib/epc/runner.rb +177 -0
- data/lib/epc/tabular_outputter.rb +161 -0
- data/lib/epc/version.rb +3 -0
- data/lib/fixnum.rb +9 -0
- data/lib/object.rb +13 -0
- data/test/command/archive_project_command_test.rb +41 -0
- data/test/command/archive_solution_command_test.rb +40 -0
- data/test/command/attach_library_command_test.rb +124 -0
- data/test/command/attach_libraryset_command_test.rb +49 -0
- data/test/command/attach_runtime_command_test.rb +44 -0
- data/test/command/base_command_test.rb +276 -0
- data/test/command/bind_service_command_test.rb +46 -0
- data/test/command/build_command_test.rb +103 -0
- data/test/command/copy_deployment_command_test.rb +38 -0
- data/test/command/create_config_command_test.rb +124 -0
- data/test/command/create_dependency_command_test.rb +55 -0
- data/test/command/create_deployment_command_test.rb +136 -0
- data/test/command/create_group_command_test.rb +34 -0
- data/test/command/create_library_command_test.rb +61 -0
- data/test/command/create_librarylanguage_command_test.rb +51 -0
- data/test/command/create_libraryset_command_test.rb +81 -0
- data/test/command/create_objectrole_command_test.rb +37 -0
- data/test/command/create_project_command_test.rb +102 -0
- data/test/command/create_role_command_test.rb +31 -0
- data/test/command/create_serviceversion_command_test.rb +60 -0
- data/test/command/create_solution_command_test.rb +70 -0
- data/test/command/create_user_command_test.rb +54 -0
- data/test/command/define_service_command_test.rb +55 -0
- data/test/command/delete_config_command_test.rb +82 -0
- data/test/command/delete_dependency_command_test.rb +50 -0
- data/test/command/delete_group_command_test.rb +56 -0
- data/test/command/delete_library_command_test.rb +43 -0
- data/test/command/delete_librarylanguage_command_test.rb +55 -0
- data/test/command/delete_libraryset_command_test.rb +55 -0
- data/test/command/delete_project_command_test.rb +76 -0
- data/test/command/delete_role_command_test.rb +41 -0
- data/test/command/delete_serviceversion_command_test.rb +53 -0
- data/test/command/delete_solution_command_test.rb +79 -0
- data/test/command/delete_user_command_test.rb +56 -0
- data/test/command/deploy_command_test.rb +185 -0
- data/test/command/detach_library_command_test.rb +53 -0
- data/test/command/info_command_test.rb +17 -0
- data/test/command/list_approvals_command_test.rb +41 -0
- data/test/command/list_boundservices_command_test.rb +46 -0
- data/test/command/list_config_command_test.rb +72 -0
- data/test/command/list_dependencies_command_test.rb +46 -0
- data/test/command/list_deployments_command_test.rb +112 -0
- data/test/command/list_deploymentstages_command_test.rb +44 -0
- data/test/command/list_libraries_command_test.rb +42 -0
- data/test/command/list_librarylanguages_command_test.rb +34 -0
- data/test/command/list_librarysets_command_test.rb +33 -0
- data/test/command/list_objectroles_command_test.rb +41 -0
- data/test/command/list_objecttypes_command_test.rb +25 -0
- data/test/command/list_permissiongroups_command_test.rb +25 -0
- data/test/command/list_projects_command_test.rb +63 -0
- data/test/command/list_projecttypes_command_test.rb +39 -0
- data/test/command/list_rolepermissions_command_test.rb +39 -0
- data/test/command/list_roles_command_test.rb +46 -0
- data/test/command/list_runtimes_command_test.rb +30 -0
- data/test/command/list_service_types_command_test.rb +44 -0
- data/test/command/list_servicedefinitions_command_test.rb +44 -0
- data/test/command/list_serviceversions_command_test.rb +47 -0
- data/test/command/list_solutions_command_test.rb +48 -0
- data/test/command/list_users_command_test.rb +33 -0
- data/test/command/login_command_test.rb +83 -0
- data/test/command/logout_command_test.rb +30 -0
- data/test/command/pull_command_test.rb +229 -0
- data/test/command/push_command_test.rb +246 -0
- data/test/command/refresh_solution_command_test.rb +35 -0
- data/test/command/renew_command_test.rb +43 -0
- data/test/command/request_passwordchange_command_test.rb +31 -0
- data/test/command/show_group_command_test.rb +50 -0
- data/test/command/show_libraryset_command_test.rb +51 -0
- data/test/command/show_project_command_test.rb +57 -0
- data/test/command/show_projecttype_command_test.rb +46 -0
- data/test/command/show_role_command_test.rb +37 -0
- data/test/command/show_solution_command_test.rb +59 -0
- data/test/command/show_user_command_test.rb +50 -0
- data/test/command/submit_deployment_command_test.rb +37 -0
- data/test/command/target_command_test.rb +58 -0
- data/test/command/unarchive_project_command_test.rb +45 -0
- data/test/command/unarchive_solution_command_test.rb +43 -0
- data/test/command/unbind_service_command_test.rb +48 -0
- data/test/command/undefine_service_command_test.rb +49 -0
- data/test/command/update_config_command_test.rb +74 -0
- data/test/command/update_deploymentproject_command_test.rb +77 -0
- data/test/command/update_group_command_test.rb +69 -0
- data/test/command/update_librarylanguage_command_test.rb +43 -0
- data/test/command/update_libraryset_command_test.rb +113 -0
- data/test/command/update_project_command_test.rb +56 -0
- data/test/command/update_role_command_test.rb +42 -0
- data/test/command/update_rolepermissions_command_test.rb +54 -0
- data/test/command/update_solution_command_test.rb +58 -0
- data/test/command/update_user_command_test.rb +76 -0
- data/test/command/vote_deployment_command_test.rb +33 -0
- data/test/config_test.rb +70 -0
- data/test/successful_test.rb +21 -0
- data/test/test_files/pom.xml +273 -0
- data/test/test_helper.rb +25 -0
- metadata +470 -0
@@ -0,0 +1,246 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PushCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "execute" do
|
7
|
+
setup do
|
8
|
+
@mock_client = mock("Client")
|
9
|
+
@mock_config = mock("Config")
|
10
|
+
@command = EPC::Command::PushCommand.new(@mock_client)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "fail if solution can't be inferred" do
|
14
|
+
@command.expects(:infer_solution_context).returns(nil)
|
15
|
+
assert_raise EPC::Error::FatalError do
|
16
|
+
@command.execute
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
should "fail if current directory is not a solution/project directory" do
|
21
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
22
|
+
EPC::Config.expects(:is_solution_dir?).returns(false)
|
23
|
+
EPC::Config.expects(:is_project_dir?).returns(false)
|
24
|
+
@command.expects(:say)
|
25
|
+
assert_equal(@command.execute, 1)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "push all projects if run from solution directory with no project name specified" do
|
29
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
30
|
+
EPC::Config.expects(:is_solution_dir?).returns(true)
|
31
|
+
@command.expects(:ask_yn).returns("Y")
|
32
|
+
|
33
|
+
assert_raise EPC::Error::FatalError do
|
34
|
+
@command.execute
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
should "push only the specified project from the solution directory" do
|
39
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
40
|
+
EPC::Config.expects(:is_solution_dir?).with(File.expand_path(".")).returns(true)
|
41
|
+
@command.expects(:infer_project_context).with("MyProj", File.expand_path("."), 1, {:get_project_name => true}).returns([1, "FirstProject"])
|
42
|
+
|
43
|
+
@command.expects(:ask_yn).returns('n')
|
44
|
+
|
45
|
+
@command.execute("MyProj")
|
46
|
+
end
|
47
|
+
|
48
|
+
should "zip, push, confirm and poll for build status" do
|
49
|
+
command = EPC::Command::PushCommand.new(@mock_client)
|
50
|
+
|
51
|
+
expected_path = File.expand_path(".")
|
52
|
+
expected_zip_path = File.join(expected_path, "pushed.zip")
|
53
|
+
expected_url = "http://www.there.com/solution/project/version/pushed.zip"
|
54
|
+
|
55
|
+
command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
56
|
+
|
57
|
+
EPC::Config.expects(:is_solution_dir?).returns(false)
|
58
|
+
EPC::Config.expects(:is_project_dir?).returns(true)
|
59
|
+
command.expects(:infer_project_context).returns([1, "FirstProject"])
|
60
|
+
|
61
|
+
command.expects(:ask_yn).returns('Y')
|
62
|
+
|
63
|
+
command.expects(:infer_project_context).returns([1, "FirstProject"])
|
64
|
+
command.expects(:say).with("\nPushing FirstProject...")
|
65
|
+
command.expects(:zip_source).with(expected_path).returns(expected_zip_path)
|
66
|
+
command.expects(:sha1).with(expected_zip_path).returns('aabbcc')
|
67
|
+
command.expects(:create_push).with("FirstProject", "FirstSolution", "aabbcc", nil).returns([202, expected_url, 'ddeeff', 1])
|
68
|
+
command.expects(:push_zip).with(expected_zip_path, expected_url, 'ddeeff').returns(true)
|
69
|
+
command.expects(:confirm_push).with(1).returns({:id => 1, :build_id=> 1, :project_version => 2})
|
70
|
+
command.expects(:poll_for_build_status).with(1)
|
71
|
+
|
72
|
+
command.execute
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
context "create_push" do
|
78
|
+
setup do
|
79
|
+
@mock_client = mock("Client")
|
80
|
+
|
81
|
+
EPC::Config.target_file = '~/.epc_test_target'
|
82
|
+
end
|
83
|
+
|
84
|
+
should "return true, the url and signature if the status is 202" do
|
85
|
+
command = EPC::Command::PushCommand.new(@mock_client)
|
86
|
+
|
87
|
+
@mock_client.expects(:post).with("/api/v1/pushes",
|
88
|
+
{ :project_name => 'Test Project', :solution_name => "Test Solution", :sha1 => "abcdef", :note => nil}).
|
89
|
+
returns([202, { :url => "http://there.com/repo", :signature => "xxyyzz", :id => 1 }, {}])
|
90
|
+
command.expects(:say).with("Successfully created a push with [http://localhost:3000]")
|
91
|
+
|
92
|
+
status, url, signature, id = command.send(:create_push, "Test Project", "Test Solution", "abcdef")
|
93
|
+
|
94
|
+
assert_equal 202, status
|
95
|
+
assert_equal("http://there.com/repo", url)
|
96
|
+
assert_equal("xxyyzz", signature)
|
97
|
+
assert_equal(1, id)
|
98
|
+
end
|
99
|
+
|
100
|
+
should "raise a BasicError if the status is not 202" do
|
101
|
+
command = EPC::Command::PushCommand.new(@mock_client)
|
102
|
+
|
103
|
+
@mock_client.expects(:post).with("/api/v1/pushes",
|
104
|
+
{ :project_name => 'Test Project', :solution_name => "Test Solution", :sha1 => "abcdef", :note => nil }).
|
105
|
+
returns([404, { :message => "Not Found" }, {}])
|
106
|
+
# command.expects(:say).with("Push creation failed [Not Found]. Aborting push command.")
|
107
|
+
|
108
|
+
assert_raise EPC::Error::BasicError do
|
109
|
+
status, url, signature, id = command.send(:create_push, "Test Project", "Test Solution", "abcdef")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "confirm_push" do
|
115
|
+
setup do
|
116
|
+
@mock_client = mock("Client")
|
117
|
+
|
118
|
+
EPC::Config.target_file = '~/.epc_test_target'
|
119
|
+
end
|
120
|
+
|
121
|
+
should "return true if the status is 200" do
|
122
|
+
command = EPC::Command::PushCommand.new(@mock_client)
|
123
|
+
|
124
|
+
@mock_client.expects(:put).with("/api/v1/pushes/1/confirm",
|
125
|
+
{ :pushed => "yes" }).returns([200, { :id => 1 }, {}])
|
126
|
+
command.expects(:say).with("Successfully confirmed the push with [http://localhost:3000]")
|
127
|
+
|
128
|
+
confirmed = command.send(:confirm_push, 1)
|
129
|
+
|
130
|
+
assert(confirmed)
|
131
|
+
end
|
132
|
+
|
133
|
+
should "return false if the status is not 200" do
|
134
|
+
command = EPC::Command::PushCommand.new(@mock_client)
|
135
|
+
|
136
|
+
@mock_client.expects(:put).with("/api/v1/pushes/1/confirm",
|
137
|
+
{ :pushed => "yes" }).returns([404, { :message => "Not Found" }, {}])
|
138
|
+
command.expects(:say).with("Push confirmation failed [Not Found].")
|
139
|
+
|
140
|
+
confirmed = command.send(:confirm_push, 1)
|
141
|
+
|
142
|
+
assert_nil(confirmed)
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
context "zip_source" do
|
148
|
+
setup do
|
149
|
+
@mock_client = mock("Client")
|
150
|
+
end
|
151
|
+
|
152
|
+
should "create a zip file based on the src files" do
|
153
|
+
command = EPC::Command::PushCommand.new(@mock_client)
|
154
|
+
|
155
|
+
|
156
|
+
command.expects(:check_push_directory).returns(true)
|
157
|
+
command.expects(:recurse_project_directory).returns(
|
158
|
+
[["toplevel/lib/foo.jar", "toplevel/src/foo1.java", "toplevel/src/foo2.java"],
|
159
|
+
["lib/foo.jar", "src/foo1.java", "src/foo2.java"]])
|
160
|
+
|
161
|
+
expected_path = File.expand_path(".")
|
162
|
+
expected_zip_path = File.join(expected_path, "pushed.zip")
|
163
|
+
|
164
|
+
mock_zf = mock("Zip::ZipFile")
|
165
|
+
Zip::ZipFile.expects(:open).yields(mock_zf)
|
166
|
+
mock_zf.expects(:add).with("lib/foo.jar", "toplevel/lib/foo.jar")
|
167
|
+
mock_zf.expects(:add).with("src/foo1.java", "toplevel/src/foo1.java")
|
168
|
+
mock_zf.expects(:add).with("src/foo2.java", "toplevel/src/foo2.java")
|
169
|
+
|
170
|
+
zip_path = command.send(:zip_source, expected_path)
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context "push_zip" do
|
176
|
+
setup do
|
177
|
+
@mock_client = mock("Client")
|
178
|
+
end
|
179
|
+
|
180
|
+
should "return true if the status is 200" do
|
181
|
+
command = EPC::Command::PushCommand.new(@mock_client)
|
182
|
+
command.expects(:http_client).returns(@mock_client)
|
183
|
+
|
184
|
+
expected_path = File.expand_path(".")
|
185
|
+
expected_zip_path = File.join(expected_path, "pushed.zip")
|
186
|
+
|
187
|
+
expected_base_url = "http://www.there.com/solution/project/version"
|
188
|
+
|
189
|
+
mock_file = mock("File")
|
190
|
+
File.expects(:new).with(expected_zip_path, "rb").returns(mock_file)
|
191
|
+
|
192
|
+
@mock_client.expects(:post).with("#{expected_base_url}",
|
193
|
+
{ :file => mock_file }, nil, { 'X-AGILEMETHODS-SIGNATURE' => 'ddeeff' }, true).
|
194
|
+
returns([200, {}, {}])
|
195
|
+
command.expects(:say).with("Successfully pushed the zip file to the build area")
|
196
|
+
|
197
|
+
pushed = command.send(:push_zip, expected_zip_path, expected_base_url, 'ddeeff')
|
198
|
+
|
199
|
+
assert(pushed)
|
200
|
+
end
|
201
|
+
|
202
|
+
should "return false if the status is not 200" do
|
203
|
+
command = EPC::Command::PushCommand.new(@mock_client)
|
204
|
+
command.expects(:http_client).returns(@mock_client)
|
205
|
+
|
206
|
+
expected_path = File.expand_path(".")
|
207
|
+
expected_zip_path = File.join(expected_path, "pushed.zip")
|
208
|
+
|
209
|
+
expected_base_url = "http://www.there.com/solution/project/version"
|
210
|
+
|
211
|
+
mock_file = mock("File")
|
212
|
+
File.expects(:new).with(expected_zip_path, "rb").returns(mock_file)
|
213
|
+
|
214
|
+
@mock_client.expects(:post).with("#{expected_base_url}",
|
215
|
+
{ :file => mock_file }, nil, { 'X-AGILEMETHODS-SIGNATURE' => 'ddeeff' }, true).
|
216
|
+
returns([500, {}, {}])
|
217
|
+
|
218
|
+
assert_raise EPC::Error::BasicError do
|
219
|
+
pushed = command.send(:push_zip, expected_zip_path, expected_base_url, 'ddeeff')
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
context "check push directory" do
|
226
|
+
setup do
|
227
|
+
@mock_client = mock("Client")
|
228
|
+
@command = EPC::Command::PushCommand.new(@mock_client)
|
229
|
+
end
|
230
|
+
|
231
|
+
should "notify if path does not exist" do
|
232
|
+
File.expects(:exists?).returns(false)
|
233
|
+
@command.expects(:say)
|
234
|
+
assert_equal(@command.send(:check_push_directory, "path"), false)
|
235
|
+
end
|
236
|
+
|
237
|
+
should "notify if path is not a directory" do
|
238
|
+
File.expects(:exists?).returns(true)
|
239
|
+
File.expects(:directory?).returns(false)
|
240
|
+
@command.expects(:say)
|
241
|
+
assert_equal(@command.send(:check_push_directory, "path"), false)
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RefreshSolutionCommandTest < Test::Unit::TestCase
|
4
|
+
context "execute" do
|
5
|
+
setup do
|
6
|
+
@mock_client = mock("Client")
|
7
|
+
@command = EPC::Command::RefreshSolutionCommand.new(@mock_client)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "fail if solution can't be inferred" do
|
11
|
+
@command.expects(:infer_solution_context).returns(nil)
|
12
|
+
assert_raise EPC::Error::FatalError do
|
13
|
+
@command.execute
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
should "prompt the user" do
|
19
|
+
@command.options[:prompt_refresh] = true
|
20
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
21
|
+
@command.expects(:ask_yn).returns("N")
|
22
|
+
@command.execute
|
23
|
+
end
|
24
|
+
|
25
|
+
should "fail if it can't retrieve data about solution" do
|
26
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
27
|
+
@command.expects(:ask_yn).returns("Y")
|
28
|
+
@mock_client.expects(:get).returns([500, {:message => "System exception"}, {}])
|
29
|
+
@command.expects(:say)
|
30
|
+
@command.execute
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RenewCommandTest < Test::Unit::TestCase
|
4
|
+
context "execute" do
|
5
|
+
setup do
|
6
|
+
@mock_client = mock("Client")
|
7
|
+
@mock_config = mock("Config")
|
8
|
+
end
|
9
|
+
|
10
|
+
should "update the auth_token if the status is 200" do
|
11
|
+
command = EPC::Command::RenewCommand.new(@mock_client)
|
12
|
+
|
13
|
+
@mock_client.expects(:put).with("/api/v1/tokens/renew").returns([200, { :authentication_token => 'wxyz' }, {}])
|
14
|
+
EPC::Config.expects(:store_auth_token).with('wxyz')
|
15
|
+
|
16
|
+
command.expects(:say)
|
17
|
+
command.execute
|
18
|
+
end
|
19
|
+
|
20
|
+
should "not update the auth_token if the status is not 200" do
|
21
|
+
command = EPC::Command::RenewCommand.new(@mock_client)
|
22
|
+
|
23
|
+
@mock_client.expects(:put).with("/api/v1/tokens/renew").
|
24
|
+
returns([500, { :message => "Error talking with the database." }, {}])
|
25
|
+
EPC::Config.expects(:store_auth_token).never
|
26
|
+
command.expects(:say)
|
27
|
+
command.execute
|
28
|
+
end
|
29
|
+
|
30
|
+
should "catch and handle exceptions" do
|
31
|
+
command = EPC::Command::RenewCommand.new(@mock_client)
|
32
|
+
|
33
|
+
@mock_client.expects(:put).with("/api/v1/tokens/renew").returns([200, { :authentication_token => 'wxyz' }, {}])
|
34
|
+
EPC::Config.expects(:store_auth_token).with('wxyz').raises(Exception)
|
35
|
+
|
36
|
+
command.expects(:say)
|
37
|
+
command.execute
|
38
|
+
end
|
39
|
+
|
40
|
+
should_require_login
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RequestPasswordchangeCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "execution" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@mock_client = mock("Client")
|
10
|
+
@command = EPC::Command::RequestPasswordchangeCommand.new(@mock_client)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "fail if no email is given" do
|
14
|
+
assert_raise EPC::Error::FatalError do
|
15
|
+
@command.execute
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "fail if the status is unsuccessful" do
|
20
|
+
@mock_client.expects(:put).with(EPC::Config::USERS_PATH + "/user@epaas.com/change_password_request").returns([500, {:message => "System exception"}, {}])
|
21
|
+
@command.expects(:say).with("Request failed: [System exception]")
|
22
|
+
@command.execute("user@epaas.com")
|
23
|
+
end
|
24
|
+
|
25
|
+
should "send the request" do
|
26
|
+
@mock_client.expects(:put).with(EPC::Config::USERS_PATH + "/user@epaas.com/change_password_request").returns([200, {:id => 1}, {}])
|
27
|
+
@command.expects(:say).with("Request successfully sent.")
|
28
|
+
@command.execute("user@epaas.com")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ShowGroupCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "execute" do
|
7
|
+
setup do
|
8
|
+
@mock_client = mock("Client")
|
9
|
+
@command = EPC::Command::ShowGroupCommand.new(@mock_client)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "fail if no group is specified" do
|
13
|
+
assert_raise EPC::Error::FatalError do
|
14
|
+
assert_equal(@command.execute, 1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
should "fail if status is not 200" do
|
19
|
+
@mock_client.expects(:get).with(EPC::Config::GROUPS_PATH + "/1?include=users").
|
20
|
+
returns([404, {:message => "Not Found"}, {}])
|
21
|
+
@command.expects(:say).with("Request failed: [Not Found]")
|
22
|
+
assert_equal(@command.execute(1), 1)
|
23
|
+
end
|
24
|
+
|
25
|
+
should "fail if group_id can't be determined" do
|
26
|
+
@command.expects(:get_resource_id).with(EPC::Config::GROUPS_PATH, :name, "admins").returns(nil)
|
27
|
+
assert_raise EPC::Error::FatalError do
|
28
|
+
assert_equal(@command.execute("admins"), 1)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
should "show a group specified by id" do
|
33
|
+
@mock_client.expects(:get).with(EPC::Config::GROUPS_PATH + "/1?include=users").
|
34
|
+
returns([200, {}, {}])
|
35
|
+
@command.expects(:say).at_least_once
|
36
|
+
|
37
|
+
assert_equal(@command.execute(1), 200)
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
should "show a group specified by name" do
|
42
|
+
@command.expects(:get_resource_id).with(EPC::Config::GROUPS_PATH, :name, "admins").returns(1)
|
43
|
+
@mock_client.expects(:get).with(EPC::Config::GROUPS_PATH + "/1?include=users").
|
44
|
+
returns([200, {:id => 1, :name => "Grp1", :users => [{:id => 1, :name => "Group Leader", :email => "group_leader@epaas.com"}]}, {}])
|
45
|
+
@command.expects(:say).at_least_once
|
46
|
+
|
47
|
+
assert_equal(@command.execute("admins"), 200)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ShowLibrarysetCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "retrieval " do
|
7
|
+
setup do
|
8
|
+
@mock_client = mock("Client")
|
9
|
+
@command = EPC::Command::ShowLibrarysetCommand.new(@mock_client)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "fail if library set is not specified" do
|
13
|
+
@command.expects(:say).with("You must specify a library-set")
|
14
|
+
@command.expects(:say).with(EPC::Help::COMMAND_USAGES[:show_libraryset])
|
15
|
+
assert_equal(@command.execute, 1)
|
16
|
+
end
|
17
|
+
|
18
|
+
should "fail if library set id can't be determined" do
|
19
|
+
@command.expects(:get_resource_id).with(EPC::Config::LIBRARY_SETS_PATH, :name, "lib-set").returns(nil)
|
20
|
+
@command.expects(:say).with("Library set could not be determined")
|
21
|
+
assert_equal(@command.execute("lib-set"), 1)
|
22
|
+
end
|
23
|
+
|
24
|
+
should "show error if status is not 201" do
|
25
|
+
@mock_client.expects(:get).with(EPC::Config::LIBRARY_SETS_PATH+"/1").
|
26
|
+
returns([404, {:message => "Not Found"}, {}])
|
27
|
+
|
28
|
+
@command.expects(:say).with("Request failed: [Not Found]")
|
29
|
+
assert_equal(@command.execute(1), 404)
|
30
|
+
end
|
31
|
+
|
32
|
+
should "show details about the requested library set" do
|
33
|
+
@mock_client.expects(:get).with(EPC::Config::LIBRARY_SETS_PATH+"/1").
|
34
|
+
returns([200, {:id => 1, :name => "lib-set", :created_at => Time.now.to_s, :updated_at => Time.now.to_s, :libraries => [{:id => 1, :name => "lib1"}], :library_language => []}, {}])
|
35
|
+
|
36
|
+
@command.expects(:say).at_least_once
|
37
|
+
assert_equal(@command.execute(1), 200)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "output the results as json when --json is passed" do
|
41
|
+
@command.options[:json] = true
|
42
|
+
@mock_client.expects(:get).with(EPC::Config::LIBRARY_SETS_PATH+"/1").
|
43
|
+
returns([200, {:id => 1, :name => "lib-set", :libraries => [{:id => 1, :name => "lib1"}], :library_language => []}, {}])
|
44
|
+
|
45
|
+
@command.expects(:say)
|
46
|
+
assert_equal(@command.execute(1), 200)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|