rgovdata 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.rvmrc +2 -0
- data/CHANGELOG +7 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +48 -0
- data/LICENSE +20 -0
- data/README.rdoc +114 -0
- data/Rakefile +61 -0
- data/bin/rgd +12 -0
- data/examples/all_quakes.rb +8 -0
- data/examples/arbitrary_data.rb +26 -0
- data/examples/catalog_traversal.rb +34 -0
- data/examples/earthquakes.rb +5 -0
- data/lib/rgovdata.rb +4 -0
- data/lib/rgovdata/catalog.rb +4 -0
- data/lib/rgovdata/catalog/catalog.rb +79 -0
- data/lib/rgovdata/catalog/dn.rb +63 -0
- data/lib/rgovdata/catalog/registry_strategy/internal_registry.rb +12 -0
- data/lib/rgovdata/catalog/registry_strategy/registry_strategy.rb +26 -0
- data/lib/rgovdata/config.rb +5 -0
- data/lib/rgovdata/config/common_config.rb +13 -0
- data/lib/rgovdata/config/config.rb +133 -0
- data/lib/rgovdata/data/config_template.yml +19 -0
- data/lib/rgovdata/data/sg/registry.yml +147 -0
- data/lib/rgovdata/data/template.rb +27 -0
- data/lib/rgovdata/data/us/registry.yml +12 -0
- data/lib/rgovdata/service.rb +10 -0
- data/lib/rgovdata/service/csv_service.rb +3 -0
- data/lib/rgovdata/service/dataset/csv_dataset.rb +43 -0
- data/lib/rgovdata/service/dataset/dataset.rb +91 -0
- data/lib/rgovdata/service/dataset/file_dataset.rb +46 -0
- data/lib/rgovdata/service/dataset/odata_dataset.rb +31 -0
- data/lib/rgovdata/service/file_service.rb +10 -0
- data/lib/rgovdata/service/listing.rb +47 -0
- data/lib/rgovdata/service/odata_service.rb +50 -0
- data/lib/rgovdata/service/service.rb +93 -0
- data/lib/rgovdata/shell/shell.rb +157 -0
- data/lib/rgovdata/version.rb +9 -0
- data/rgovdata.gemspec +128 -0
- data/spec/fixtures/sample.csv +821 -0
- data/spec/integration/service/sg/nlb_spec.rb +57 -0
- data/spec/integration/service/sg/places_spec.rb +73 -0
- data/spec/integration/service/us/eqs7day-M1_spec.rb +57 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/support/config_examples.rb +8 -0
- data/spec/support/mocks.rb +22 -0
- data/spec/support/utility.rb +18 -0
- data/spec/unit/catalog/base_spec.rb +93 -0
- data/spec/unit/catalog/registry_strategy_spec.rb +28 -0
- data/spec/unit/config/config_spec.rb +130 -0
- data/spec/unit/data/template_spec.rb +32 -0
- data/spec/unit/service/dataset/csv_dataset_spec.rb +42 -0
- data/spec/unit/service/dataset/dataset_spec.rb +37 -0
- data/spec/unit/service/dataset/file_dataset_spec.rb +40 -0
- data/spec/unit/service/dataset/odata_dataset_spec.rb +36 -0
- data/spec/unit/service/file_service_spec.rb +25 -0
- data/spec/unit/service/listing_spec.rb +100 -0
- data/spec/unit/service/odata_service_spec.rb +42 -0
- data/spec/unit/service/service_spec.rb +82 -0
- data/spec/unit/shell/shell_spec.rb +10 -0
- metadata +228 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RGovData::Template do
|
4
|
+
subject { RGovData::Template }
|
5
|
+
it { should respond_to(:get) }
|
6
|
+
|
7
|
+
[
|
8
|
+
{ :name => 'config_template.yml', :realm => nil, :expect => 'credentials'},
|
9
|
+
{ :name => 'registry.yml', :realm => 'sg', :expect => 'description'},
|
10
|
+
{ :name => 'registry.yml', :realm => :sg, :expect => 'description'},
|
11
|
+
{ :name => 'registry.yml', :realm => 'zz', :expect => nil},
|
12
|
+
{ :name => 'not_found.yml', :realm => nil, :expect => nil}
|
13
|
+
].each do |options|
|
14
|
+
context "with #{options[:realm]}:#{options[:name]}" do
|
15
|
+
|
16
|
+
describe "##path" do
|
17
|
+
subject { RGovData::Template.path(options[:name],options[:realm]) }
|
18
|
+
it { File.exists?(subject).should == options[:expect].present? }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "##get" do
|
22
|
+
subject { RGovData::Template.get(options[:name],options[:realm]) }
|
23
|
+
if options[:expect]
|
24
|
+
it { should include(options[:expect]) }
|
25
|
+
else
|
26
|
+
it { should be_nil }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include MocksHelper
|
3
|
+
|
4
|
+
describe RGovData::CsvDataSet do
|
5
|
+
|
6
|
+
let(:dataset_key) { 'csv' }
|
7
|
+
let(:sample_file) { mock_file_path('sample.csv') }
|
8
|
+
let(:expect_row_count) { 820 }
|
9
|
+
let(:expect_headers) { ["Src", "Eqid", "Version", "Datetime", "Lat", "Lon", "Magnitude", "Depth", "NST", "Region"] }
|
10
|
+
|
11
|
+
let(:service) { RGovData::CsvService.new({:uri=>sample_file,:type=>'csv'}) }
|
12
|
+
let(:dataset) { RGovData::CsvDataSet.new({:dataset_key=>dataset_key},service) }
|
13
|
+
|
14
|
+
describe "#native_dataset_key" do
|
15
|
+
let(:expect) { dataset_key }
|
16
|
+
subject { dataset.native_dataset_key }
|
17
|
+
it { should eql(expect) }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#attributes" do
|
21
|
+
subject { dataset.attributes }
|
22
|
+
it { should eql(expect_headers) }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#records" do
|
26
|
+
subject { dataset.records }
|
27
|
+
its(:count) { should eql(expect_row_count) }
|
28
|
+
|
29
|
+
context "with a record_limit" do
|
30
|
+
let(:record_limit) { 3 }
|
31
|
+
before {
|
32
|
+
dataset.limit = record_limit
|
33
|
+
}
|
34
|
+
subject { dataset.records(true) }
|
35
|
+
it { should be_a(Array) }
|
36
|
+
its(:first) { should be_a(CSV::Row) }
|
37
|
+
its(:count) { should eql(record_limit) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RGovData::DataSet do
|
4
|
+
|
5
|
+
let(:dataset_key) { 'Test' }
|
6
|
+
let(:service) { RGovData::Service.new({:type=>'dummy'}) }
|
7
|
+
let(:dataset) { RGovData::DataSet.new({:dataset_key=>dataset_key},service) }
|
8
|
+
|
9
|
+
describe "#limit" do
|
10
|
+
subject { dataset.limit }
|
11
|
+
context "not set" do
|
12
|
+
it { should be_nil }
|
13
|
+
end
|
14
|
+
context "set" do
|
15
|
+
let(:expect) { 5 }
|
16
|
+
before { dataset.limit = 5 }
|
17
|
+
it { should eql(expect) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#records" do
|
22
|
+
subject { dataset.records }
|
23
|
+
context "with only a single result from load_records" do
|
24
|
+
before {
|
25
|
+
dataset.stub(:load_records).and_return('single result')
|
26
|
+
}
|
27
|
+
it { should eql('single result') }
|
28
|
+
end
|
29
|
+
context "with only a single result from load_records" do
|
30
|
+
before {
|
31
|
+
dataset.stub(:load_records).and_return(['result 1','result 2'])
|
32
|
+
}
|
33
|
+
it { should be_a(Array) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include MocksHelper
|
3
|
+
|
4
|
+
describe RGovData::FileDataSet do
|
5
|
+
|
6
|
+
let(:dataset_key) { 'file' }
|
7
|
+
let(:sample_file) { mock_file_path('sample.csv') }
|
8
|
+
let(:service) { RGovData::FileService.new({:uri=>sample_file,:type=>dataset_key}) }
|
9
|
+
let(:dataset) { RGovData::FileDataSet.new({:dataset_key=>dataset_key},service) }
|
10
|
+
|
11
|
+
describe "#native_dataset_key" do
|
12
|
+
let(:expect) { dataset_key }
|
13
|
+
subject { dataset.native_dataset_key }
|
14
|
+
it { should eql(expect) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#attributes" do
|
18
|
+
let(:expect) { ['row'] }
|
19
|
+
subject { dataset.attributes }
|
20
|
+
it { should eql(expect) }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#records" do
|
24
|
+
subject { dataset.records }
|
25
|
+
it { should be_a(StringIO) }
|
26
|
+
|
27
|
+
context "with a record_limit" do
|
28
|
+
let(:record_limit) { 3 }
|
29
|
+
before {
|
30
|
+
dataset.limit = record_limit
|
31
|
+
}
|
32
|
+
subject { dataset.records(true) }
|
33
|
+
it { should be_a(Array) }
|
34
|
+
its(:first) { should be_a(String) }
|
35
|
+
its(:count) { should eql(record_limit) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RGovData::OdataDataSet do
|
4
|
+
|
5
|
+
let(:credentialset) { 'basic' }
|
6
|
+
let(:dataset_key) { 'Test' }
|
7
|
+
let(:service) { RGovData::OdataService.new({:uri=>'uri',:type=>'odata',:credentialset=>credentialset}) }
|
8
|
+
let(:dataset) { RGovData::OdataDataSet.new({:dataset_key=>dataset_key},service) }
|
9
|
+
|
10
|
+
before {
|
11
|
+
# These tests won't call on a real service
|
12
|
+
OData::Service.any_instance.stub(:build_collections_and_classes).and_return(nil)
|
13
|
+
RGovData::Config.stub(:default_config_file).and_return(mock_configfile_path)
|
14
|
+
RGovData::Config.instance.load_default_config
|
15
|
+
}
|
16
|
+
|
17
|
+
describe "#native_dataset_key" do
|
18
|
+
let(:expect) { 'Test' }
|
19
|
+
subject { dataset.native_dataset_key }
|
20
|
+
it { should eql(expect) }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#entity_name" do
|
24
|
+
{
|
25
|
+
'Test' => 'Test',
|
26
|
+
'TestSet'=>'Test'
|
27
|
+
}.each do |given_key,expect|
|
28
|
+
context "with dataset_key:#{given_key}" do
|
29
|
+
let(:dataset_key) { given_key }
|
30
|
+
subject { dataset.entity_name }
|
31
|
+
it { should eql(expect) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RGovData::FileService do
|
4
|
+
|
5
|
+
let(:dataset_key) { 'file' }
|
6
|
+
let(:sample_file) { mock_file_path('sample.csv') }
|
7
|
+
let(:service) { RGovData::FileService.new({:uri=>sample_file,:type=>'file'}) }
|
8
|
+
|
9
|
+
|
10
|
+
describe "#dataset_keys" do
|
11
|
+
let(:expect) { [dataset_key] }
|
12
|
+
subject { service.dataset_keys }
|
13
|
+
it { should eql(expect) }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#native_instance" do
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#datasets" do
|
20
|
+
subject { service.datasets }
|
21
|
+
it { should be_a(Array) }
|
22
|
+
its(:first) { should be_a(RGovData::FileDataSet) }
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RGovData::ServiceListing do
|
4
|
+
|
5
|
+
describe "property:" do
|
6
|
+
subject { RGovData::ServiceListing.new }
|
7
|
+
[
|
8
|
+
:realm,:key,:name,:description,:keywords,:publisher,
|
9
|
+
:uri,:license,:type,:credentialset
|
10
|
+
].each do |property|
|
11
|
+
describe property do
|
12
|
+
it "should support setter and getter" do
|
13
|
+
value = "x"
|
14
|
+
subject.send("#{property}=",value)
|
15
|
+
subject.send(property).should eql(value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#id" do
|
22
|
+
let(:realm) { :sg }
|
23
|
+
let(:key) { 'key_name' }
|
24
|
+
let(:expect) { '//sg/key_name' }
|
25
|
+
let(:listing) { RGovData::ServiceListing.new }
|
26
|
+
subject { listing }
|
27
|
+
before do
|
28
|
+
listing.realm = realm
|
29
|
+
listing.key = key
|
30
|
+
end
|
31
|
+
its(:id) { should eql(expect) }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#service" do
|
35
|
+
[
|
36
|
+
{:type => :odata, :uri => 'http://example.com', :expect_class => RGovData::OdataService },
|
37
|
+
{:type => 'odata', :uri => 'http://example.com', :expect_class => RGovData::OdataService },
|
38
|
+
{:type => :csv, :uri => 'http://example.com', :expect_class => RGovData::FileService },
|
39
|
+
{:type => 'csv', :uri => 'http://example.com', :expect_class => RGovData::FileService },
|
40
|
+
{:type => :dummy, :uri => 'http://example.com', :expect_class => nil }
|
41
|
+
].each do |options|
|
42
|
+
context "with type:#{options[:type]}" do
|
43
|
+
let(:listing) { RGovData::ServiceListing.new }
|
44
|
+
before do
|
45
|
+
listing.type = options[:type]
|
46
|
+
listing.uri = options[:uri]
|
47
|
+
end
|
48
|
+
subject { listing.service }
|
49
|
+
if options[:expect_class]
|
50
|
+
it { should be_a(options[:expect_class]) }
|
51
|
+
else
|
52
|
+
it { should be_nil }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#datasets" do
|
59
|
+
let(:listing) { RGovData::ServiceListing.new }
|
60
|
+
let(:mock_datasets) { ['a','b'] }
|
61
|
+
before {
|
62
|
+
RGovData::Service.stub(:get_instance).and_return(RGovData::Service.new({:uri=>'uri',:type=>'type',:credentialset=>'credentialset'}))
|
63
|
+
RGovData::Service.any_instance.stub(:datasets).and_return(mock_datasets)
|
64
|
+
}
|
65
|
+
subject { listing.datasets }
|
66
|
+
it { should be_a(Array) }
|
67
|
+
it { should eql(mock_datasets) }
|
68
|
+
|
69
|
+
describe "#records" do
|
70
|
+
subject { listing.records }
|
71
|
+
it { should eql(mock_datasets) }
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#get_dataset" do
|
75
|
+
let(:key) { 'key' }
|
76
|
+
let(:mock_dataset_a) { 'mock_dataset_a' }
|
77
|
+
let(:mock_dataset_b) { 'mock_dataset_b' }
|
78
|
+
let(:mock_dataset) { [mock_dataset_a,mock_dataset_b] }
|
79
|
+
before {
|
80
|
+
RGovData::Service.any_instance.stub(:get_dataset).and_return(mock_dataset)
|
81
|
+
}
|
82
|
+
subject { listing.get_dataset(key) }
|
83
|
+
it { should eql(mock_dataset) }
|
84
|
+
describe "#find" do
|
85
|
+
subject { listing.find(key) }
|
86
|
+
it { should eql(mock_dataset_a) }
|
87
|
+
end
|
88
|
+
describe "#find_by_id" do
|
89
|
+
subject { listing.find_by_id(key) }
|
90
|
+
it { should eql(mock_dataset_a) }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#to_s" do
|
96
|
+
its(:to_s) { should be_a(String) }
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RGovData::OdataService do
|
4
|
+
|
5
|
+
let(:credentialset) { 'basic' }
|
6
|
+
let(:service) { RGovData::OdataService.new({:uri=>'uri',:type=>'odata',:credentialset=>credentialset}) }
|
7
|
+
|
8
|
+
before {
|
9
|
+
# These tests won't call on a real service
|
10
|
+
OData::Service.any_instance.stub(:build_collections_and_classes).and_return(nil)
|
11
|
+
RGovData::Config.stub(:default_config_file).and_return(mock_configfile_path)
|
12
|
+
RGovData::Config.instance.load_default_config
|
13
|
+
}
|
14
|
+
|
15
|
+
describe "#native_instance" do
|
16
|
+
subject { service.native_instance }
|
17
|
+
it { should be_a(OData::Service) }
|
18
|
+
|
19
|
+
context "with basic credentials" do
|
20
|
+
subject { service.native_instance.instance_variable_get(:@rest_options) }
|
21
|
+
it "should have user set" do
|
22
|
+
subject[:user].should_not be_nil
|
23
|
+
end
|
24
|
+
it "should have password set" do
|
25
|
+
subject[:password].should_not be_nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with projectnimbus credentials" do
|
30
|
+
let(:credentialset) { 'projectnimbus' }
|
31
|
+
subject { service.native_instance.instance_variable_get(:@rest_options) }
|
32
|
+
it "should have headers set" do
|
33
|
+
subject[:headers].should_not be_nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#datasets" do
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RGovData::Service do
|
4
|
+
|
5
|
+
describe "##get_instance" do
|
6
|
+
context "with unsupported options" do
|
7
|
+
subject { RGovData::Service.get_instance({:uri=>'uri',:type=>'type',:transport=>'transport',:credentialset=>'credentialset'}) }
|
8
|
+
it { should be_nil }
|
9
|
+
end
|
10
|
+
context "with odata type" do
|
11
|
+
subject { RGovData::Service.get_instance({:uri=>'uri',:type=>'odata',:transport=>'odata',:credentialset=>'credentialset'}) }
|
12
|
+
it { should be_a(RGovData::OdataService) }
|
13
|
+
end
|
14
|
+
context "with csv type" do
|
15
|
+
subject { RGovData::Service.get_instance({:uri=>'uri',:type=>'csv',:transport=>'get',:credentialset=>'credentialset'}) }
|
16
|
+
it { should be_a(RGovData::FileService) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:service) { RGovData::Service.new({:realm=>:sg, :service_key=>'service_name', :uri=>'uri',:type=>'csv',:transport=>'get',:credentialset=>'credentialset'}) }
|
21
|
+
subject { service }
|
22
|
+
|
23
|
+
it_behaves_like "includes common config"
|
24
|
+
|
25
|
+
describe "#native_instance" do
|
26
|
+
subject { service.native_instance }
|
27
|
+
it { should eql(service) }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#meta_attributes" do
|
31
|
+
subject { service.meta_attributes }
|
32
|
+
it { should be_a(Array) }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#initialization_hash" do
|
36
|
+
subject { service.initialization_hash }
|
37
|
+
let(:keys) { service.initialization_hash.keys }
|
38
|
+
it { should be_a(Hash) }
|
39
|
+
it "should contain members for all attributes" do
|
40
|
+
service.meta_attributes.each do |attribute|
|
41
|
+
keys.should include(attribute)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#id" do
|
47
|
+
let(:expect) { '//sg/service_name' }
|
48
|
+
its(:id) { should eql(expect) }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#datasets" do
|
52
|
+
let(:mock_dataset_a) { RGovData::DataSet.new({:dataset_key=>'mock_dataset_a'},service) }
|
53
|
+
let(:mock_dataset_b) { RGovData::DataSet.new({:dataset_key=>'mock_dataset_b'},service) }
|
54
|
+
let(:mock_datasets) { [mock_dataset_a,mock_dataset_b] }
|
55
|
+
before {
|
56
|
+
service.stub(:datasets).and_return(mock_datasets)
|
57
|
+
}
|
58
|
+
subject { service.datasets }
|
59
|
+
it { should be_a(Array) }
|
60
|
+
it { should eql(mock_datasets) }
|
61
|
+
|
62
|
+
describe "#records" do
|
63
|
+
subject { service.records }
|
64
|
+
it { should eql(mock_datasets) }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#get_dataset" do
|
68
|
+
let(:key) { 'mock_dataset' }
|
69
|
+
subject { service.get_dataset(key) }
|
70
|
+
it { should eql(mock_datasets) }
|
71
|
+
describe "#find" do
|
72
|
+
subject { service.find(key) }
|
73
|
+
it { should eql(mock_dataset_a) }
|
74
|
+
end
|
75
|
+
describe "#find_by_id" do
|
76
|
+
subject { service.find_by_id(key) }
|
77
|
+
it { should eql(mock_dataset_a) }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|