gooddata 0.6.0.pre11 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +12 -1
  3. data/.yardopts +2 -0
  4. data/README.md +6 -3
  5. data/Rakefile +24 -7
  6. data/gooddata +2 -2
  7. data/gooddata.gemspec +4 -3
  8. data/lib/gooddata.rb +17 -12
  9. data/lib/gooddata/bricks/base_downloader.rb +7 -7
  10. data/lib/gooddata/bricks/brick.rb +7 -8
  11. data/lib/gooddata/bricks/bricks.rb +4 -1
  12. data/lib/gooddata/bricks/middleware/base_middleware.rb +2 -2
  13. data/lib/gooddata/bricks/middleware/bench_middleware.rb +5 -6
  14. data/lib/gooddata/bricks/middleware/bulk_salesforce_middleware.rb +21 -22
  15. data/lib/gooddata/bricks/middleware/fs_upload_middleware.rb +3 -4
  16. data/lib/gooddata/bricks/middleware/gooddata_middleware.rb +14 -14
  17. data/lib/gooddata/bricks/middleware/logger_middleware.rb +6 -6
  18. data/lib/gooddata/bricks/middleware/middleware.rb +4 -1
  19. data/lib/gooddata/bricks/middleware/restforce_middleware.rb +29 -32
  20. data/lib/gooddata/bricks/middleware/stdout_middleware.rb +5 -5
  21. data/lib/gooddata/bricks/middleware/twitter_middleware.rb +6 -8
  22. data/lib/gooddata/bricks/utils.rb +3 -3
  23. data/lib/gooddata/cli/cli.rb +4 -2
  24. data/lib/gooddata/cli/commands/api_cmd.rb +6 -4
  25. data/lib/gooddata/cli/commands/auth_cmd.rb +5 -3
  26. data/lib/gooddata/cli/commands/console_cmd.rb +1 -1
  27. data/lib/gooddata/cli/commands/process_cmd.rb +6 -4
  28. data/lib/gooddata/cli/commands/profile_cmd.rb +5 -3
  29. data/lib/gooddata/cli/commands/project_cmd.rb +24 -22
  30. data/lib/gooddata/cli/commands/run_ruby_cmd.rb +12 -10
  31. data/lib/gooddata/cli/commands/scaffold_cmd.rb +8 -6
  32. data/lib/gooddata/cli/hooks.rb +4 -2
  33. data/lib/gooddata/cli/shared.rb +3 -1
  34. data/lib/gooddata/cli/terminal.rb +16 -0
  35. data/lib/gooddata/client.rb +28 -22
  36. data/lib/gooddata/commands/api.rb +43 -26
  37. data/lib/gooddata/commands/auth.rb +22 -53
  38. data/lib/gooddata/commands/base.rb +2 -0
  39. data/lib/gooddata/commands/commands.rb +3 -0
  40. data/lib/gooddata/commands/datasets.rb +39 -136
  41. data/lib/gooddata/commands/process.rb +134 -130
  42. data/lib/gooddata/commands/profile.rb +2 -0
  43. data/lib/gooddata/commands/projects.rb +91 -129
  44. data/lib/gooddata/commands/runners.rb +11 -11
  45. data/lib/gooddata/commands/scaffold.rb +28 -26
  46. data/lib/gooddata/connection.rb +61 -68
  47. data/lib/gooddata/core/core.rb +1 -2
  48. data/lib/gooddata/data/data.rb +7 -0
  49. data/lib/gooddata/data/guesser.rb +114 -0
  50. data/lib/gooddata/exceptions/command_failed.rb +7 -0
  51. data/lib/gooddata/exceptions/exceptions.rb +7 -0
  52. data/lib/gooddata/{exceptions.rb → exceptions/project_not_found.rb} +2 -2
  53. data/lib/gooddata/extensions/big_decimal.rb +5 -0
  54. data/lib/gooddata/extract.rb +2 -0
  55. data/lib/gooddata/goodzilla/goodzilla.rb +11 -12
  56. data/lib/gooddata/helpers.rb +49 -35
  57. data/lib/gooddata/models/attribute.rb +7 -5
  58. data/lib/gooddata/models/dashboard.rb +44 -45
  59. data/lib/gooddata/models/data_result.rb +10 -13
  60. data/lib/gooddata/models/data_set.rb +6 -6
  61. data/lib/gooddata/models/display_form.rb +4 -4
  62. data/lib/gooddata/models/empty_result.rb +4 -3
  63. data/lib/gooddata/models/fact.rb +5 -5
  64. data/lib/gooddata/models/links.rb +3 -1
  65. data/lib/gooddata/models/metadata.rb +34 -32
  66. data/lib/gooddata/models/metric.rb +33 -34
  67. data/lib/gooddata/models/model.rb +165 -173
  68. data/lib/gooddata/models/models.rb +3 -0
  69. data/lib/gooddata/models/process.rb +18 -17
  70. data/lib/gooddata/models/profile.rb +3 -1
  71. data/lib/gooddata/models/project.rb +107 -35
  72. data/lib/gooddata/models/project_metadata.rb +12 -12
  73. data/lib/gooddata/models/report.rb +31 -30
  74. data/lib/gooddata/models/report_data_result.rb +22 -19
  75. data/lib/gooddata/models/report_definition.rb +101 -80
  76. data/lib/gooddata/version.rb +5 -3
  77. data/lib/templates/bricks/brick.rb.erb +3 -3
  78. data/lib/templates/bricks/main.rb.erb +3 -2
  79. data/lib/templates/project/Goodfile.erb +2 -2
  80. data/lib/templates/project/model/model.rb.erb +19 -19
  81. data/spec/data/.gooddata +4 -0
  82. data/spec/helpers/blueprint_helper.rb +2 -2
  83. data/spec/helpers/cli_helper.rb +28 -0
  84. data/spec/helpers/connection_helper.rb +2 -2
  85. data/spec/integration/command_projects_spec.rb +1 -1
  86. data/spec/integration/create_from_template_spec.rb +12 -0
  87. data/spec/integration/full_project_spec.rb +2 -2
  88. data/spec/integration/partial_md_export_import_spec.rb +36 -0
  89. data/spec/logging_in_logging_out_spec.rb +1 -1
  90. data/spec/spec_helper.rb +29 -2
  91. data/spec/unit/cli/cli_spec.rb +3 -3
  92. data/spec/unit/cli/commands/cmd_api_spec.rb +21 -4
  93. data/spec/unit/cli/commands/cmd_auth_spec.rb +2 -4
  94. data/spec/unit/cli/commands/cmd_process_spec.rb +20 -4
  95. data/spec/unit/cli/commands/cmd_profile_spec.rb +9 -4
  96. data/spec/unit/cli/commands/cmd_project_spec.rb +53 -4
  97. data/spec/unit/cli/commands/cmd_run_ruby_spec.rb +2 -4
  98. data/spec/unit/cli/commands/cmd_scaffold_spec.rb +14 -4
  99. data/spec/unit/commands/command_api_spec.rb +21 -2
  100. data/spec/unit/commands/command_auth_spec.rb +62 -1
  101. data/spec/unit/commands/command_dataset_spec.rb +31 -3
  102. data/spec/unit/commands/command_process_spec.rb +75 -1
  103. data/spec/unit/commands/command_profile_spec.rb +7 -1
  104. data/spec/unit/commands/command_projects_spec.rb +1 -1
  105. data/spec/unit/commands/command_scaffold_spec.rb +46 -1
  106. data/spec/unit/core/connection_spec.rb +1 -0
  107. data/spec/unit/data/guesser_spec.rb +54 -0
  108. data/spec/unit/helpers_spec.rb +47 -0
  109. data/spec/unit/model/schema_builder_spec.rb +2 -0
  110. data/spec/unit/model/tools_spec.rb +89 -0
  111. data/test/test_upload.rb +39 -15
  112. metadata +98 -75
  113. data/test/test_commands.rb +0 -85
  114. data/test/test_guessing.rb +0 -46
  115. data/test/test_model.rb +0 -81
  116. data/test/test_rest_api_basic.rb +0 -41
