Skip to content

Commit bcfbfb8

Browse files
author
Tomas Svarovsky
committed
Rewrote the test full_project to use the new syntax. Removing unused Mode::MdObject. Added SST logging + test
1 parent 07bb36c commit bcfbfb8

10 files changed

Lines changed: 120 additions & 148 deletions

File tree

lib/gooddata/mixins/md_relations.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
module GoodData
44
module Mixin
55
module MdRelations
6-
def dependency(uri, key = nil, opts = { :client => GoodData.connection, :project => GoodData.project })
6+
def dependency(uri, key = nil, opts = { :client => client, :project => project })
77
GoodData::MdObject.dependency(uri, key, opts)
88
end
99

1010
# Checks for dependency
11-
def dependency?(type, obj, opts = { :client => GoodData.connection, :project => GoodData.project })
11+
def dependency?(type, obj, opts = { :client => client, :project => project })
1212
GoodData::MdObject.dependency?(type, self, obj, opts)
1313
end
1414

1515
# Returns which objects uses this MD resource
16-
def usedby(key = nil, opts = { :client => GoodData.connection, :project => GoodData.project })
16+
def usedby(key = nil, opts = { :client => client, :project => project })
1717
p = opts[:project]
1818
fail ArgumentError, 'No :project specified' if p.nil?
1919

