Class: ODDB::OdbaExporter::TestGenericXls

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
FlexMock::TestCase
Defined in:
ext/export/test/test_generics_xls.rb

Instance Method Summary collapse

Instance Method Details

#assert_row(row) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
# File 'ext/export/test/test_generics_xls.rb', line 103

def assert_row(row)
  flexstub(Spreadsheet::Excel) do |klass|
    klass.should_receive(:new).and_return(flexmock{|book|
      book.should_receive(:add_worksheet).and_return(flexmock{|sheet|
        sheet.should_receive(:format_column)
        sheet.should_receive(:write).with(0,0,Array, Spreadsheet::Format)
        sheet.should_receive(:write).with(1,0,row) # This is the check point
      })
    })
  end
end

#redefine_ODBA(package) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'ext/export/test/test_generics_xls.rb', line 144

def redefine_ODBA(package)
  # This is a trick code, a little bit different from the flexstub in setup method
  # That is why I can re-define the ODBA stub.
  flexstub(ODBA) do |odba|
    odba.should_receive(:cache).and_return(flexmock{|cache|
     cache.should_receive(:fetch_named).and_return(flexmock{|app|
       app.should_receive(:log_group).with(:swissmedic_journal).and_return(@loggroup_swiss)
       app.should_receive(:log_group).with(:bsv_sl).and_return(@loggroup_bsv)
       app.should_receive(:each_package).and_yield(package)
     })
    })
  end
end

#setupObject



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
48
49
50
51
52
53
54
55
56
# File 'ext/export/test/test_generics_xls.rb', line 18

def setup
  @loggroup_swiss = LogGroup.new(:swissmedic_journal)
  @loggroup_swiss.create_log(Date.today)
  @loggroup_swiss.latest.change_flags = {123 => [:new]}
  @loggroup_bsv = LogGroup.new(:bsv_sl)
  @loggroup_bsv.create_log(Date.today)
  @loggroup_bsv.latest.change_flags = {123 => [:price_cut]}

  flexstub(ODBA.cache) do |cacheobj|
     cacheobj.should_receive(:fetch_named).and_return do
       flexmock do |appobj|
         appobj.should_receive(:log_group).with(:swissmedic_journal).and_return(@loggroup_swiss)
         appobj.should_receive(:log_group).with(:bsv_sl).and_return(@loggroup_bsv)
       end
     end
  end

  @pac = flexmock('Package') do |pack|
    pack.should_receive(:basename).and_return("basename")
    pack.should_receive(:dose).and_return("dose")
    pack.should_receive(:comparable_size).and_return(111)
    pack.should_receive(:barcode).and_return("222")
    pack.should_receive(:pharmacode).and_return(333)
    pack.should_receive(:name).and_return("name")
    pack.should_receive(:price_exfactory).and_return(444.444)
    pack.should_receive(:price_public).and_return(555.555)
    pack.should_receive(:company_name).and_return("company_name")
    pack.should_receive(:ikscat).and_return(666)
    pack.should_receive(:sl_entry).and_return(777)
    pack.should_receive(:registration_date).and_return(Date.new(2010,12,31))
    pack.should_receive(:"registration.pointer").and_return(123)
    pack.should_receive(:pointer).and_return(123)
    pack.should_receive(:comparables).and_return([@pac])
    pack.should_receive(:"registration.generic?").and_return(true)
    pack.should_receive(:public?).and_return(true)
  end

  @generics_xls = GenericXls.new(".")
end

#test__remarks1Object



57
58
59
60
61
62
63
# File 'ext/export/test/test_generics_xls.rb', line 57

def test__remarks1
  pac = flexstub(Package) do |pack|
    pack.should_receive(:"registration.pointer").and_return(999)
    pack.should_receive(:pointer).and_return(999)
  end
  assert_nil(@generics_xls._remarks(pac, 'Generikum'))
end

#test__remarks2Object



64
65
66
67
# File 'ext/export/test/test_generics_xls.rb', line 64

def test__remarks2
  expect = "Generikum: neue Registration, Preissenkung"
  assert_equal(expect, @generics_xls._remarks(@pac, 'Generikum'))
end

#test_export_comparableObject



123
124
125
126
127
128
129
130
131
132
# File 'ext/export/test/test_generics_xls.rb', line 123

def test_export_comparable
  expect_row =  ["basename", "basename dose/111", "222", "333", "name", 
                 "dose", "111", "444.44", "555.55", "company_name", "666", 
                 "SL", "31.12.2010", "222", "333", "name", "dose", "111", 
                 "444.44", "555.55", "company_name", "666", "SL", "31.12.2010", 
                 "Original: neue Registration, Preissenkung Generikum: neue Registration, Preissenkung"]
  assert_row(expect_row)
  generics_xls = GenericXls.new(".")
  assert_equal(2, generics_xls.export_comparable(@pac, @pac))
end

#test_export_comparablesObject



133
134
135
136
137
138
139
140
141
142
143
# File 'ext/export/test/test_generics_xls.rb', line 133

def test_export_comparables
  expect_row =  ["basename", "basename dose/111", "222", "333", "name", 
                 "dose", "111", "444.44", "555.55", "company_name", "666", 
                 "SL", "31.12.2010", "222", "333", "name", "dose", "111", 
                 "444.44", "555.55", "company_name", "666", "SL", "31.12.2010", 
                 "Original: neue Registration, Preissenkung Generikum: neue Registration, Preissenkung"]
  assert_row(expect_row)
  generics_xls = GenericXls.new(".")
  assert_equal(2, generics_xls.export_comparable(@pac, @pac))
 