@@ -0,0 +1,4 @@
1
+ {
2
+ "username": "svarovsky+gem_tester@gooddata.com",
3
+ "password": "jindrisska"
4
+ }
@@ -1,5 +1,5 @@
1
1
  # Global requires
2
- require 'json'
2
+ require 'multi_json'
3
3
 
4
4
  # Local requires
5
5
  require 'gooddata/models/models'
@@ -11,7 +11,7 @@ module BlueprintHelper
11
11
 
12
12
  # TODO: Try to load as relative path if failed
13
13
 
14
- parsed = JSON.parse(raw, :symbolize_names => true)
14
+ parsed = MultiJson.load(raw, :symbolize_keys => true)
15
15
  return GoodData::Model::ProjectBlueprint.new(parsed)
16
16
  end
17
17
  end
@@ -0,0 +1,28 @@
1
+ require 'gooddata/cli/cli'
2
+
3
+ module CliHelper
4
+ # Execute block and capture its stdou
5
+ # @param block Block to be executed with stdout redirected
6
+ # @returns Captured output as string
7
+ def capture_stdout(&block)
8
+ original_stdout = $stdout
9
+ $stdout = fake = StringIO.new
10
+ begin
11
+ yield
12
+ ensure
13
+ $stdout = original_stdout
14
+ end
15
+ fake.string
16
+ end
17
+
18
+ # Run CLI with arguments and return captured stdout
19
+ # @param args Arguments
20
+ # @return Captured stdout
21
+ def run_cli(args = [])
22
+ old = $0
23
+ $0 = 'gooddata'
24
+ res = capture_stdout { GoodData::CLI.main(args) }
25
+ $0 = old
26
+ res
27
+ end
28
+ end
@@ -2,11 +2,11 @@ require 'gooddata/connection'
2
2
 
