mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 21:16:12 +02:00
added test
This commit is contained in:
parent
0d40feb9c0
commit
7c8c9120b5
5 changed files with 107 additions and 8 deletions
|
@ -1,19 +1,17 @@
|
||||||
class ScanCsvRegistryBusinnesContactsJob < ApplicationJob
|
class ScanCsvRegistryBusinnesContactsJob < ApplicationJob
|
||||||
FILE_NAME = './ettevotja_rekvisiidid_init.csv'.freeze
|
def perform(filename)
|
||||||
|
|
||||||
def perform
|
|
||||||
BusinessRegistryContact.delete_all
|
BusinessRegistryContact.delete_all
|
||||||
|
|
||||||
return p 'File not exist!' unless File.exist?(FILE_NAME)
|
return p 'File not exist!' unless File.exist?(filename)
|
||||||
|
|
||||||
enumurate_csv_file
|
enumurate_csv_file(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def enumurate_csv_file
|
def enumurate_csv_file(filename)
|
||||||
i = 0
|
i = 0
|
||||||
CSV.foreach(FILE_NAME, headers: true, col_sep: ';') do |row|
|
CSV.foreach(filename, headers: true, col_sep: ';') do |row|
|
||||||
record = BusinessRegistryContact.create(
|
record = BusinessRegistryContact.create(
|
||||||
name: row[0],
|
name: row[0],
|
||||||
registry_code: row[1],
|
registry_code: row[1],
|
||||||
|
|
78
lib/tasks/collect_invalid_validation_business_contacts.rake
Normal file
78
lib/tasks/collect_invalid_validation_business_contacts.rake
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
namespace :collect_invalid_contacts do
|
||||||
|
desc 'Starts collect invalid validation contacts'
|
||||||
|
task all_domains: :environment do
|
||||||
|
# prepare_csv_file
|
||||||
|
|
||||||
|
Contact.all.each do |contact|
|
||||||
|
# email = convert_to_unicode(contact.email)
|
||||||
|
# result = Truemail.validate(email, with: :mx)
|
||||||
|
|
||||||
|
# collect_data_for_csv(contact, result.result) unless result.result.success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# def find_related_domains(contact)
|
||||||
|
# registrant_domains = Domain.where(registrant_id: contact.id)
|
||||||
|
|
||||||
|
# tech_domains = collect_tech_domains(contact)
|
||||||
|
# admin_domains = collect_admin_domains(contact)
|
||||||
|
|
||||||
|
# tech_domains | admin_domains | registrant_domains
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def collect_admin_domains(contact)
|
||||||
|
# admin_domains = []
|
||||||
|
|
||||||
|
# admin_contacts = AdminDomainContact.where(contact_id: contact.id)
|
||||||
|
# admin_contacts.each do |c|
|
||||||
|
# admin_domains << Domain.find(c.domain_id)
|
||||||
|
# end
|
||||||
|
|
||||||
|
# admin_domains
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def collect_tech_domains(contact)
|
||||||
|
# tech_domains = []
|
||||||
|
|
||||||
|
# tech_contacts = TechDomainContact.where(contact_id: contact.id)
|
||||||
|
# tech_contacts.each do |c|
|
||||||
|
# tech_domains << Domain.find(c.domain_id)
|
||||||
|
# end
|
||||||
|
|
||||||
|
# tech_domains
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def collect_data_for_csv(contact, result)
|
||||||
|
# domains = find_related_domains(contact)
|
||||||
|
# domains.reject! { |dom| dom.statuses.include? DomainStatus::FORCE_DELETE }
|
||||||
|
|
||||||
|
# CSV.open('invalid_emails.csv', 'a') do |csv|
|
||||||
|
# domains.each do |domain|
|
||||||
|
# attrs = []
|
||||||
|
# attrs.push(domain.name, contact.email, result.errors)
|
||||||
|
|
||||||
|
# csv << attrs
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def prepare_csv_file
|
||||||
|
# headers = %w[
|
||||||
|
# contact
|
||||||
|
# domain
|
||||||
|
# error
|
||||||
|
# ]
|
||||||
|
# csv = CSV.open('invalid_emails.csv', 'w')
|
||||||
|
# csv << headers
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def convert_to_unicode(email)
|
||||||
|
# original_domain = Mail::Address.new(email).domain
|
||||||
|
# decoded_domain = SimpleIDN.to_unicode(original_domain)
|
||||||
|
|
||||||
|
# original_local = Mail::Address.new(email).local
|
||||||
|
# decoded_local = SimpleIDN.to_unicode(original_local)
|
||||||
|
|
||||||
|
# "#{decoded_local}@#{decoded_domain}"
|
||||||
|
# end
|
|
@ -1,7 +1,9 @@
|
||||||
namespace :collect_csv_data do
|
namespace :collect_csv_data do
|
||||||
desc 'Import from csv registry business contact into BusinessRegistryContact model'
|
desc 'Import from csv registry business contact into BusinessRegistryContact model'
|
||||||
|
|
||||||
|
FILE_NAME = './ettevotja_rekvisiidid_init.csv'.freeze
|
||||||
|
|
||||||
task business_contacts: :environment do
|
task business_contacts: :environment do
|
||||||
ScanCsvRegistryBusinnesContactsJob.perform_now
|
ScanCsvRegistryBusinnesContactsJob.perform_later(FILE_NAME)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
10
test/fixtures/files/ette.csv
vendored
Normal file
10
test/fixtures/files/ette.csv
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
nimi;ariregistri_kood;ettevotja_oiguslik_vorm;ettevotja_oigusliku_vormi_alaliik;kmkr_nr;ettevotja_staatus;ettevotja_staatus_tekstina;ettevotja_esmakande_kpv;ettevotja_aadress;asukoht_ettevotja_aadressis;asukoha_ehak_kood;asukoha_ehak_tekstina;indeks_ettevotja_aadressis;ads_adr_id;ads_ads_oid;ads_normaliseeritud_taisaadress;teabesysteemi_link
|
||||||
|
001 group OÜ;12754230;Osaühing;;;R;Registrisse kantud;17.11.2014;;Õismäe tee 78-9;0176;Haabersti linnaosa, Tallinn, Harju maakond;13513;2182337;;Harju maakond, Tallinn, Haabersti linnaosa, Õismäe tee 78-9;https://ariregister.rik.ee/ettevotja.py?ark=12754230&ref=rekvisiidid
|
||||||
|
001 Kinnisvara OÜ;12652512;Osaühing;;EE101721589;R;Registrisse kantud;25.04.2014;;Õismäe tee 78-9;0176;Haabersti linnaosa, Tallinn, Harju maakond;13513;2182337;;Harju maakond, Tallinn, Haabersti linnaosa, Õismäe tee 78-9;https://ariregister.rik.ee/ettevotja.py?ark=12652512&ref=rekvisiidid
|
||||||
|
007 Autohaus osaühing;11694365;Osaühing;;EE101335276;R;Registrisse kantud;30.07.2009;;;;;;;;;https://ariregister.rik.ee/ettevotja.py?ark=11694365&ref=rekvisiidid
|
||||||
|
013 investment OÜ;12937781;Osaühing;;;R;Registrisse kantud;29.10.2015;;Tartu mnt 18;0298;Kesklinna linnaosa, Tallinn, Harju maakond;10145;2311081;;Harju maakond, Tallinn, Kesklinna linnaosa, Tartu mnt 18;https://ariregister.rik.ee/ettevotja.py?ark=12937781&ref=rekvisiidid
|
||||||
|
01Arvutiabi OÜ;14112620;Osaühing;;;R;Registrisse kantud;13.09.2016;;Aru tn 19-5;0614;Põhja-Tallinna linnaosa, Tallinn, Harju maakond;10318;2283769;;Harju maakond, Tallinn, Põhja-Tallinna linnaosa, Aru tn 19-5;https://ariregister.rik.ee/ettevotja.py?ark=14112620&ref=rekvisiidid
|
||||||
|
01 Creations Osaühing;10818150;Osaühing;;;R;Registrisse kantud;21.11.2001;;Ahtri tn 12;0298;Kesklinna linnaosa, Tallinn, Harju maakond;10151;2113048;;Harju maakond, Tallinn, Kesklinna linnaosa, Ahtri tn 12;https://ariregister.rik.ee/ettevotja.py?ark=10818150&ref=rekvisiidid
|
||||||
|
020 EHITUS OÜ;16035029;Osaühing;;EE102307287;R;Registrisse kantud;24.08.2020;;Harju maakond, Tallinn, Kristiine linnaosa, A. H. Tammsaare tee 47;0339;Kristiine linnaosa, Tallinn, Harju maakond;11316;2216417;;Harju maakond, Tallinn, Kristiine linnaosa, A. H. Tammsaare tee 47;https://ariregister.rik.ee/ettevotja.py?ark=16035029&ref=rekvisiidid
|
||||||
|
02JDM OÜ;16240491;Osaühing;;;R;Registrisse kantud;28.05.2021;;Mustamäe tee 106-20;0482;Mustamäe linnaosa, Tallinn, Harju maakond;12917;2311996;;Harju maakond, Tallinn, Mustamäe linnaosa, Mustamäe tee 106-20;https://ariregister.rik.ee/ettevotja.py?ark=16240491&ref=rekvisiidid
|
||||||
|
0dav riie OÜ;14288602;Osaühing;;;R;Registrisse kantud;04.07.2017;;Vanaaseme;2087;Ingliste küla, Kehtna vald, Rapla maakond;79004;3201213;;Rapla maakond, Kehtna vald, Ingliste küla, Vanaaseme;https://ariregister.rik.ee/ettevotja.py?ark=14288602&ref=rekvisiidid
|
|
11
test/jobs/scan_csv_registry_businnes_contacts_job_test.rb
Normal file
11
test/jobs/scan_csv_registry_businnes_contacts_job_test.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ScanCsvRegistryBusinnesContactsJobTest < ActiveJob::TestCase
|
||||||
|
def test_delivers_email
|
||||||
|
filename = 'test/fixtures/files/ette.csv'
|
||||||
|
|
||||||
|
assert_performed_jobs 1 do
|
||||||
|
ScanCsvRegistryBusinnesContactsJob.perform_later(filename)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue