How to use foo method of Api Package

Best Active_mocker_ruby code snippet using Api.foo

api_spec.rb

Source:api_spec.rb Github

copy

Full Screen

...58 let(:params) { {:pki => 'ca'} }59 it { is_expected.to contain_exec('icinga2 pki create certificate signing request') }60 it { is_expected.to contain_exec('icinga2 pki sign certificate') }61 end62 context "#{os} with pki => foo (not a valid value)" do63 let(:params) { {:pki => 'foo'} }64 it { is_expected.to raise_error(Puppet::Error, /foo isn't supported/) }65 end66 context "#{os} with pki => none, ssl_key => foo, ssl_cert => bar, ssl_cacert => baz" do67 let(:params) { {:pki => 'none', 'ssl_key' => 'foo', 'ssl_cert' => 'bar', 'ssl_cacert' => 'baz'} }68 it { is_expected.to contain_file('/etc/icinga2/pki/host.example.org.key').with({69 'mode' => '0600',70 }).with_content(/^foo/) }71 it { is_expected.to contain_file('/etc/icinga2/pki/host.example.org.crt')72 .with_content(/^bar/) }73 it { is_expected.to contain_file('/etc/icinga2/pki/ca.crt')74 .with_content(/^baz/) }75 end76 context "#{os} with ssl_key_path = /foo/bar" do77 let(:params) { {:ssl_key_path => '/foo/bar'} }78 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')79 .with({ 'target' => '/etc/icinga2/features-available/api.conf' })80 .with_content(/key_path = "\/foo\/bar"/) }81 end82 context "#{os} with ssl_key_path = foo/bar (not a valid absolute path)" do83 let(:params) { {:ssl_key_path => 'foo/bar'} }84 it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) }85 end86 context "#{os} with ssl_cert_path = /foo/bar" do87 let(:params) { {:ssl_cert_path => '/foo/bar'} }88 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')89 .with({ 'target' => '/etc/icinga2/features-available/api.conf' })90 .with_content(/cert_path = "\/foo\/bar"/) }91 end92 context "#{os} with ssl_cert_path = foo/bar (not a valid absolute path)" do93 let(:params) { {:ssl_cert_path => 'foo/bar'} }94 it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) }95 end96 context "#{os} with ssl_cacert_path = /foo/bar" do97 let(:params) { {:ssl_cacert_path => '/foo/bar'} }98 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')99 .with({ 'target' => '/etc/icinga2/features-available/api.conf' })100 .with_content(/ca_path = "\/foo\/bar"/) }101 end102 context "#{os} with ssl_cacert_path = foo/bar (not a valid absolute path)" do103 let(:params) { {:ssl_cacert_path => 'foo/bar'} }104 it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) }105 end106 context "#{os} with accept_config => true" do107 let(:params) { {:accept_config => true} }108 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')109 .with({ 'target' => '/etc/icinga2/features-available/api.conf' })110 .with_content(/accept_config = true/) }111 end112 context "#{os} with accept_config => false" do113 let(:params) { {:accept_config => false} }114 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')115 .with({ 'target' => '/etc/icinga2/features-available/api.conf' })116 .with_content(/accept_config = false/) }117 end118 context "#{os} with accept_config => foo (not a valid boolean)" do119 let(:params) { {:accept_config => 'foo'} }120 it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) }121 end122 context "#{os} with accept_commands => true" do123 let(:params) { {:accept_commands => true} }124 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')125 .with({ 'target' => '/etc/icinga2/features-available/api.conf' })126 .with_content(/accept_commands = true/) }127 end128 context "#{os} with accept_commands => false" do129 let(:params) { {:accept_commands => false} }130 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')131 .with({ 'target' => '/etc/icinga2/features-available/api.conf' })132 .with_content(/accept_commands = false/) }133 end134 context "#{os} with accept_commands => foo (not a valid boolean)" do135 let(:params) { {:accept_commands => 'foo'} }136 it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) }137 end138 context "#{os} with pki => 'icinga2', ca_host => foo" do139 let(:params) { {:pki => 'icinga2', :ca_host => 'foo'} }140 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')141 .with({ 'target' => '/etc/icinga2/features-available/api.conf' }) }142 end143 context "#{os} with pki => 'icinga2', ca_port => 1234" do144 let(:params) { {:pki => 'icinga2',:ca_port => '1234'} }145 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')146 .with({ 'target' => '/etc/icinga2/features-available/api.conf' }) }147 end148 context "#{os} with pki => 'icinga2', ca_port => foo (not a valid integer)" do149 let(:params) { {:pki => 'icinga2',:ca_port => 'foo'} }150 it { is_expected.to raise_error(Puppet::Error, /first argument to be an Integer/) }151 end152 context "#{os} with pki => none, ticket_salt => foo" do153 let(:params) { {:pki => 'none', :ticket_salt => 'foo'} }154 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')155 .with({ 'target' => '/etc/icinga2/features-available/api.conf' })156 .with_content(/ticket_salt = "foo"/) }157 end158 context "#{os} with endpoints => { foo => {} }" do159 let(:params) { {:endpoints => { 'foo' => {}} }}160 it { is_expected.to contain_icinga2__object__endpoint('foo') }161 end162 context "#{os} with endpoints => foo (not a valid hash)" do163 let(:params) { {:endpoints => 'foo'} }164 it { is_expected.to raise_error(Puppet::Error, /"foo" is not a Hash/) }165 end166 context "#{os} with zones => { foo => {endpoints => ['bar']} } }" do167 let(:params) { {:zones => { 'foo' => {'endpoints' => ['bar']}} }}168 it { is_expected.to contain_icinga2__object__zone('foo')169 .with({ 'endpoints' => [ 'bar' ] }) }170 end171 context "#{os} with zones => foo (not a valid hash)" do172 let(:params) { {:zones => 'foo'} }173 it { is_expected.to raise_error(Puppet::Error, /"foo" is not a Hash/) }174 end175 context "#{os} with TLS detail settings" do176 let(:params) { { ssl_protocolmin: 'TLSv1.2', ssl_cipher_list: 'HIGH:MEDIUM:!aNULL:!MD5:!RC4' } }177 it 'should set TLS detail setting' do178 is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')179 .with({ 'target' => '/etc/icinga2/features-available/api.conf' })180 .with_content(/tls_protocolmin = "TLSv1.2"/)181 .with_content(/cipher_list = "HIGH:MEDIUM:!aNULL:!MD5:!RC4"/)182 end183 end184 context "#{os} with bind settings" do185 let(:params) { { bind_host: '::', bind_port: 1234 } }186 it 'should set bind_* settings' do187 is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')188 .with({ 'target' => '/etc/icinga2/features-available/api.conf' })189 .with_content(/bind_host = "::"/)190 .with_content(/bind_port = 1234/)191 end192 end193 end194end195describe('icinga2::feature::api', :type => :class) do196 let(:facts) { {197 :kernel => 'Windows',198 :architecture => 'x86_64',199 :osfamily => 'Windows',200 :operatingsystem => 'Windows',201 :operatingsystemmajrelease => '2012 R2',202 :path => 'C:\Program Files\Puppet Labs\Puppet\puppet\bin;203 C:\Program Files\Puppet Labs\Puppet\facter\bin;204 C:\Program Files\Puppet Labs\Puppet\hiera\bin;205 C:\Program Files\Puppet Labs\Puppet\mcollective\bin;206 C:\Program Files\Puppet Labs\Puppet\bin;207 C:\Program Files\Puppet Labs\Puppet\sys\ruby\bin;208 C:\Program Files\Puppet Labs\Puppet\sys\tools\bin;209 C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;210 C:\Windows\System32\WindowsPowerShell\v1.0\;211 C:\ProgramData\chocolatey\bin;',212 :icinga2_puppet_hostcert => 'C:\Program Files\Puppet Labs\Puppet\var\lib\puppet\ssl\certs\host.example.org.pem',213 :icinga2_puppet_hostprivkey => 'C:\Program Files\Puppet Labs\Puppet\var\lib\puppet\ssl\private_keys\host.example.org.pem',214 :icinga2_puppet_localcacert => 'C:\Program Files\Puppet Labs\Puppet\var\lib\puppet\ssl\certs\ca.pem',215 } }216 let(:pre_condition) { [217 "class { 'icinga2': features => [], constants => {'NodeName' => 'host.example.org'} }"218 ] }219 context 'Windows 2012 R2 with ensure => present' do220 let(:params) { {:ensure => 'present'} }221 it { is_expected.to contain_icinga2__feature('api').with({'ensure' => 'present'}) }222 it { is_expected.to contain_icinga2__object('icinga2::object::ApiListener::api')223 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' })224 .that_notifies('Class[icinga2::service]') }225 end226 context 'Windows 2012 R2 with ensure => absent' do227 let(:params) { {:ensure => 'absent'} }228 it { is_expected.to contain_icinga2__feature('api').with({'ensure' => 'absent'}) }229 it { is_expected.to contain_icinga2__object('icinga2::object::ApiListener::api')230 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' }) }231 end232 context "Windows 2012 R2 with all defaults" do233 it { is_expected.to contain_icinga2__feature('api').with({'ensure' => 'present'}) }234 it { is_expected.to contain_icinga2__object('icinga2::object::ApiListener::api')235 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' })236 .that_notifies('Class[icinga2::service]') }237 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')238 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' })239 .with_content(/accept_config = false/)240 .with_content(/accept_commands = false/) }241 it { is_expected.to contain_file('C:/ProgramData/icinga2/etc/icinga2/pki/host.example.org.key') }242 it { is_expected.to contain_file('C:/ProgramData/icinga2/etc/icinga2/pki/host.example.org.crt') }243 it { is_expected.to contain_file('C:/ProgramData/icinga2/etc/icinga2/pki/ca.crt') }244 it { is_expected.to contain_icinga2__object__endpoint('NodeName') }245 it { is_expected.to contain_icinga2__object__zone('ZoneName')246 .with({ 'endpoints' => [ 'NodeName' ] }) }247 end248 context "Windows 2012 R2 with pki => puppet" do249 let(:params) { {:pki => 'puppet'} }250 it { is_expected.to contain_file('C:/ProgramData/icinga2/etc/icinga2/pki/host.example.org.key') }251 it { is_expected.to contain_file('C:/ProgramData/icinga2/etc/icinga2/pki/host.example.org.crt') }252 it { is_expected.to contain_file('C:/ProgramData/icinga2/etc/icinga2/pki/ca.crt') }253 end254 context "Windows 2012 R2 with pki => icinga2" do255 let(:params) { {:pki => 'icinga2'} }256 it { is_expected.to contain_exec('icinga2 pki create key') }257 it { is_expected.to contain_exec('icinga2 pki get trusted-cert') }258 it { is_expected.to contain_exec('icinga2 pki request') }259 end260 context "Windows 2012 R2 with pki => foo (not a valid value)" do261 let(:params) { {:pki => 'foo'} }262 it { is_expected.to raise_error(Puppet::Error, /foo isn't supported/) }263 end264 context "Windows 2012 R2 with pki => none, ssl_key => foo, ssl_cert => bar, ssl_cacert => baz" do265 let(:params) { {:pki => 'none', 'ssl_key' => 'foo', 'ssl_cert' => 'bar', 'ssl_cacert' => 'baz'} }266 it { is_expected.to contain_file('C:/ProgramData/icinga2/etc/icinga2/pki/host.example.org.key')267 .with_content(/^foo/) }268 it { is_expected.to contain_file('C:/ProgramData/icinga2/etc/icinga2/pki/host.example.org.crt')269 .with_content(/^bar/) }270 it { is_expected.to contain_file('C:/ProgramData/icinga2/etc/icinga2/pki/ca.crt')271 .with_content(/^baz/) }272 end273 context "Windows 2012 R2 with ssl_key_path = /foo/bar" do274 let(:params) { {:ssl_key_path => '/foo/bar'} }275 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')276 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' })277 .with_content(/key_path = "\/foo\/bar"/) }278 end279 context "Windows 2012 R2 with ssl_key_path = foo/bar (not a valid absolute path)" do280 let(:params) { {:ssl_key_path => 'foo/bar'} }281 it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) }282 end283 context "Windows 2012 R2 with ssl_cert_path = /foo/bar" do284 let(:params) { {:ssl_cert_path => '/foo/bar'} }285 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')286 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' })287 .with_content(/cert_path = "\/foo\/bar"/) }288 end289 context "Windows 2012 R2 with ssl_cert_path = foo/bar (not a valid absolute path)" do290 let(:params) { {:ssl_cert_path => 'foo/bar'} }291 it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) }292 end293 context "Windows 2012 R2 with ssl_cacert_path = /foo/bar" do294 let(:params) { {:ssl_cacert_path => '/foo/bar'} }295 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')296 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' })297 .with_content(/ca_path = "\/foo\/bar"/) }298 end299 context "Windows 2012 R2 with ssl_cacert_path = foo/bar (not a valid absolute path)" do300 let(:params) { {:ssl_cacert_path => 'foo/bar'} }301 it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) }302 end303 context "Windows 2012 R2 with accept_config => true" do304 let(:params) { {:accept_config => true} }305 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')306 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' })307 .with_content(/accept_config = true/) }308 end309 context "Windows 2012 R2 with accept_config => false" do310 let(:params) { {:accept_config => false} }311 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')312 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' })313 .with_content(/accept_config = false/) }314 end315 context "Windows 2012 R2 with accept_config => foo (not a valid boolean)" do316 let(:params) { {:accept_config => 'foo'} }317 it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) }318 end319 context "Windows 2012 R2 with accept_commands => true" do320 let(:params) { {:accept_commands => true} }321 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')322 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' })323 .with_content(/accept_commands = true/) }324 end325 context "Windows 2012 R2 with accept_commands => false" do326 let(:params) { {:accept_commands => false} }327 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')328 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' })329 .with_content(/accept_commands = false/) }330 end331 context "Windows 2012 R2 with accept_config => foo (not a valid boolean)" do332 let(:params) { {:accept_commands => 'foo'} }333 it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) }334 end335 context "Windows 2012 R2 with pki => none, ticket_salt => foo" do336 let(:params) { {:pki => 'none', :ticket_salt => 'foo'} }337 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')338 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' })339 .with_content(/ticket_salt = "foo"/) }340 end341 context "Windows 2012 R2 with pki => 'icinga2', ca_host => foo" do342 let(:params) { {:pki => 'icinga2', :ca_host => 'foo'} }343 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')344 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' }) }345 end346 context "Windows 2012 R2 with pki => 'icinga2', ca_port => 1234" do347 let(:params) { {:pki => 'icinga2',:ca_port => '1234'} }348 it { is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')349 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' }) }350 end351 context "Windows 2012 R2 with pki => 'icinga2', ca_port => foo (not a valid integer)" do352 let(:params) { {:pki => 'icinga2',:ca_port => 'foo'} }353 it { is_expected.to raise_error(Puppet::Error, /first argument to be an Integer/) }354 end355 context "Windows 2012 R2 with endpoints => { foo => {} }" do356 let(:params) { {:endpoints => { 'foo' => {}} }}357 it { is_expected.to contain_icinga2__object__endpoint('foo') }358 end359 context "Windows 2012 R2 with endpoints => foo (not a valid hash)" do360 let(:params) { {:endpoints => 'foo'} }361 it { is_expected.to raise_error(Puppet::Error, /"foo" is not a Hash/) }362 end363 context "Windows 2012 R2 with zones => { foo => {endpoints => ['bar']} } }" do364 let(:params) { {:zones => { 'foo' => {'endpoints' => ['bar']}} }}365 it { is_expected.to contain_icinga2__object__zone('foo')366 .with({ 'endpoints' => [ 'bar' ] }) }367 end368 context "Windows 2012 R2 with zones => foo (not a valid hash)" do369 let(:params) { {:zones => 'foo'} }370 it { is_expected.to raise_error(Puppet::Error, /"foo" is not a Hash/) }371 end372 context 'Windows 2012 R2 with bind settings' do373 let(:params) { { bind_host: '::', bind_port: 1234 } }374 it 'should set bind_* settings' do375 is_expected.to contain_concat__fragment('icinga2::object::ApiListener::api')376 .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/api.conf' })377 .with_content(/bind_host = "::"/)378 .with_content(/bind_port = 1234/)379 end380 end381end...