3
3
  module ConnectionHelper
4
4
  GD_PROJECT_TOKEN = ENV["GD_PROJECT_TOKEN"]
5
- DEFAULT_USERNAME = "svarovsky+gem_tester@goddata.com"
5
+ DEFAULT_USERNAME = "svarovsky+gem_tester@gooddata.com"
6
6
  DEFAULT_PASSWORD = "jindrisska"
7
7
 
8
8
  def self.create_default_connection(username = DEFAULT_USERNAME, password = DEFAULT_PASSWORD)
9
- GoodData::Connection.new(username, password)
9
+ GoodData::connect(username, password)
10
10
  end
11
11
 
12
12
  end
@@ -7,7 +7,7 @@ describe GoodData::Command::Projects, :constraint => 'slow' do
7
7
  @blueprint = GoodData::Model::ProjectBlueprint.from_json("./spec/data/test_project_model_spec.json")
8
8
  @module_blueprint = GoodData::Model::ProjectBlueprint.from_json("./spec/data/additional_dataset_module.json")
9
9
 
10
- GoodData.connect("svarovsky+gem_tester@gooddata.com", "jindrisska")
10
+ ConnectionHelper::create_default_connection
11
11
  @project = GoodData::Command::Projects.build({:spec => @blueprint, :token => GD_PROJECT_TOKEN})
12
12
  end
13
13
 
@@ -0,0 +1,12 @@
1
+ require 'gooddata'
2
+
3
+ describe "Spin a project from template", :constraint => 'slow' do
4
+ before(:all) do
5
+ ConnectionHelper::create_default_connection
6
+ end
7
+
8
+ it "should spin a project from a template that does not exist. It should throw an error" do
9
+ expect{GoodData::Project.create(:title => "Test project", :template => "/some/nonexisting/tempalte/uri", :auth_token => ENV['GD_PROJECT_TOKEN'])}.to raise_error
10
+ end
11
+
12
+ end
@@ -2,8 +2,8 @@ require 'gooddata'
2
2
 