@@ -26,24 +26,21 @@ def usedby(key = nil, opts = { :client => GoodData.connection, :project => GoodD
2626
alias_method :used_by, :usedby
2727

2828
# Returns which objects this MD resource uses
29-
def using(key = nil, opts = { :client => GoodData.connection, :project => GoodData.project })
30-
p = opts[:project]
31-
fail ArgumentError, 'No :project specified' if p.nil?
32-
29+
def using(key = nil, opts = { :client => client, :project => project })
3330
project = opts[:project]
3431
fail ArgumentError, 'Wrong :project specified' if project.nil?
3532

3633
dependency("#{project.md['using2']}/#{obj_id}", key, opts)
3734
end
3835

39-
def usedby?(obj, opts = { :client => GoodData.connection, :project => GoodData.project })
36+
def usedby?(obj, opts = { :client => client, :project => project })
4037
GoodData::MdObject.used_by?(self, obj, opts)
4138
end
4239

4340
alias_method :used_by?, :usedby?
4441

4542
# Checks if obj is using this MD resource
46-
def using?(obj, opts = { :client => GoodData.connection, :project => GoodData.project })
43+
def using?(obj, opts = { :client => client, :project => project })
4744
dependency?(:using, obj, opts)
4845
end
4946
end

lib/gooddata/models/md_object.rb

Lines changed: 0 additions & 25 deletions
This file was deleted.

lib/gooddata/models/metadata/attribute.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def all(options = {})
3030
# @return [String] Textual representation of a particular attribute element
3131
def find_element_value(uri, opts = { :client => @client, :project => @project })
3232
matches = uri.match(/(.*)\/elements\?id=(\d+)$/)
33-
Attribute[matches[1], :client => opts[:client], :project => opts[:project]].primary_label.find_element_value(uri)
33+
opts[:project].attributes(matches[1]).primary_label.find_element_value(uri)
3434
end
3535
end
3636

lib/gooddata/models/metadata/report.rb

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,20 @@ def all(options = {})
1717
query('reports', Report, options)
1818
end
1919

20-
def create(options = {})
20+
def create(options = { :client => GoodData.connection, :project => GoodData.project })
21+
client = options[:client]
22+
fail ArgumentError, 'No :client specified' if client.nil?
23+
24+
p = options[:project]
25+
fail ArgumentError, 'No :project specified' if p.nil?
26+
27+
project = GoodData::Project[p, options]
28+
fail ArgumentError, 'Wrong :project specified' if project.nil?
29+
2130
title = options[:title]
31+
fail "Report needs a title specified" unless title
2232
summary = options[:summary] || ''
23-
rd = options[:rd] || ReportDefinition.create(:top => options[:top], :left => options[:left])
33+
rd = options[:rd] || ReportDefinition.create(options)
2434
rd.save
2535

2636
report = {
@@ -39,10 +49,20 @@ def create(options = {})
3949
}
4050
# TODO: write test for report definitions with explicit identifiers
4151
report['report']['meta']['identifier'] = options[:identifier] if options[:identifier]
42-
Report.new report
52+
client.create(Report, report, :project => project)
4353
end
4454
end
4555

56+
# Add a report definition to a report. This will show on a UI as a new version.
57+
#
58+
# @param report_definition [GoodData::ReportDefinition | String] Report definition to add. Either it can be a URI of a report definition or an actual report definition object.
59+
# @return [GoodData::Report] Return self
60+
def add_definition(report_definition)
61+
rep_def = project.report_definitions(report_definition)
62+
content['definitions'] = definition_uris << rep_def.uri
63+
self
64+
end
65+
4666
def results
4767
content['results']
4868
end

lib/gooddata/models/project.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,18 @@ def user_csv_import(row)
152152
end
153153
end
154154

155-
def add_metric(options = {})
156-
options[:expression] || fail('Metric has to have its expression defined')
157-
m1 = GoodData::Metric.xcreate(options)
158-
m1.save
155+
def add_metric(metric, options = {})
156+
default = { client: client, project: self }
157+
if metric.is_a?(String)
158+
GoodData::Metric.xcreate(metric, options.merge(default))
159+
else
160+
GoodData::Metric.xcreate(metric.merge(default))
161+
end
159162
end
160163
alias_method :create_metric, :add_metric
161164

162165
def add_report(options = {})
163-
rep = GoodData::Report.create(options)
166+
rep = GoodData::Report.create(options.merge(client: client, project: self))
164167
rep.save
165168
end
166169
alias_method :create_report, :add_report
@@ -340,6 +343,10 @@ def facts_by_title(title)
340343
GoodData::Fact.find_by_title(title, project: self, client: client)
341344
end
342345

346+
def find_attribute_element_value(uri)
347+
GoodData::Attribute.find_element_value(uri, client: client, project: self)
348+
end
349+
343350
# Gets project role by its identifier
344351
#
345352
# @param [String] role_name Title of role to look for

lib/gooddata/rest/connection.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,12 @@ def initialize(opts)
5454
def connect(username, password, options = {})
5555
# Reset old cookies first
5656
if options[:sst_token]
57-
# server_cookies = options[:cookies]
58-
# options.merge(:cookies => { 'GDCAuthSST' => token })
5957
merge_cookies!({ 'GDCAuthSST' => options[:sst_token] })
60-
# status = :logged_in
58+
@user = get(get('/gdc/app/account/bootstrap')['bootstrapResource']['accountSetting']['links']['self'])
59+
@auth = {}
6160
refresh_token :dont_reauth => true
6261
else
6362
credentials = Connection.construct_login_payload(username, password)
64-
6563
@auth = post(LOGIN_PATH, credentials, :dont_reauth => true)['userLogin']
6664

6765
@user = get(@auth['profile'])
@@ -73,7 +71,7 @@ def connect(username, password, options = {})
7371
def disconnect
7472
# TODO: Wrap somehow
7573
url = @auth['state']
76-
delete url
74+
delete url if url
7775

7876
@auth = nil
7977
@server = nil
@@ -126,6 +124,13 @@ def post(uri, data, options = {})
126124
fail NotImplementedError "POST #{uri}"
127125
end
128126

127+
# Reader method for SST token
128+
#
129+
# @return uri [String] SST token
130+
def sst_token
131+
cookies[:cookies]['GDCAuthSST']
132+
end
133+
129134
def stats_table(values = stats)
130135
sorted = values.sort_by { |k, v| v[:avg] }
131136
Terminal::Table.new :headings => %w(title avg min max total calls) do |t|
@@ -143,6 +148,13 @@ def stats_table(values = stats)
143148
end
144149
end
145150

151+
# Reader method for TT token
152+
#
153+
# @return uri [String] TT token
154+
def tt_token
155+
cookies[:cookies]['GDCAuthTT']
156+
end
157+
146158
private
147159

148160
def merge_cookies!(cookies)

0 commit comments

Comments
 (0)