bsm-openx 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class SessionTest < OpenX::TestCase
4
+
5
+ test "has a URI" do
6
+ assert_instance_of URI::HTTP, new_session.uri
7
+ end
8
+
9
+ test "has a URL" do
10
+ assert_equal 'http://test.host/path/to/api', new_session('http://test.host/path/to/api').url
11
+ end
12
+
13
+ test "has a host" do
14
+ assert_equal 'http://test.host', new_session('http://test.host/path/to/api').host
15
+ end
16
+
17
+ test "offers session-based API client (remote reference)" do
18
+ assert_instance_of OpenX::XmlrpcSessionClient, new_session.remote
19
+ end
20
+
21
+ test "login working" do
22
+ assert_nothing_raised { new_session.create(config['username'], config['password']) }
23
+ end
24
+
25
+ test "logout working" do
26
+ assert_nothing_raised { new_session.create(config['username'], config['password']) }
27
+ assert_not_nil new_session.id
28
+ assert_nothing_raised { new_session.destroy }
29
+ assert_nil new_session.id
30
+ end
31
+
32
+ private
33
+
34
+ def config
35
+ OpenX.configuration
36
+ end
37
+
38
+ def new_session(url = config['url'])
39
+ @session ||= Session.new(url)
40
+ end
41
+
42
+ end
@@ -0,0 +1,86 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TargetingRuleTest < OpenX::TestCase
4
+
5
+ test "is a Hash" do
6
+ assert_kind_of Hash, rule
7
+ end
8
+
9
+ test "has a type" do
10
+ assert_equal 'Geo:Region', rule['type']
11
+ end
12
+
13
+ test "raises exception on invalid type" do
14
+ assert_raise(RuntimeError) { new_rule('Wrong') }
15
+ assert_raise(RuntimeError) { new_rule('Geo:Wrong') }
16
+ assert_nothing_raised { new_rule('deliveryLimitations:Geo:Country') }
17
+ end
18
+
19
+ test "accepts updates" do
20
+ rule = new_rule.update('comparison' => '==')
21
+ assert_instance_of TargetingRule, rule
22
+ assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"=="}, rule)
23
+ end
24
+
25
+ test "accessors" do
26
+ rule = new_rule.logical('or').compare('==').with('GB|H9')
27
+ assert_equal({"logical"=>"or", "type"=>"Geo:Region", "comparison"=>"==", "data" => "GB|H9"}, rule)
28
+ end
29
+
30
+ test "completeness" do
31
+ assert !new_rule.complete?
32
+ assert new_rule.logical('or').compare('==').with('GB|H9').complete?
33
+ end
34
+
35
+ test "instantiation" do
36
+ assert_equal({
37
+ "logical"=>"and", "data"=>"test", "type"=>"Site:Pageurl", "comparison"=>"=~"
38
+ }, TargetingRule.instantiate(
39
+ "logical"=>"and", "data"=>"test", "type"=>"deliveryLimitations:Site:Pageurl", "comparison"=>"=~"
40
+ ))
41
+ end
42
+
43
+ test "comparisons" do
44
+ assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"==", "data" => "GB|H9"}, new_rule == 'GB|H9')
45
+ assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"==", "data" => "GB|H9"}, new_rule.eq?('GB|H9'))
46
+ assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"==", "data" => "GB|H9"}, new_rule.equal?('GB|H9'))
47
+ assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"==", "data" => "GB|H9"}, new_rule.is?('GB|H9'))
48
+
49
+ assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"!=", "data" => "GB|H9"}, new_rule.ne?('GB|H9'))
50
+ assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"!=", "data" => "GB|H9"}, new_rule.not_equal?('GB|H9'))
51
+ assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"!=", "data" => "GB|H9"}, new_rule.not?('GB|H9'))
52
+
53
+ assert_equal({"logical"=>"and", "type"=>"Time:Day", "comparison"=>">", "data" => "3"}, new_rule('Time:Day') > '3')
54
+ assert_equal({"logical"=>"and", "type"=>"Time:Day", "comparison"=>"<", "data" => "3"}, new_rule('Time:Day') < '3')
55
+ assert_equal({"logical"=>"and", "type"=>"Time:Day", "comparison"=>">=", "data" => "3"}, new_rule('Time:Day') >= '3')
56
+ assert_equal({"logical"=>"and", "type"=>"Time:Day", "comparison"=>"<=", "data" => "3"}, new_rule('Time:Day') <= '3')
57
+
58
+ assert_equal({"logical"=>"and", "type"=>"Geo:Country", "comparison"=>"=~", "data" => "GB,US"}, new_rule('Geo:Country').include?('GB', 'US'))
59
+ assert_equal({"logical"=>"and", "type"=>"Geo:Country", "comparison"=>"=~", "data" => "GB,US"}, new_rule('Geo:Country').contains?('GB', 'US'))
60
+ assert_equal({"logical"=>"and", "type"=>"Geo:Country", "comparison"=>"!~", "data" => "GB,US"}, new_rule('Geo:Country').exclude?('GB', 'US'))
61
+
62
+ assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"=x", "data" => "GB.H\\d"}, new_rule.match?(/GB.H\d/))
63
+ assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"=x", "data" => "GB.H\\d"}, new_rule =~ /GB.H\d/)
64
+ assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"!x", "data" => "GB.H\\d"}, new_rule.no_match?(/GB.H\d/))
65
+ end
66
+
67
+ test 'combining' do
68
+ rule = new_rule('Time:Day').gt?(3)
69
+ assert_equal rule['logical'], 'and'
70
+ rule = new_rule & rule
71
+ assert_equal rule['logical'], 'and'
72
+ rule = new_rule | rule
73
+ assert_equal rule['logical'], 'or'
74
+ end
75
+
76
+ private
77
+
78
+ def rule
79
+ @rule ||= new_rule
80
+ end
81
+
82
+ def new_rule(type = 'Geo:Region')
83
+ TargetingRule.new(type)
84
+ end
85
+
86
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TargetingRulesTest < OpenX::TestCase
4
+
5
+ test "creating rules" do
6
+ assert_equal [
7
+ {"logical"=>"and", "type"=>"Site:Pageurl", "comparison"=>"=~", "data" => "test"},
8
+ {"logical"=>"and", "type"=>"Client:Ip", "comparison"=>"=x", "data" => "^127\\."},
9
+ {"logical"=>"or", "type"=>"Geo:Country", "comparison"=>"=~", "data" => "GB,US"}
10
+ ], targeting_rules
11
+ end
12
+
13
+ end
data/test/test_zone.rb ADDED
@@ -0,0 +1,101 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class ZoneTest < OpenX::TestCase
4
+
5
+ def test_create
6
+ params = init_params
7
+ zone = Zone.create!(params)
8
+ assert_not_nil zone
9
+ params.each do |k,v|
10
+ assert_equal(v, zone.send(:"#{k}"))
11
+ end
12
+ zone.destroy
13
+ end
14
+
15
+ def test_find
16
+ params = init_params
17
+ zone = Zone.create!(params)
18
+ assert_not_nil zone
19
+ found_zone = Zone.find(zone.id)
20
+ assert_not_nil found_zone
21
+ assert_equal(zone, found_zone)
22
+ zone.destroy
23
+ end
24
+
25
+ def test_find_all
26
+ params = init_params
27
+ zone = Zone.create!(params)
28
+ assert_not_nil zone
29
+
30
+ zones = Zone.find(:all, publisher.id)
31
+ assert_equal(zones.sort, publisher.zones.sort)
32
+ found_zone = zones.find { |z| z.id == zone.id }
33
+ assert found_zone
34
+ assert_equal(zone, found_zone)
35
+ zone.destroy
36
+ end
37
+
38
+ def test_destroy
39
+ params = init_params
40
+ zone = Zone.create!(params)
41
+ assert_not_nil zone
42
+ id = zone.id
43
+ assert_nothing_raised {
44
+ zone.destroy
45
+ }
46
+ assert_raises(XMLRPC::FaultException) {
47
+ Zone.find(id)
48
+ }
49
+ end
50
+
51
+ def test_update
52
+ params = init_params
53
+ zone = Zone.create!(params)
54
+ assert_not_nil zone
55
+
56
+ found_zone = Zone.find(zone.id)
57
+ found_zone.name = 'tenderlove'
58
+ found_zone.save!
59
+
60
+ found_zone = Zone.find(zone.id)
61
+ assert_equal('tenderlove', found_zone.name)
62
+ end
63
+
64
+ def test_link_campaign
65
+ assert zone.link_campaign(campaign)
66
+ end
67
+
68
+ def test_unlink_campaign
69
+ assert_raises(XMLRPC::FaultException) {
70
+ zone.unlink_campaign(campaign)
71
+ }
72
+ assert zone.link_campaign(campaign)
73
+ assert zone.unlink_campaign(campaign)
74
+ end
75
+
76
+ def test_link_banner
77
+ assert zone.link_banner(banner)
78
+ end
79
+
80
+ def test_unlink_banner
81
+ assert_raises(XMLRPC::FaultException) {
82
+ zone.unlink_banner(banner)
83
+ }
84
+ assert zone.link_banner(banner)
85
+ assert zone.unlink_banner(banner)
86
+ end
87
+
88
+ def test_generate_tags
89
+ assert_match(/iframe/, zone.generate_tags)
90
+ end
91
+
92
+ def init_params
93
+ {
94
+ :publisher => publisher,
95
+ :name => "Zone - #{Time.now}",
96
+ :type => Zone::BANNER,
97
+ :width => 468,
98
+ :height => 60,
99
+ }
100
+ end
101
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bsm-openx
3
+ version: !ruby/object:Gem::Version
4
+ hash: 49
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 9
9
+ - 1
10
+ version: 1.9.1
11
+ platform: ruby
12
+ authors:
13
+ - Aaron Patterson
14
+ - Andy Smith
15
+ - TouchLocal P/L
16
+ - Dimitrij Denissenko
17
+ autorequire:
18
+ bindir: bin
19
+ cert_chain: []
20
+
21
+ date: 2010-09-09 00:00:00 +01:00
22
+ default_executable:
23
+ dependencies: []
24
+
25
+ description: A Ruby interface to the OpenX XML-RPC API
26
+ email: dimitrij@blacksquaremedia.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.txt
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - README.txt
38
+ - Rakefile
39
+ - VERSION
40
+ - bsm-openx.gemspec
41
+ - lib/openx.rb
42
+ - lib/openx/image.rb
43
+ - lib/openx/invocation.rb
44
+ - lib/openx/services.rb
45
+ - lib/openx/services/advertiser.rb
46
+ - lib/openx/services/agency.rb
47
+ - lib/openx/services/banner.rb
48
+ - lib/openx/services/base.rb
49
+ - lib/openx/services/campaign.rb
50
+ - lib/openx/services/channel.rb
51
+ - lib/openx/services/persistance.rb
52
+ - lib/openx/services/publisher.rb
53
+ - lib/openx/services/session.rb
54
+ - lib/openx/services/targeting_rule.rb
55
+ - lib/openx/services/targeting_rules.rb
56
+ - lib/openx/services/zone.rb
57
+ - lib/openx/xmlrpc_client.rb
58
+ - test/assets/300x250.jpg
59
+ - test/assets/cat.swf
60
+ - test/helper.rb
61
+ - test/test_advertiser.rb
62
+ - test/test_agency.rb
63
+ - test/test_banner.rb
64
+ - test/test_base.rb
65
+ - test/test_campaign.rb
66
+ - test/test_channel.rb
67
+ - test/test_openx.rb
68
+ - test/test_publisher.rb
69
+ - test/test_services.rb
70
+ - test/test_session.rb
71
+ - test/test_targeting_rule.rb
72
+ - test/test_targeting_rules.rb
73
+ - test/test_zone.rb
74
+ has_rdoc: true
75
+ homepage: http://github.com/dim/openx
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ requirements: []
102
+
103
+ rubyforge_project:
104
+ rubygems_version: 1.3.7
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: A Ruby interface to the OpenX XML-RPC API
108
+ test_files:
109
+ - test/test_openx.rb
110
+ - test/test_channel.rb
111
+ - test/test_targeting_rule.rb
112
+ - test/test_zone.rb
113
+ - test/test_session.rb
114
+ - test/helper.rb
115
+ - test/test_campaign.rb
116
+ - test/test_base.rb
117
+ - test/test_agency.rb
118
+ - test/test_advertiser.rb
119
+ - test/test_services.rb
120
+ - test/test_banner.rb
121
+ - test/test_targeting_rules.rb
122
+ - test/test_publisher.rb