Full Screen

Full Screen

query_generator_test.rb

Source:query_generator_test.rb Github

copy

Full Screen

...16 _(query.to_json).wont_be_nil17 _(query.to_json).must_match_json_expression pattern18 end19 it 'should allow adding an equality clause' do20 pattern = conjunction(foo: { '@eq' => 'bar' })21 query = DataServicesApi::QueryGenerator.new22 .eq('foo', 'bar')23 _(query.to_json).wont_be_nil24 _(query.to_json).must_match_json_expression pattern25 end26 it 'should allow adding a relational operator clause' do27 query = DataServicesApi::QueryGenerator.new28 _(query.ge('foo', 1).to_json).must_match_json_expression(conjunction(foo: { '@ge' => 1 }))29 _(query.gt('foo', 1).to_json).must_match_json_expression(conjunction(foo: { '@gt' => 1 }))30 _(query.le('foo', 1).to_json).must_match_json_expression(conjunction(foo: { '@le' => 1 }))31 _(query.lt('foo', 1).to_json).must_match_json_expression(conjunction(foo: { '@lt' => 1 }))32 end33 it 'should allow sorting to specified' do34 query = DataServicesApi::QueryGenerator.new35 _(query.sort(:up, 'foo').to_json).must_match_json_expression('@sort' => [{ '@up' => 'foo' }])36 _(query.sort(:up, 'foo').sort(:down, 'bar').to_json).must_match_json_expression('@sort' => [{ '@up' => 'foo' }, { '@down' => 'bar' }])37 end38 it 'should allow a range to be specified' do39 query = DataServicesApi::QueryGenerator.new40 _(query.le('foo', 10)41 .ge('foo', 1)42 .to_json)43 .must_match_json_expression(conjunction([{ foo: { '@ge' => 1 } }, { foo: { '@le' => 10 } }]))44 end45 it 'should allow an arbitrary relational operator to be added' do46 query = DataServicesApi::QueryGenerator.new47 _(query.op(:le, :foo, 1000)48 .op('@ge', :foo, 100)49 .to_json)50 .must_match_json_expression(conjunction([{ foo: { '@ge' => 100 } }, { foo: { '@le' => 1000 } }]))51 end52 it 'should reject an unknown relational operator' do53 _(proc {54 query = DataServicesApi::QueryGenerator.new55 query.op(:range, :foo, 1000)56 }).must_raise NameError57 end58 it 'should add a value type when required' do59 query = DataServicesApi::QueryGenerator.new60 _(query.op(:ge, :foo, Date.parse('2014-01-01'))61 .to_json)62 .must_match_json_expression(conjunction(foo: { '@ge' => { '@value' => '2014-01-01', '@type' => 'xsd:date' } }))63 end64 it 'should allow a text search option to be added' do65 query = DataServicesApi::QueryGenerator.new66 _(query.search('foo')67 .to_json)68 .must_match_json_expression(conjunction('@search' => 'foo'))69 end70 it 'should allow a text search against a specific property to be added' do71 query = DataServicesApi::QueryGenerator.new72 _(query.search_property('foo:bar', 'foo')73 .to_json)74 .must_match_json_expression(conjunction('@search' => { '@value' => 'foo', '@property' => 'foo:bar' }))75 end76 it 'should allow a text search against a specific aspect to be added' do77 query = DataServicesApi::QueryGenerator.new78 _(query.search_aspect('foo:aspect', 'foo')79 .to_json)80 .must_match_json_expression(conjunction('foo:aspect' => { '@search' => 'foo' }))81 end82 it 'should allow a text search against a specific property of an aspect to be added' do83 query = DataServicesApi::QueryGenerator.new84 _(query.search_aspect_property('foo:aspect', 'foo:bar', 'foo')85 .to_json)86 .must_match_json_expression(conjunction('foo:aspect' => { '@search' => { '@value' => 'foo', '@property' => 'foo:bar' } }))87 end88 it 'should allow the limit to be set on a search query' do89 query = DataServicesApi::QueryGenerator.new90 _(query.search_aspect_property('foo:aspect', 'foo:bar', 'foo', '@limit' => 997)91 .to_json)92 .must_match_json_expression(conjunction('foo:aspect' => { '@search' => { '@value' => 'foo',93 '@property' => 'foo:bar',94 '@limit' => 997 } }))95 _(query.search_property('foo:bar', 'foo', '@limit' => 779)96 .to_json)97 .must_match_json_expression(conjunction('@search' => { '@value' => 'foo',98 '@property' => 'foo:bar',99 '@limit' => 779 }))100 end101 it 'should allow a simple boolean expression to be added' do102 query = DataServicesApi::QueryGenerator.new103 _(query.eq_any_uri('foo:aspect', ['foo:bar', 'foo:bam'])104 .to_json)105 .must_match_json_expression(conjunction('foo:aspect' => { '@oneof' => [{ '@id' => 'foo:bar' }, { '@id' => 'foo:bam' }] }))106 _(query.eq_any_value('foo:aspect', ['foo:bar', 'foo:bam'])107 .to_json)108 .must_match_json_expression(conjunction('foo:aspect' => { '@oneof' => [{ '@value' => 'foo:bar' }, { '@value' => 'foo:bam' }] }))109 end110 it 'should allow a type to be specified for a boolean expression value' do111 query = DataServicesApi::QueryGenerator.new112 _(query.eq_any_value('foo:aspect', ['foo:bar', 'foo:bam'], type: 'xsd:coconut')113 .to_json)114 .must_match_json_expression(conjunction('foo:aspect' => { '@oneof' => [{ '@value' => 'foo:bar', '@type' => 'xsd:coconut' },115 { '@value' => 'foo:bam', '@type' => 'xsd:coconut' }] }))116 end117 it 'should allow a terms to be composed' do118 query = DataServicesApi::QueryGenerator.new119 _(query.eq('foo', 'bar')120 .eq('cat', 'cow')121 .search_aspect_property('foo:aspect', 'foo:bar', 'foo')122 .to_json)123 .must_match_json_expression(conjunction([124 { foo: { '@eq' => 'bar' } },125 { cat: { '@eq' => 'cow' } },126 { 'foo:aspect' => { '@search' => { '@value' => 'foo', '@property' => 'foo:bar' } } }127 ]))128 query = DataServicesApi::QueryGenerator.new129 _(query.search_aspect_property('foo:aspect', 'foo:bar', 'foo')130 .search_aspect_property('foo:aspect', 'foo:blom', 'fim')131 .to_json)132 .must_match_json_expression(conjunction([133 { 'foo:aspect' => { '@search' => { '@value' => 'foo', '@property' => 'foo:bar' } } },134 { 'foo:aspect' => { '@search' => { '@value' => 'fim', '@property' => 'foo:blom' } } }135 ]))136 end137 it 'should allow a regex match to be specified' do138 query = DataServicesApi::QueryGenerator.new139 _(query.matches('foo:aspect', 'bing.*')140 .to_json)141 .must_match_json_expression(conjunction('foo:aspect' => { '@matches' => 'bing.*' }))142 query = DataServicesApi::QueryGenerator.new143 _(query.matches('foo:aspect', 'bing.*', flags: 'i')144 .to_json)145 .must_match_json_expression(conjunction('foo:aspect' => { '@matches' => ['bing.*', 'i'] }))146 end147 it 'should allow an overall query limit to be set' do148 query = DataServicesApi::QueryGenerator.new149 _(query.limit(101)150 .offset(20)151 .to_json)152 .must_match_json_expression('@limit' => 101, '@offset' => 20)153 end154 it 'should allow a query to be run in count mode' do155 query = DataServicesApi::QueryGenerator.new156 _(query.count_only.to_json)157 .must_match_json_expression('@count' => true)158 end159 it 'should not share structure between queries' do160 query_base = DataServicesApi::QueryGenerator.new.le('foo:crivens', 42)161 query_base.eq('foo:test', '@id' => 'http://foo.bar')162 _(query_base.terms['@and'].size).must_equal 1163 end164 it 'should allow compact JSON to be specified' do165 query = DataServicesApi::QueryGenerator.new166 _(query.compact_json.to_json)167 .must_match_json_expression('@json_mode' => 'compact')168 end169end...

Full Screen

Full Screen

core_spec.rb

Source:core_spec.rb Github

copy

Full Screen

...4require "npolar/rack/request"5require "npolar/rack/response"6require "npolar/api"7require "npolar/api/core"8describe 'Api::Core (accepts == formats == ["foo", bar"])' do9 def app10 Rack::Lint.new(api)11 end12 def api13 api = Npolar::Api::Core.new(nil, config)14 api.storage = storage_double15 api16 end17 def config18 {19 :accepts => ["foo/bar"],20 :formats => ["foo", "bar"],21 :headers => { "Content-Type" => "application/bar; charset=utf-8" },22 }23 end24 def storage_double25 storage = double("Api::Storage::Dummy")26 27 storage.stub(:delete => rack_response("DELETE"))28 storage.stub(:get => rack_response("GET"))29 storage.stub(:post => rack_response("POST"))30 storage.stub(:put => rack_response("PUT"))31 head_response = rack_response("GET")32 head_response[2] = []33 storage.stub(:head => head_response)34 35 storage.stub(:accepts => ["foo", "bar"])36 storage.stub(:accepts?) do | format|37 storage.accepts.include? format38 end39 #storage.stub(:valid?)40 storage.stub(:format)41 storage.stub(:format=)42 storage.stub(:media_format=)43 storage.stub(:formats => ["foo", "bar"])44 45 storage46 end47 def env(path="/", *args)48 Rack::MockRequest.env_for(path, *args)49 end50 def rack_response(method)51 52 status = 20053 if method =~ /POST|PUT/54 status = 20155 end56 headers = {"Content-Type" => "foo/bar; charset=utf-8" }57 body = method58 [status, headers, body]59 end60 def rack_request(path="/")61 Npolar::Rack::Request.new(env(path))62 end63 context "Document" do64 ["GET", "HEAD", "DELETE"].each do | method |65 context "#{method} /foo.bar" do66 it "200 OK" do67 request "/foo.bar", :method => method68 last_response.status.should == 20069 end70 it "Content-Length: #{method == 'HEAD' ? "3 or missing" : method.size }" do71 request "/foo.bar", :method => method72 if last_response.headers.keys.include? "Content-Length"73 last_response.headers.should include ({"Content-Length"=>"#{method == 'HEAD' ? "3" : method.size.to_s }"})74 end75 end76 77 if method == "HEAD"78 it "Body = ''" do79 head "/foo.bar"80 last_response.body.should == ""81 end82 else83 it "Body = '#{method}'" do84 request "/foo.bar", :method => method85 last_response.body.should == method86 end87 end88 end89 context "#{method} /foo [Accept: foo/bar]" do90 it "200 OK" do91 request "/foo", { :method => method, "HTTP_ACCEPT" => "foo/bar" }92 last_response.status.should == 20093 end94 end95 context "#{method} /foo.bad" do96 it "406 Not Acceptable" do97 request "/foo.bad", :method => method98 last_response.status.should == 40699 end100 end101 context "#{method} /foo [Accept: foo/bad]" do102 it "406 Not Acceptable" do103 request "/foo", { :method => method, "HTTP_ACCEPT" => "foo/bad" }104 last_response.status.should == 406105 end106 end107 #it "Content-Type: foo/bar; charset=utf-8"108 109 end 110 111 context "PUT /foo.bar" do112 113 # should => {"CONTENT_TYPE" => "foo/bar" }114 it "Format .bar should equal Content-Type: foo/bar" do115 put "/foo.bar", "PUT"116 last_request.env["CONTENT_TYPE"].should == "foo/bar"117 end118 it "201 Created" do119 put "/foo.bar", "PUT", {"CONTENT_TYPE" => "foo/bar" }120 last_response.status.should == 201121 end122 it "Body = 'PUT" do123 put "/foo.bar", "PUT", {"CONTENT_TYPE" => "foo/bar" }124 last_response.body.should == "PUT"125 end126 context "/foo.bad" do127 it "415 Unsupported Media Type" do128 put "/foo.bad", "{}", {"CONTENT_TYPE" => "foo/bad" }129 last_response.status.should == 415130 end131 end132 context "/foo [Content-Type: foo/bad, Accept: foo/bar]" do133 it "415 Unsupported Media Type" do134 put "/foo", "{}", {"CONTENT_TYPE" => "foo/bad", "HTTP_ACCEPT" => "foo/bar" }135 last_response.status.should == 415136 end137 end138 it "Invalid document" 139 it "Location: URI" # after POST|PUT140 it "Remove HTTP headers not on Whitelist"141 context "without payload" do142 it "400 Bad Method" do143 put "/foo.bar"144 last_response.status.should == 400145 end146 end147 # 4xx PUT foo.bad with bar Content-Type headers?148 # 201 PUT foo with bar headers?149 # POST?150 # DELETE foo.bar === DELETE foo ?151 end152 context "POST" do153 context "/foo.bar" do154 it "201 Created" do155 post "/foo.bar", "{}", {"CONTENT_TYPE" => "foo/bar" }156 last_response.status.should == 201157 end158 end159 context "/foo.bad" do160 it "415 Unsupported Media Type" do161 post "/foo.bad", "{}", {"CONTENT_TYPE" => "foo/bad" }162 last_response.status.should == 415163 end164 end165 context "/foo [Content-Type: foo/bad]" do166 it "415 Unsupported Media Type" do167 post "/foo", "{}", {"CONTENT_TYPE" => "foo/bad" }168 last_response.status.should == 415169 end170 end171 end172 context "UNKOWN" do173 context "/foo.bar" do174 it "405 Method Not Allowed" do175 request "/foo.bar", :method => "UNKOWN"176 last_response.status.should == 405177 end178 end179 end180 end181 context "Blank id" do182 ["PUT", "DELETE"].each do | method |183 context "#{method}" do184 it "400 Bad Request" do185 request "/.bar", :method => method186 last_response.status.should == 400187 end188 end189 end190 end191 context "Storage" do192 context "Missing storage" do193 it "501 Not Implemented" do194 core = Npolar::Api::Core.new195 core.call(env("/foo.foo")).status.should == 501196 end197 end198 end199 # POST tukle med id => overstyre ID altså POST uten id for å sikre at ID = uuid200 #context "JSON" do201 #202 # context "security" do203 # context "PUT requests where id in path != id in body" do204 # it "403 Forbidden" 205 # end206 # end 207 #208 #end209 context "Polar bears eat Exceptions" do210 it "500 Internal Server Error" do211 storage = double("Api::Storage::Dummy")212 storage.stub(:get => lambda { }) # will cause Exception213 core = Npolar::Api::Core.new(nil, :formats => ["foo", "bar"], :accepts => ["foo", "bar"], :storage => storage)214 core.call(env("/foo.bar")).status.should == 500215 end216 end217 context "Configuration" do218 context ":formats and :accepts" do219 it "String" do220 core = Npolar::Api::Core.new(nil, :formats => "zoo", :accepts => "zoo", :storage => storage_double)221 core.accepts.should == ["zoo"]222 core.formats.should == ["zoo"]223 end224 it "Array" do225 core = Npolar::Api::Core.new(nil, :formats => ["zoo","tzar"], :accepts => ["zoo","tzar"], :storage => storage_double)226 core.accepts.should == ["zoo","tzar"]227 core.formats.should == ["zoo","tzar"]228 end...

Full Screen

Full Screen

foo

Using AI Code Generation

copy

Full Screen

1class Api; end2statement is used to import the3statement is used to import4class Api; end5class Post; end

Full Screen

Full Screen

foo

Using AI Code Generation

copy

Full Screen

1class Api; end2statement is used to import the3statement is used to import4class Api; end5class Post; end

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Active_mocker_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful