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,94 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class AgencyTest < OpenX::TestCase
4
+ def destroy
5
+ Agency.find(:all).each do |agency|
6
+ agency.destroy if agency.name == init_params[:name]
7
+ end
8
+ super
9
+ end
10
+
11
+ def test_create!
12
+ a = nil
13
+ assert_nothing_raised {
14
+ a = Agency.create!(init_params)
15
+ }
16
+ assert_not_nil a
17
+ assert_not_nil a.id
18
+ init_params.each { |k,v|
19
+ assert_equal(v, a.send(:"#{k}"))
20
+ }
21
+ end
22
+
23
+ def test_modify
24
+ a = nil
25
+ assert_nothing_raised {
26
+ a = Agency.create!(init_params)
27
+ }
28
+ assert_not_nil a
29
+ assert_not_nil a.id
30
+ a.name = 'Awesome name!'
31
+ a.save!
32
+
33
+ a = Agency.find(a.id)
34
+ assert_equal('Awesome name!', a.name)
35
+ a.destroy
36
+ end
37
+
38
+ def test_find
39
+ a = nil
40
+ assert_nothing_raised {
41
+ a = Agency.create!(init_params)
42
+ }
43
+ a = Agency.find(a.id)
44
+ init_params.each { |k,v|
45
+ assert_equal(v, a.send(:"#{k}"))
46
+ }
47
+ end
48
+
49
+ def test_find_all
50
+ a = nil
51
+ assert_nothing_raised {
52
+ a = Agency.create!(init_params)
53
+ }
54
+ list = Agency.find(:all)
55
+ assert list.all? { |x| x.is_a?(Agency) }
56
+ assert list.any? { |x| x.name == init_params[:name] }
57
+ end
58
+
59
+ def test_destroy
60
+ a = nil
61
+ assert_nothing_raised {
62
+ a = Agency.create!(init_params)
63
+ }
64
+ id = a.id
65
+ assert_nothing_raised {
66
+ a.destroy
67
+ }
68
+ assert_raises(XMLRPC::FaultException) {
69
+ Agency.find(id)
70
+ }
71
+ end
72
+
73
+ def test_static_destroy
74
+ a = nil
75
+ assert_nothing_raised {
76
+ a = Agency.create!(init_params)
77
+ }
78
+ id = a.id
79
+ assert_nothing_raised {
80
+ Agency.destroy(id)
81
+ }
82
+ assert_raises(XMLRPC::FaultException) {
83
+ Agency.find(id)
84
+ }
85
+ end
86
+
87
+ def init_params
88
+ {
89
+ :name => 'Testing!',
90
+ :contact_name => 'Contact Name!',
91
+ :email => 'foo@bar.com'
92
+ }
93
+ end
94
+ end
@@ -0,0 +1,85 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+ require 'date'
3
+
4
+ class BannerTest < OpenX::TestCase
5
+
6
+ test "destroy" do
7
+ id = banner.id
8
+ assert_nothing_raised {
9
+ banner.destroy
10
+ }
11
+ assert_raises(XMLRPC::FaultException) {
12
+ Banner.find(id)
13
+ }
14
+ end
15
+
16
+ test "find" do
17
+ assert_not_nil banner
18
+ found = Banner.find(banner.id)
19
+ assert_not_nil found
20
+ assert_equal(banner, found)
21
+ end
22
+
23
+ test "update" do
24
+ banner.name = 'super awesome'
25
+ banner.save!
26
+
27
+ found = Banner.find(banner.id)
28
+ assert_equal('super awesome', found.name)
29
+ found.destroy
30
+ end
31
+
32
+ test "find all" do
33
+ banner = Banner.create!(init_params)
34
+ list = Banner.find(:all, banner.campaign.id)
35
+ assert list.all? { |x| x.is_a?(Banner) }
36
+ assert list.any? { |x| x == banner }
37
+ end
38
+
39
+ test "create" do
40
+ banner = nil
41
+ params = init_params
42
+ assert_nothing_raised {
43
+ banner = Banner.create!(params)
44
+ }
45
+ assert_not_nil banner
46
+ params.each do |k,v|
47
+ assert_equal(v, banner.send(:"#{k}"))
48
+ end
49
+ end
50
+
51
+ test "create with JPEG" do
52
+ banner = nil
53
+ params = init_params.merge({
54
+ :image => OpenX::Image.new(File.open(TEST_JPG, 'rb'))
55
+ })
56
+ assert_nothing_raised {
57
+ banner = Banner.create!(params)
58
+ }
59
+ assert_not_nil banner
60
+ params.each do |k,v|
61
+ assert_equal(v, banner.send(:"#{k}"))
62
+ end
63
+ end
64
+
65
+ test "getting/setting targeting" do
66
+ assert_equal [], banner.targeting
67
+ assert_nothing_raised {
68
+ banner.targeting = targeting_rules
69
+ }
70
+ assert_equal targeting_rules, banner.targeting
71
+ end
72
+
73
+ private
74
+
75
+ def init_params
76
+ {
77
+ :name => "Banner-#{Time.now}",
78
+ :storage_type => Banner::LOCAL_SQL,
79
+ :campaign => campaign,
80
+ :url => 'http://tenderlovemaking.com/',
81
+ :file_name => 'oogabooga',
82
+ :image => OpenX::Image.new(File.open(TEST_SWF, 'rb'))
83
+ }
84
+ end
85
+ end
data/test/test_base.rb ADDED
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+ require 'fileutils'
3
+
4
+ class BaseTest < OpenX::TestCase
5
+
6
+ def teardown
7
+ Base.connection = nil
8
+ end
9
+
10
+ test "uses (shared) default connection" do
11
+ assert_equal OpenX::Services.default_connection, Base.connection
12
+ assert_equal Base.connection, Banner.connection
13
+ end
14
+
15
+ test "can use custom connection" do
16
+ Base.establish_connection(OpenX.configuration)
17
+
18
+ assert_not_equal OpenX::Services.default_connection, Base.connection
19
+ assert_not_equal Base.connection, Banner.connection
20
+ end
21
+
22
+ test "can temporarily use a custom connection" do
23
+ assert_equal OpenX::Services.default_connection, Base.connection
24
+ assert_equal Base.connection, Banner.connection
25
+
26
+ Base.with_connection(OpenX.configuration) do
27
+ assert_not_equal OpenX::Services.default_connection, Base.connection
28
+ assert_not_equal Base.connection, Banner.connection
29
+ end
30
+
31
+ assert_equal OpenX::Services.default_connection, Base.connection
32
+ assert_equal Base.connection, Banner.connection
33
+ end
34
+
35
+ test "has remote client reference" do
36
+ assert_instance_of OpenX::XmlrpcSessionClient, Base.remote
37
+ assert_equal Banner.remote, Base.remote
38
+ end
39
+
40
+ end
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+ require 'date'
3
+
4
+ class CampaignTest < OpenX::TestCase
5
+ def test_destroy
6
+ a = nil
7
+ assert_nothing_raised {
8
+ a = Campaign.create!(init_params)
9
+ }
10
+ id = a.id
11
+ assert_nothing_raised {
12
+ a.destroy
13
+ }
14
+ assert_raises(XMLRPC::FaultException) {
15
+ Campaign.find(id)
16
+ }
17
+ end
18
+
19
+ def test_create_campaign
20
+ campaign = nil
21
+ params = init_params
22
+ assert_nothing_raised {
23
+ campaign = Campaign.create!(params)
24
+ }
25
+ assert_not_nil campaign
26
+ params.each do |k,v|
27
+ assert_equal(v, campaign.send(:"#{k}"))
28
+ end
29
+ end
30
+
31
+ def test_find
32
+ a = nil
33
+ params = init_params
34
+ assert_nothing_raised {
35
+ a = Campaign.create!(params)
36
+ }
37
+ assert_not_nil a
38
+ a = Campaign.find(a.id)
39
+ assert a
40
+ assert_equal(params[:advertiser].id, a.advertiser.id)
41
+ params.each { |k,v|
42
+ assert_equal(v, a.send(:"#{k}"))
43
+ }
44
+ end
45
+
46
+ def test_find_all
47
+ a = nil
48
+ params = init_params
49
+ assert_nothing_raised {
50
+ a = Campaign.create!(params)
51
+ }
52
+ list = Campaign.find(:all, a.advertiser.id)
53
+ assert list.all? { |x| x.is_a?(Campaign) }
54
+ assert list.any? { |x| x.name == params[:name] }
55
+ end
56
+
57
+ def init_params
58
+ {
59
+ :advertiser => advertiser,
60
+ :name => "Test Campaign-#{Time.now}",
61
+ :impressions => 2000
62
+ }
63
+ end
64
+ end
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class ChannelTest < OpenX::TestCase
4
+
5
+ test "create" do
6
+ channel = Channel.create!(params)
7
+ assert_not_nil channel
8
+ params.each do |k,v|
9
+ assert_equal(v, channel.send(:"#{k}"))
10
+ end
11
+ channel.destroy
12
+ end
13
+
14
+ test "find" do
15
+ found = Channel.find(channel.id)
16
+ assert_not_nil found
17
+ assert_equal(channel, found)
18
+ end
19
+
20
+ test "find_all" do
21
+ channel # Create one
22
+ channels = Channel.find(:all, publisher.id)
23
+ assert_equal channels.sort, publisher.channels.sort
24
+ assert_equal 1, channels.size
25
+ end
26
+
27
+ test "destroy" do
28
+ assert_not_nil channel
29
+ id = channel.id
30
+ assert_nothing_raised {
31
+ channel.destroy
32
+ }
33
+ assert_raises(XMLRPC::FaultException) {
34
+ Channel.find(id)
35
+ }
36
+ end
37
+
38
+ test "update" do
39
+ channel
40
+ channel.name = 'tenderlove'
41
+ channel.save!
42
+
43
+ found = Channel.find(channel.id)
44
+ assert_equal('tenderlove', found.name)
45
+ end
46
+
47
+ test "getting/setting targeting" do
48
+ assert_equal [], channel.targeting
49
+ assert_nothing_raised {
50
+ channel.targeting = targeting_rules
51
+ }
52
+ assert_equal targeting_rules, channel.targeting
53
+ end
54
+
55
+ private
56
+
57
+ def params
58
+ @params ||= {
59
+ :publisher => publisher,
60
+ :name => "Channel - #{Time.now}",
61
+ :comments => 'Random Comments',
62
+ :description => 'Random Description'
63
+ }
64
+ end
65
+ end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class OpenXTest < OpenX::TestCase
4
+
5
+ test "has an env" do
6
+ assert_equal 'test', OpenX.env
7
+ end
8
+
9
+ test "has an configuration" do
10
+ assert_instance_of Hash, OpenX.configuration
11
+ end
12
+
13
+ test "has config file location" do
14
+ assert File.exist?(OpenX.config_file)
15
+ end
16
+
17
+ end
@@ -0,0 +1,69 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class PublisherTest < OpenX::TestCase
4
+ def test_update
5
+ params = init_params
6
+ publisher = Publisher.create!(params)
7
+ found_pub = Publisher.find(publisher.id)
8
+ assert_equal(publisher, found_pub)
9
+ found_pub.name = 'awesome!!!!'
10
+ found_pub.save!
11
+
12
+ found_pub = Publisher.find(publisher.id)
13
+ assert_equal('awesome!!!!', found_pub.name)
14
+ found_pub.destroy
15
+ end
16
+
17
+ def test_create
18
+ params = init_params
19
+ publisher = Publisher.create!(params)
20
+ assert_not_nil publisher
21
+ params.each do |k,v|
22
+ assert_equal(v, publisher.send(:"#{k}"))
23
+ end
24
+ publisher.destroy
25
+ end
26
+
27
+ def test_find
28
+ params = init_params
29
+ publisher = Publisher.create!(params)
30
+ assert_not_nil publisher
31
+ found_pub = Publisher.find(publisher.id)
32
+ assert_equal(publisher, found_pub)
33
+ publisher.destroy
34
+ end
35
+
36
+ def test_find_all
37
+ params = init_params
38
+ publisher = Publisher.create!(params)
39
+ publishers = Publisher.find(:all, agency.id)
40
+ pub = publishers.find { |a| a.id == publisher.id }
41
+ assert_not_nil pub
42
+ assert_equal(publisher, pub)
43
+ publisher.destroy
44
+ end
45
+
46
+ def test_destroy
47
+ params = init_params
48
+ publisher = Publisher.create!(params)
49
+ assert_not_nil publisher
50
+ id = publisher.id
51
+ assert_nothing_raised {
52
+ publisher.destroy
53
+ }
54
+ assert_raises(XMLRPC::FaultException) {
55
+ Publisher.find(id)
56
+ }
57
+ end
58
+
59
+ def init_params
60
+ {
61
+ :agency => agency,
62
+ :name => "Publisher! - #{Time.now}",
63
+ :contact_name => 'Aaron Patterson',
64
+ :email => 'aaron@tenderlovemaking.com',
65
+ :username => 'one',
66
+ :password => 'two',
67
+ }
68
+ end
69
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class ServicesTest < OpenX::TestCase
4
+
5
+ test "has a default connection" do
6
+ assert_instance_of OpenX::Services::Session, OpenX::Services.default_connection
7
+ end
8
+
9
+ test "can establish new connections" do
10
+ default = OpenX::Services.default_connection
11
+ clone = OpenX::Services.establish_connection(OpenX.configuration)
12
+ assert_equal OpenX::Services.default_connection, default
13
+ assert_not_equal OpenX::Services.default_connection, clone
14
+ end
15
+
16
+ end