3
3
  describe "Spin a project", :constraint => 'slow' do
4
4
  before(:all) do
5
- spec = JSON.parse(File.read("./spec/data/test_project_model_spec.json"), :symbolize_names => true)
6
- GoodData.connect("svarovsky+gem_tester@gooddata.com", "jindrisska")
5
+ spec = MultiJson.load(File.read("./spec/data/test_project_model_spec.json"), :symbolize_keys => true)
6
+ ConnectionHelper::create_default_connection
7
7
 
8
8
  @project = GoodData::Model::ProjectCreator.migrate({:spec => spec, :token => GD_PROJECT_TOKEN})
9
9
  end
@@ -0,0 +1,36 @@
1
+ require 'gooddata'
2
+
3
+ describe "Spin a project", :constraint => 'slow' do
4
+ before(:all) do
5
+ spec = MultiJson.load(File.read("./spec/data/test_project_model_spec.json"), :symbolize_keys => true)
6
+ ConnectionHelper::create_default_connection
7
+
8
+ @source_project = GoodData::Model::ProjectCreator.migrate({:spec => spec, :token => GD_PROJECT_TOKEN})
9
+ @target_project = GoodData::Model::ProjectCreator.migrate({:spec => spec, :token => GD_PROJECT_TOKEN})
10
+ end
11
+
12
+ after(:all) do
13
+ @source_project.delete unless @source_project.nil?
14
+ @target_project.delete unless @target_project.nil?
15
+ end
16
+
17
+ it "should transfer a metric" do
18
+ GoodData.with_project(@source_project) do |p|
19
+ f = GoodData::Fact.find_first_by_title('Lines changed')
20
+ metric_title = "Testing metric to be exported"
21
+ metric = GoodData::Metric.xcreate(:expression => "SELECT SUM(#\"#{f.title}\")", :title => metric_title)
22
+ metric.save
23
+
24
+ GoodData.with_project(@target_project) {|p| GoodData::Metric[:all].count.should == 0}
25
+ p.partial_md_export([metric.uri], :project => @target_project)
26
+ GoodData.with_project(@target_project) do |p|
27
+ GoodData::Metric[:all].count.should == 1
28
+ metric = GoodData::Metric.find_first_by_title(metric_title)
29
+ metric.should_not be_nil
30
+ metric.title.should == metric_title
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+ end
@@ -5,7 +5,7 @@ describe GoodData::Connection, :constraint => 'slow' do
5
5
 
6
6
  it "should log in and disconnect" do
7
7
 
8
- GoodData.connect("svarovsky+gem_tester@gooddata.com", "jindrisska")
8
+ ConnectionHelper::create_default_connection
9
9
  GoodData.get("/gdc/md")
10
10
 
11
11
  conn = GoodData.connection
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,38 @@
1
+ require 'simplecov'
1
2
  require 'rspec'
3
+ require 'coveralls'
4
+ require 'pathname'
5
+
6
+ Coveralls.wear!
2
7
 
3
8
  # Automagically include all helpers/*_helper.rb
4
9
 
5
- require File.join(File.dirname(__FILE__), 'helpers/blueprint_helper')
6
- require File.join(File.dirname(__FILE__), 'helpers/connection_helper.rb')
10
+ base = Pathname(__FILE__).dirname.expand_path
11
+ Dir.glob(base + 'helpers/*_helper.rb').each do |file|
12
+ require file
13
+ end
7
14
 
8
15
  RSpec.configure do |config|
9
16
  include BlueprintHelper
17
+ include CliHelper
10
18
  include ConnectionHelper
11
19
  end