end

#test_export_genericObject



114
115
116
117
118
119
120
121
122
# File 'ext/export/test/test_generics_xls.rb', line 114

def test_export_generic
  expect_row = ["", "", "", "", "", "", "", "", "", "", "", "", "", 
                "222", "333", "name", "dose", "111", "444.44", "555.55", 
                "company_name", "666", "SL", "31.12.2010", 
                "Generikum: neue Registration, Preissenkung"]
  assert_row(expect_row)
  generics_xls = GenericXls.new(".")
  assert_equal(2, generics_xls.export_generic(@pac))
end

#test_export_generics__case_exportObject



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'ext/export/test/test_generics_xls.rb', line 196

def test_export_generics__case_export
  pac = flexstub(@pac) do |pack|
    pack.should_receive(:"registration.active?").and_return(true)
    pack.should_receive(:"registration.original?").and_return(true)
    pack.should_receive(:comparables).and_return([]) 
    pack.should_receive(:basename).and_return("basename")          # This is the point
    pack.should_receive(:"registration.generic?").and_return(true) # This is the point
    pack.should_receive(:"registration.pointer").and_return(123)
  end

  redefine_ODBA(pac)

  # Note:
  # The actual row value (data) is not checked here,
  # since it is tested in test_export_generic.
  generics_xls = GenericXls.new(".")
  assert_equal(3, generics_xls.export_generics)
end

#test_export_generics__case_no_outputObject



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'ext/export/test/test_generics_xls.rb', line 157

def test_export_generics__case_no_output
  # Note:
  # if the return value of comparables is not empty (point.1), or
  # if the return value of registration.generics? is not false (ture) (point.2),
  # then you have to define the other method in the flexstub(Package),
  # since export_comparables or export_generic will be called.
  pac = flexstub(@pac) do |pack|
    pack.should_receive(:"registration.active?").and_return(true)
    pack.should_receive(:"registration.original?").and_return(true)
    pack.should_receive(:comparables).and_return([])                # point.1
    pack.should_receive(:"registration.generic?").and_return(false) # point.2
  end

  redefine_ODBA(pac)

  generics_xls = GenericXls.new(".")
  assert_equal(2, generics_xls.export_generics)
end

#test_export_generics__case_warningObject



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'ext/export/test/test_generics_xls.rb', line 175

def test_export_generics__case_warning
  pac = flexstub(@pac) do |pack|
    pack.should_receive(:"registration.active?").and_return(true)
    pack.should_receive(:"registration.original?").and_return(true)
    pack.should_receive(:basename).and_return(nil)      # This is the point
  end

  redefine_ODBA(pac)

  # Note:
  # if the following flexstub is not defined,
  # an actual email will be sent.
  flexstub(Log) do |log|
    log.should_receive(:new)
  end

  generics_xls = GenericXls.new(".")
  assert_raise(NoMethodError) do    # This means the report process runs if this assert passes
    generics_xls.export_generics
  end
end

#test_format_genericObject



87
88
89
90
91
92
93
94
# File 'ext/export/test/test_generics_xls.rb', line 87

def test_format_generic
  pac = flexstub(@pac) do |pack|
    pack.should_receive(:sl_entry).and_return(nil)
  end
  expect = ["222", "333", "name", "dose", "111", "444.44", "555.55", "company_name",
            "666", "", "31.12.2010"]
  assert_equal(expect,  @generics_xls.format_generic(pac))
end

#test_format_originalObject



82
83
84
85
86
# File 'ext/export/test/test_generics_xls.rb', line 82

def test_format_original
  expect = ["basename", "basename dose/111", "222", "333", "name", "dose", "111", 
            "444.44", "555.55", "company_name", "666", "SL", "31.12.2010"]
  assert_equal(expect,  @generics_xls.format_original(@pac))
end

#test_format_priceObject



72
73
74
75
76
77
# File 'ext/export/test/test_generics_xls.rb', line 72

def test_format_price
  price = nil
  assert_nil(@generics_xls.format_price(price))
  price = 12.349
  assert_equal("12.35", @generics_xls.format_price(price))
end

#test_format_rowObject



95
96
97
98
99
100
101
102
# File 'ext/export/test/test_generics_xls.rb', line 95

def test_format_row
  expect = ["basename", "basename dose/111", "222", "333", "name", "dose", "111",
            "444.44", "555.55", "company_name", "666", "SL", "31.12.2010", "222",
            "333", "name", "dose", "111", "444.44", "555.55", "company_name",
            "666", "SL", "31.12.2010", 
            "Original: neue Registration, Preissenkung Generikum: neue Registration, Preissenkung"]
  assert_equal(expect,  @generics_xls.format_row(@pac, @pac))
end

#test_preprocess_fieldsObject



78
79
80
81
# File 'ext/export/test/test_generics_xls.rb', line 78

def test_preprocess_fields
  fields = [1,2,3,Date.new(2010, 12, 31)]
  assert_equal(["1","2","3","31.12.2010"], @generics_xls.preprocess_fields(fields))
end

#test_remarksObject



68
69
70
71
# File 'ext/export/test/test_generics_xls.rb', line 68

def test_remarks
  expect = "Original: neue Registration, Preissenkung Generikum: neue Registration, Preissenkung"
  assert_equal(expect, @generics_xls.remarks(@pac, @pac))
end