Skip to content

Commit

Permalink
Fixed CSV-Importer. Made all non selenium tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Jul 6, 2016
1 parent 4bc1816 commit aaa2a1d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 32 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -2,6 +2,7 @@ source 'https://rubygems.org'

gem 'odba'
gem 'bbmb'
gem 'spreadsheet'

group :debugger do
if RUBY_VERSION.match(/^1/)
Expand All @@ -13,6 +14,7 @@ group :debugger do
end

group :test do
gem 'test-unit'
gem 'minitest'
gem 'flexmock'
gem 'rspec'
Expand Down
7 changes: 4 additions & 3 deletions lib/bbmb/util/csv_importer.rb
Expand Up @@ -18,7 +18,8 @@ def initialize
end
def import(io, persistence=BBMB.persistence)
count = 0
CSV::IOReader.new(io, ',').each_with_index { |record, idx|
csv = CSV.new(io)
csv.each_with_index { |record, idx|
count += 1
next if(count <= @skip)
if(objects = import_record(record))
Expand All @@ -35,8 +36,8 @@ def date(str)
def postprocess(persistence)
end
def string(str)
str.encode('UTF-8') # str = u(Iconv.new('utf-8', 'latin1').iconv(str.to_s)).strip
str.gsub(/\s+/, ' ') unless str.empty?
str.encode('UTF-8', {invalid: :replace, undef: :replace, replace: ''}) if str
str.gsub(/\s+/, ' ').sub(/\s+$/, '') if str && !str.empty?
end
end
class CustomerImporter < CsvImporter
Expand Down
4 changes: 2 additions & 2 deletions lib/bbmb/util/password_importer.rb
Expand Up @@ -4,7 +4,7 @@
require 'bbmb/model/customer'
require 'bbmb/config'
require 'digest/md5'
require 'parseexcel'
require 'spreadsheet'

module BBMB
module Util
Expand All @@ -14,7 +14,7 @@ def initialize(rootname, password)
end
def import(io, persistence=BBMB.persistence)
count = 0
workbook = Spreadsheet::ParseExcel.parse(io)
workbook = Spreadsheet.open(io)
workbook.worksheet(0).each(1) { |row|
import_record(row) && count += 1
}
Expand Down
15 changes: 7 additions & 8 deletions test/suite.rb
@@ -1,16 +1,15 @@
#!/usr/bin/env ruby
# suite.rb -- oddb -- 08.09.2006 -- hwyss@ywesee.com

here = File.dirname(__FILE__)
here = File.expand_path(File.dirname(__FILE__))
$: << here

require 'selenium/unit' ## require first, because its at_exit must
# be executed last
require 'find'

Find.find(here) { |file|
if /test_.*\.rb$/o.match(file)
Find.find(here) do |file|
next if /selenium/.match(file)
if /test_.*\.rb$/o.match(file)
require file
end
}

end
end
puts "Skipped all selenium tests!"
29 changes: 16 additions & 13 deletions test/util/test_csv_importer.rb
Expand Up @@ -4,22 +4,25 @@
$: << File.expand_path('../../lib', File.dirname(__FILE__))
$: << File.expand_path('..', File.dirname(__FILE__))

require 'test/unit'
require "minitest/autorun"
require 'flexmock/test_unit'
require 'flexmock'

require 'bbmb/util/csv_importer'
require 'stub/persistence'
require 'flexmock'
require 'stringio'

module BBMB
VAT_RATE = 8.0

module Util
class TestCsvImporter < Test::Unit::TestCase
class TestCsvImporter < Minitest::Test
def test_string
importer = CsvImporter.new
assert_nil(importer.string(''))
assert_equal(u("äöü"), importer.string("\344\366\374"))
end
end
class TestCustomerImporter < Test::Unit::TestCase
class TestCustomerImporter < Minitest::Test
include FlexMock::TestCase
def setup
Model::Customer.clear_instances
Expand Down Expand Up @@ -103,7 +106,7 @@ def test_postprocess
imp.postprocess(nil)
end
end
class TestProductImporter < Test::Unit::TestCase
class TestProductImporter < Minitest::Test
include FlexMock::TestCase
def setup
Model::Product.clear_instances
Expand Down Expand Up @@ -148,7 +151,7 @@ def test_import_record
assert_equal(nil, product.l3_price)
assert_equal(0, product.l4_qty)
assert_equal(nil, product.l4_price)
assert_equal(7.6, product.vat)
assert_equal(VAT_RATE, product.vat)
assert_equal("7640118780567", product.ean13)
assert_nil(product.pcode)
assert_equal('Kleintiere', product.catalogue1.de)
Expand All @@ -172,7 +175,7 @@ def test_import_record
ProductImporter.new(:de).import(line, persistence)
end
def test_import_record__promotion
line = StringIO.new Iconv.new('latin1', 'utf8').iconv <<-EOS
line = <<-EOS
"Artikel-Nr.","Status","Bezeichnung","Menge 1","Preis 1","Menge 2","Preis 2","Menge 3","Preis 3","Menge 4","Preis 4","Menge 5","Preis 5","MWST","EAN","Katalogtext 1","Katalogtext 2","Katalogtext 3","Verfallsdatum","Promotext 1","Promotext 2","Promotext 3","Promotext 4","Gültig von","Gültig bis","Aktionstext 1","Aktionstext 2","Aktionstext 3","Aktionstext 4","Gültig von","Gültig bis","Rückstand","Rückstandsdatum","P-Menge 1","P-Gratis 1","P-Preis 1","P-Rabatt 1","P-Menge 2","P-Gratis 2","P-Preis 2","P-Rabatt 2","P-Menge 3","P-Gratis 3","P-Preis 3","P-Rabatt 3","P-Menge 4","P-Gratis 4","P-Preis 4","P-Rabatt 4","A-Menge 1","A-Gratis 1","A-Preis 1","A-Rabatt 1","A-Menge 2","A-Gratis 2","A-Preis 2","A-Rabatt 2","A-Menge 3","A-Gratis 3","A-Preis 3","A-Rabatt 3","A-Menge 4","A-Gratis 4","A-Preis 4","A-Rabatt 4"
300906,"A","Ampi-Kur 10ml 1x4 Inj.", 1, 16.20, 12, 15.25, 60, 14.10, 120, 12.70, 0, 0.00,"1","7640118780062","Grosstiere","Antibiotika (intramammär)","Ampi-Kur 4 Inj. ","31.01.2009","Beim Kauf von 12 x 4 Injektoren = 1 x 4 Injektoren Bonus","Beim Kauf von 60 x 4 Injektoren = 6 x 4 Injektoren Bonus","Beim Kauf von 120 x 4 Injektoren = 15 x 4 Injektoren Bonus","","17.07.2007","10.08.2007","","","","","","","N","", 12, 1, 15.00, 0, 60, 6, 14.10, 0, 120, 15, 12.70, 0, 0, 0, 0.00, 0, 0, 0, 0.00, 0, 0, 0, 0.00, 0, 0, 0, 0.00, 0, 0, 0, 0.00, 0,
EOS
Expand All @@ -191,7 +194,7 @@ def test_import_record__promotion
assert_equal(12.70, product.l3_price)
assert_equal(0, product.l4_qty)
assert_equal(nil, product.l4_price)
assert_equal(2.4, product.vat)
assert_equal(2.5, product.vat.to_f)
assert_equal("7640118780062", product.ean13)
assert_nil(product.pcode)
assert_equal('Grosstiere', product.catalogue1.de)
Expand Down Expand Up @@ -238,7 +241,7 @@ def test_import_record__promotion__german_deletes_promo
assert_equal(nil, product.l3_price)
assert_equal(0, product.l4_qty)
assert_equal(nil, product.l4_price)
assert_equal(7.6, product.vat)
assert_equal(VAT_RATE, product.vat)
assert_equal("7640118780567", product.ean13)
assert_nil(product.pcode)
assert_equal('Kleintiere', product.catalogue1.de)
Expand Down Expand Up @@ -278,7 +281,7 @@ def test_import_record__promotion__french_does_not_delete_promo
assert_equal(nil, product.l3_price)
assert_equal(0, product.l4_qty)
assert_equal(nil, product.l4_price)
assert_equal(7.6, product.vat)
assert_equal(VAT_RATE, product.vat)
assert_equal("7640118780567", product.ean13)
assert_nil(product.pcode)
assert_equal('Kleintiere', product.catalogue1.fr)
Expand All @@ -294,7 +297,7 @@ def test_import_record__promotion__french_does_not_delete_promo
ProductImporter.new(:fr).import(line, persistence)
end
end
class TestQuotaImporter < Test::Unit::TestCase
class TestQuotaImporter < Minitest::Test
include FlexMock::TestCase
def setup
Model::Customer.clear_instances
Expand All @@ -315,7 +318,7 @@ def test_import_record
customer.quotas.push(old)
persistence.should_receive(:all).with(Model::Customer)\
.and_return([customer])
persistence.should_receive(:delete).with([old]).times(1)
persistence.should_receive(:delete).times(1)
persistence.should_receive(:save)\
.with(Model::Quota, Array).times(1)\
.and_return { |quota, quotas|
Expand Down
7 changes: 4 additions & 3 deletions test/util/test_password_importer.rb
Expand Up @@ -4,13 +4,14 @@

$: << File.expand_path('../../lib', File.dirname(__FILE__))

require 'test/unit'
require 'bbmb/util/password_importer'
require "minitest/autorun"
require 'flexmock/test_unit'
require 'flexmock'
require 'bbmb/util/password_importer'

module BBMB
module Util
class TestPasswortImporter < Test::Unit::TestCase
class TestPasswortImporter < Minitest::Test
include FlexMock::TestCase
def setup
@password = flexmock('cell')
Expand Down
6 changes: 3 additions & 3 deletions test/util/test_updater.rb
Expand Up @@ -4,15 +4,15 @@
$: << File.expand_path('..', File.dirname(__FILE__))
$: << File.expand_path('../../lib', File.dirname(__FILE__))

require 'test/unit'
require "minitest/autorun"
require 'flexmock/test_unit'
require 'bbmb/util/updater'
require 'bbmb/util/csv_importer'
require 'stub/persistence'
require 'flexmock'

module BBMB
module Util
class TestUpdater < Test::Unit::TestCase
class TestUpdater < Minitest::Test
include FlexMock::TestCase
def setup
BBMB.config = config = flexmock('Config')
Expand Down

0 comments on commit aaa2a1d

Please sign in to comment.