20
+
21
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
22
+ SimpleCov::Formatter::HTMLFormatter,
23
+ Coveralls::SimpleCov::Formatter
24
+ ]
25
+
26
+ SimpleCov.start do
27
+ add_filter 'spec/'
28
+ add_filter 'test/'
29
+
30
+ add_group 'Bricks', 'lib/gooddata/bricks'
31
+ add_group 'CLI', 'lib/gooddata/cli'
32
+ add_group 'Commands', 'lib/gooddata/commands'
33
+ add_group 'Core', 'lib/gooddata/core'
34
+ add_group 'Exceptions', 'lib/gooddata/exceptions'
35
+ add_group 'Extensions', 'lib/gooddata/extensions'
36
+ add_group 'Goodzilla', 'lib/gooddata/goodzilla'
37
+ add_group 'Models', 'lib/gooddata/models'
38
+ end
@@ -1,11 +1,11 @@
1
1
  require 'gooddata/cli/cli'
2
2
 
3
3
  describe GoodData::CLI do
4
- it "Has GoodData::CLI class" do
4
+ it 'Has GoodData::CLI class' do
5
5
  GoodData::CLI.should_not == nil
6
6
  end
7
7
 
8
- it "Has GoodData::CLI::main() working" do
9
- GoodData::CLI.main([])
8
+ it 'Has GoodData::CLI::main() working' do
9
+ run_cli
10
10
  end
11
11
  end
@@ -2,10 +2,27 @@ require 'gooddata/cli/cli'
2
2
 
3
3
  describe GoodData::CLI do
4
4
  it "Has working 'api' command" do
5
- args = [
6
- 'api'
7
- ]
5
+ args = %w(api)
8
6
 
9
- GoodData::CLI.main(args)
7
+ out = run_cli(args)
8
+ out.should include("Command 'api' requires a subcommand info,get")
9
+ end
10
+
11
+ it "Has working 'api info' command" do
12
+ args = %w(api info)
13
+
14
+ run_cli(args)
15
+ end
16
+
17
+ it "Has working 'api get' command" do
18
+ args = %w(api get)
19
+
20
+ run_cli(args)
21
+ end
22
+
23
+ it "Has working 'api get /gdc' command" do
24
+ args = %w(api get /gdc)
25
+
26
+ run_cli(args)
10
27
  end
11
28
  end
@@ -2,10 +2,8 @@ require 'gooddata/cli/cli'
2
2
 
3
3
  describe GoodData::CLI do
4
4
  it "Has working 'auth' command" do
5
- args = [
6
- 'auth'
7
- ]
5
+ args = %w(auth)
8
6
 
9
- GoodData::CLI.main(args)
7
+ run_cli(args)
10
8
  end
11
9
  end
@@ -2,10 +2,26 @@ require 'gooddata/cli/cli'
2
2
 
3
3
  describe GoodData::CLI do
4
4
  it "Has working 'process' command" do
5
- args = [
6
- 'process'
7
- ]
5
+ args = %w(process)
8
6
 
9
- GoodData::CLI.main(args)
7
+ run_cli(args)
8
+ end
9
+
10
+ it "Has working 'process deploy' command" do
11
+ args = %w(process deploy)
12
+
13
+ run_cli(args)
14
+ end
15
+
16
+ it "Has working 'process get' command" do
17
+ args = %w(process get)
18
+
19
+ run_cli(args)
20
+ end
21
+
22
+ it "Has working 'process list' command" do
23
+ args = %w(process list)
24
+
25
+ run_cli(args)
10
26
  end
11
27
  end
@@ -2,10 +2,15 @@ require 'gooddata/cli/cli'
2
2
 
3
3
  describe GoodData::CLI do
4
4
  it "Has working 'profile' command" do
5
- args = [
6
- 'profile'
7
- ]
5
+ args = %w(profile)
8
6
 
9
- GoodData::CLI.main(args)
7
+ out = run_cli(args)
8
+ out.should include("Command 'profile' requires a subcommand show")
9
+ end
10
+
11
+ it "Has working 'profile show' command" do
12
+ args = %w(profile show)
13
+
14
+ run_cli(args)
10
15
  end
11
16
  end
@@ -2,10 +2,59 @@ require 'gooddata/cli/cli'
2
2
 
3
3
  describe GoodData::CLI do
4
4
  it "Has working 'project' command" do
5
- args = [
6
- 'project'
7
- ]
5
+ args = %w(project)
8
6
 
9
- GoodData::CLI.main(args)
7
+ run_cli(args)
10
8
  end
9
+
10
+ it "Has working 'project build' command" do
11
+ args = %w(project build)
12
+
13
+ run_cli(args)
14
+ end
15
+
16
+ it "Has working 'project clone' command" do
17
+ args = %w(project clone)
18
+
19
+ run_cli(args)
20
+ end
21
+
22
+ it "Has working 'project create' command" do
23
+ args = %w(project create)
24
+
25
+ # TODO: Pass all required args to prevent interaction
26
+ # TODO: Investigate, fix and enable execution
27
+ # run_cli(args)
28
+ end
29
+
30
+ it "Has working 'project delete' command" do
31
+ args = %w(project delete)
32
+
33
+ run_cli(args)
34
+ end
35
+
36
+ it "Has working 'project jack_in' command" do
37
+ args = %w(project jack_in)
38
+
39
+ run_cli(args)
40
+ end
41
+
42
+ it "Has working 'project list' command" do
43
+ args = %w(project list)
44
+
45
+ run_cli(args)
46
+ end
47
+
48
+ it "Has working 'project show' command" do
49
+ args = %w(project show)
50
+
51
+ run_cli(args)
52
+ end
53
+
54
+ it "Has working 'project update' command" do
55
+ args = %w(project update)
56
+
57
+ run_cli(args)
58
+ end
59
+
11
60
  end
@@ -2,10 +2,8 @@ require 'gooddata/cli/cli'
2
2
 
3
3
  describe GoodData::CLI do
4
4
  it "Has working 'run_ruby' command" do
5
- args = [
6
- 'run_ruby'
7
- ]
5
+ args = %w(run_ruby)
8
6
 
9
- GoodData::CLI.main(args)
7
+ run_cli(args)
10
8
  end
11
9
  end
@@ -2,10 +2,20 @@ require 'gooddata/cli/cli'
2
2
 
3
3
  describe GoodData::CLI do
4
4
  it "Has working 'scaffold' command" do
5
- args = [
6
- 'scaffold'
7
- ]
5
+ args = %w(scaffold)
8
6
 
9
- GoodData::CLI.main(args)
7
+ run_cli(args)
8
+ end
9
+
10
+ it "Has working 'scaffold brick' command" do
11
+ args = %w(scaffold brick)
12
+
13
+ run_cli(args)
14
+ end
15
+
16
+ it "Has working 'scaffold project' command" do
17
+ args = %w(scaffold project)
18
+
19
+ run_cli(args)
10
20
  end
11
21
  end
@@ -2,11 +2,30 @@ require 'gooddata/commands/api'
2
2
 
3
3
  describe GoodData::Command::Api do
4
4
  before(:each) do
5
- @connection = ConnectionHelper::create_default_connection
5
+ ConnectionHelper::create_default_connection
6
6
  end
7
7
 
8
- it "Is Possible to create GoodData::Command::Profile instance" do
8
+ it "Is Possible to create GoodData::Command::Api instance" do
9
9
  cmd = GoodData::Command::Api.new()
10
10
  cmd.should be_a(GoodData::Command::Api)
11
11
  end
12
+
13
+ describe "#get" do
14
+ it "Call without arguments" do
15
+ GoodData::Command::Api.test()
16
+ end
17
+ end
18
+
19
+ describe "#delete" do
20
+ it "Call without arguments" do
21
+ GoodData::Command::Api.test()
22
+ end
23
+ end
24
+
25
+ describe "#test" do
26
+ it "Call without arguments" do
27
+ GoodData::Command::Api.test()
28
+ end
29
+ end
30
+
12
31
  end