Class: ODDB::TestNotificationLogger

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_util/notification_logger.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



13
14
15
16
# File 'test/test_util/notification_logger.rb', line 13

def setup
  @log = NotificationLogger.new
  @app = FlexMock.new
end

- (Object) test_create_csv



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'test/test_util/notification_logger.rb', line 131

def test_create_csv
  time1 = Time.local(2005, 1, 6, 12, 34)
  time2 = Time.local(2005, 1, 6, 12, 34)
  time3 = Time.local(2005, 2, 26, 18)
  time4 = Time.local(2005, 4, 7, 2, 4)

  time5 = Time.local(2004, 12, 24, 23, 44)
  time6 = Time.local(2005, 1, 12, 12, 34)
  time7 = Time.local(2005, 2, 4, 12, 34)


  entry1 = NotificationLogger::LogEntry.new("jlang@ywesee.com", "usenguel@ywesee.com", time1)
  entry2 = NotificationLogger::LogEntry.new("jlang@ywesee.com", "usenguel@ywesee.com", time2)
  entry3 = NotificationLogger::LogEntry.new("jlang@ywesee.com", "usenguel@ywesee.com", time3)
  entry4 = NotificationLogger::LogEntry.new("jlang@ywesee.com", "usenguel@ywesee.com", time4)
  entry5 = NotificationLogger::LogEntry.new("jlang@ywesee.com", "usenguel@ywesee.com", time5)
  entry6 = NotificationLogger::LogEntry.new("jlang@ywesee.com", "usenguel@ywesee.com", time5)
  entry7 = NotificationLogger::LogEntry.new("jlang@ywesee.com", "usenguel@ywesee.com", time7)
  logs = {
    [:drugs, '23487012']  => [entry1, entry2, entry3, entry4],
    [:drugs, '30785007']  => [entry5, entry6, entry7],
  }
  string = "Code;Name;Gr\303\266sse;Sender;Empf\303\244nger;Total;December 2004;January 2005;February 2005;March 2005;April 2005\n23487012;Ponstan;50 Tabletten;jlang@ywesee.com;usenguel@ywesee.com;4;0;2;1;0;1\n23487012;Ponstan;50 Tabletten;jlang@ywesee.com;usenguel@ywesee.com;4;0;2;1;0;1\n23487012;Ponstan;50 Tabletten;jlang@ywesee.com;usenguel@ywesee.com;4;0;2;1;0;1\n23487012;Ponstan;50 Tabletten;jlang@ywesee.com;usenguel@ywesee.com;4;0;2;1;0;1\n30785007;\\\"Mefanzid; Tabletten\\\";20 Tabletten;jlang@ywesee.com;usenguel@ywesee.com;3;2;0;1;0;0\n30785007;\\\"Mefanzid; Tabletten\\\";20 Tabletten;jlang@ywesee.com;usenguel@ywesee.com;3;2;0;1;0;0\n30785007;\\\"Mefanzid; Tabletten\\\";20 Tabletten;jlang@ywesee.com;usenguel@ywesee.com;3;2;0;1;0;0\n"
  @log.instance_variable_set('@logs', logs)
  assert_equal(4, @log.last_month.mon)
  registration1 = FlexMock.new
  registration2 = FlexMock.new
  @app.should_receive(:registration).and_return { |iksnr| 
    case iksnr
    when '30785'
      registration1
    when '23487'
      registration2
    else
      flunk("unexpected iksnr: #{iksnr}")
    end
  }
  package1 = FlexMock.new
  package2 = FlexMock.new
  registration1.should_receive(:package).and_return { |iksnr| 
    assert_equal('007', iksnr)
    package1
  }
  registration2.should_receive(:package).and_return { |iksnr| 
    assert_equal('012', iksnr)
    package2
  }
  package1.should_receive(:name).and_return {
    'Mefanzid; Tabletten'
  }
  package1.should_receive(:size).and_return {
    '20 Tabletten'
  }
  package2.should_receive(:name).and_return {
    'Ponstan'
  }
  package2.should_receive(:size).and_return {
    '50 Tabletten'
  }
  assert_equal(string, @log.create_csv(@app))
end

- (Object) test_csv_line



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'test/test_util/notification_logger.rb', line 94

def test_csv_line
  time1 = Time.local(2005, 2, 6, 12, 34)
  time2 = Time.local(2005, 2, 26, 18)
  time3 = Time.local(2005, 4, 7, 2, 4)
  time4 = Time.local(2005, 4, 6, 12, 34)
  logs = [time1, time2, time3, time4]
  month_range = Date.new(2005, 2)..Date.new(2005, 4)
  entry = @log.log('30785010', "usenguel@ywesee.com", "jlang@ywesee.com", time1)
  entries = [entry, entry, entry]
  arguments = {
    :name         => "Ponstan",
    :size  => "12 Tabletten",
    :iksnr        => "30785010", 
    :entries      => entries, 
  }
  result = @log.csv_line(month_range, entry, entries, arguments)
  line = ["30785010", "Ponstan", "12 Tabletten", "usenguel@ywesee.com", "jlang@ywesee.com", "3", "3", "0", "0"]
  assert_equal(line, result)
end

- (Object) test_csv_line__2



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'test/test_util/notification_logger.rb', line 113

