Skip to content

Commit

Permalink
add integrationt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianMindee committed Sep 12, 2024
1 parent 1d9a742 commit 6f70d21
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/mindee/http/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def predict_req_post(input_source, all_words: false, full_text: false, close_fil

params = {}
params[:cropper] = 'true' if cropper
params[:full_text_ocr] = 'true' if full_text
uri.query = URI.encode_www_form(params)

headers = {
Expand All @@ -127,7 +128,6 @@ def predict_req_post(input_source, all_words: false, full_text: false, close_fil
[input_source.read_document(close: close_file)]
end
form_data.push ['include_mvision', 'true'] if all_words
form_data.push ['full_text_ocr', 'true'] if full_text

req.set_form(form_data, 'multipart/form-data')
response = nil
Expand All @@ -148,6 +148,7 @@ def document_queue_req_get(input_source, all_words, full_text, close_file, cropp

params = {}
params[:cropper] = 'true' if cropper
params[:full_text_ocr] = 'true' if full_text
uri.query = URI.encode_www_form(params)

headers = {
Expand All @@ -161,7 +162,6 @@ def document_queue_req_get(input_source, all_words, full_text, close_file, cropp
[input_source.read_document(close: close_file)]
end
form_data.push ['include_mvision', 'true'] if all_words
form_data.push ['full_text_ocr', 'true'] if full_text

req.set_form(form_data, 'multipart/form-data')

Expand Down Expand Up @@ -202,9 +202,9 @@ def check_api_key
return unless @api_key.nil? || @api_key.empty?

raise "Missing API key for product \"'#{@url_name}' v#{@version}\" (belonging to \"#{@owner}\"), " \
"check your Client Configuration.\n" \
'You can set this using the ' \
"'#{HTTP::API_KEY_ENV_NAME}' environment variable."
"check your Client Configuration.\n" \
'You can set this using the ' \
"'#{HTTP::API_KEY_ENV_NAME}' environment variable."
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def initialize(prediction, page_id)
@country_of_issue = StringField.new(prediction['country_of_issue'], page_id)
@document_number = StringField.new(prediction['document_number'], page_id)
@document_type = ClassificationField.new(prediction['document_type'], page_id)
puts prediction['expiry_date']
@expiry_date = DateField.new(prediction['expiry_date'], page_id)
@given_names = []
prediction['given_names'].each do |item|
Expand Down
2 changes: 1 addition & 1 deletion spec/extras/cropper_extra_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'mindee'
require_relative 'extras_utils'

describe 'cropper extra do' do
describe 'cropper extra' do
let(:cropper_dir) do
File.join(EXTRAS_DIR, 'cropper')
end
Expand Down
35 changes: 35 additions & 0 deletions spec/extras/extras_integration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require 'json'
require 'mindee'
require_relative 'extras_utils'
require_relative '../data'
require_relative '../test_utilities'

describe 'cropper extra' do
let(:invoice_path) { File.join(DATA_DIR, 'products', 'invoices', 'default_sample.jpg') }
let(:client) { Mindee::Client.new }
it 'should send correctly' do
cropper_extra = Mindee::Input::Source::PathInputSource.new(
File.join(invoice_path)
)
cropper_result = client.parse(cropper_extra, Mindee::Product::Invoice::InvoiceV4, cropper: true)
expect(cropper_result.document.inference.pages[0].extras.cropper).to_not be_nil
end
end

describe 'Full Text OCR extra' do
let(:invoice_path) { File.join(DATA_DIR, 'products', 'invoices', 'default_sample.jpg') }
let(:client) { Mindee::Client.new }
it 'should send correctly' do
full_text_ocr_input = Mindee::Input::Source::PathInputSource.new(
File.join(invoice_path)
)
full_text_ocr_result = client.enqueue_and_parse(
full_text_ocr_input,
Mindee::Product::InternationalId::InternationalIdV2,
full_text: true
)
expect(full_text_ocr_result.document.extras.full_text_ocr).to_not be_nil
end
end

0 comments on commit 6f70d21

Please sign in to comment.