def test_csv_line__2
  time1 = Time.local(2005, 2, 6, 12, 34)
  time2 = Time.local(2005, 2, 26, 18)
  time3 = Time.local(2005, 4, 7, 2, 4)
  time4 = Time.local(2005, 4, 6, 12, 34)
  logs = [time1, time2, time3, time4]
  month_range = Date.new(2005, 1)..Date.new(2005, 5)
  entry = @log.log('30785010', "usenguel@ywesee.com", "jlang@ywesee.com", time1)
  entries = [entry, entry, entry]
  arguments = {
    :name         => "Ponstan",
    :size  => "12 Tabletten",
    :iksnr        => "30785010", 
    :entries      => entries, 
  }
  result = @log.csv_line(month_range, entry, entries, arguments)
  line = ["30785010", "Ponstan", "12 Tabletten", "usenguel@ywesee.com", "jlang@ywesee.com", "3", "3", "0", "0"]
end

- (Object) test_first_month



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'test/test_util/notification_logger.rb', line 64

def test_first_month
  time1 = Time.local(2005, 1, 6, 12, 34)
  time2 = Time.local(2005, 2, 26, 18)
  time3 = Time.local(2005, 4, 7, 2, 4)
  time4 = Time.local(2005, 1, 6, 12, 34)
  time5 = Time.local(2004, 12, 24, 23, 44)
  time6 = Time.local(2005, 1, 12, 12, 34)
  time7 = Time.local(2005, 2, 4, 12, 34)
  logs = {
    '23487012'  => [time1, time2, time3, time4],
    '30785007'  => [time5, time6, time7],
  }
  @log.instance_variable_set('@logs', logs)
  assert_equal(Date.new(2004, 12), @log.first_month)
end

- (Object) test_last_month



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'test/test_util/notification_logger.rb', line 79

def test_last_month
  time1 = Time.local(2005, 1, 6, 12, 34)
  time2 = Time.local(2005, 2, 26, 18)
  time3 = Time.local(2005, 4, 7, 2, 4)
  time4 = Time.local(2005, 1, 6, 12, 34)
  time5 = Time.local(2004, 12, 24, 23, 44)
  time6 = Time.local(2005, 1, 12, 12, 34)
  time7 = Time.local(2005, 2, 4, 12, 34)
  logs = {
    '23487012'  => [time1, time2, time3, time4],
    '30785007'  => [time5, time6, time7],
  }
  @log.instance_variable_set('@logs', logs)
  assert_equal(Date.new(2005, 2), @log.last_month)
end

- (Object) test_log__1



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'test/test_util/notification_logger.rb', line 17

def test_log__1
  time1 = Time.local(2005, 4, 21, 15, 54)
  entry1 = @log.log([:drugs, '30785010'], "usenguel@ywesee.com", 
    "jlang@ywesee.com", time1)
  logs = @log.logs
  assert_equal(1, logs.size)
  entries = logs[[:drugs, '30785010']]
  assert_instance_of(Array, entries)
  assert_equal([entry1], entries)
  assert_instance_of(NotificationLogger::LogEntry, entry1)
  assert_equal(time1, entry1.time)
  assert_equal('usenguel@ywesee.com', entry1.sender)
  assert_equal('jlang@ywesee.com', entry1.recipient)

  time2 = Time.local(2005, 5, 21, 15, 54)
  entry2 = @log.log([:drugs, '30785011'], "usenguel@ywesee.com", 
    "jlang@ywesee.com", time2)
  expected = {
    [:drugs, "30785010"]  => [entry1],
    [:drugs, "30785011"]  => [entry2],
  }
  assert_equal(expected, @log.logs)

  time3 = Time.local(2005, 6, 21, 15, 54)
  entry3 = @log.log([:drugs, '30785010'], 'usenguel@ywesee.com',         'jlang@ywesee.com', time3)
  expected = {
    [:drugs, "30785010"]  => [entry1, entry3],
    [:drugs, "30785011"]  => [entry2],
  }
  assert_equal(expected, @log.logs)
end

- (Object) test_total_count



48
49
50
51
52
53
# File 'test/test_util/notification_logger.rb', line 48

def test_total_count
  time1 = Time.local(2005, 4, 21, 15, 54)
  @log.log('30785010', "usenguel@ywesee.com", "jlang@ywesee.com", time1)
 @log.log('30785011', "usenguel@ywesee.com", "jlang@ywesee.com", time1)
  assert_equal(2, @log.total_count)
end

- (Object) test_total_count_iksnr



54
55
56
57
58
59
60
61
62
63
# File 'test/test_util/notification_logger.rb', line 54

def test_total_count_iksnr
  time1 = Time.local(2005, 4, 21, 15, 54)
  time2 = Time.local(2005, 5, 21, 15, 54)
  time3 = Time.local(2005, 6, 21, 15, 54)
  @log.log('30785010', "usenguel@ywesee.com", "jlang@ywesee.com", time1)
  @log.log('30785010', "usenguel@ywesee.com", "jlang@ywesee.com", time2)
  @log.log('30785010', "usenguel@ywesee.com", "jlang@ywesee.com", time3)
  assert_equal(3, @log.total_count_iksnr(30785010))
  assert_equal(0, @log.total_count_iksnr(30785016))
end