otrs_import_test.rb 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. # encoding: utf-8
  2. require 'integration_test_helper'
  3. class OtrsImportTest < ActiveSupport::TestCase
  4. if !ENV['IMPORT_OTRS_ENDPOINT']
  5. raise "ERROR: Need IMPORT_OTRS_ENDPOINT - hint IMPORT_OTRS_ENDPOINT='http://vz305.demo.znuny.com/otrs/public.pl?Action=ZammadMigrator'"
  6. end
  7. if !ENV['IMPORT_OTRS_ENDPOINT_KEY']
  8. raise "ERROR: Need IMPORT_OTRS_ENDPOINT_KEY - hint IMPORT_OTRS_ENDPOINT_KEY='01234567899876543210'"
  9. end
  10. Setting.set('import_otrs_endpoint', ENV['IMPORT_OTRS_ENDPOINT'])
  11. Setting.set('import_otrs_endpoint_key', ENV['IMPORT_OTRS_ENDPOINT_KEY'])
  12. Setting.set('import_mode', true)
  13. Import::OTRS.start
  14. # check settings items
  15. test 'check settings' do
  16. http = nil
  17. system_id = nil
  18. fqdn = nil
  19. if ENV['IMPORT_OTRS_ENDPOINT'] =~ %r{^(http|https)://((.+?)\..+?)/}
  20. http = $1
  21. fqdn = $2
  22. system_id = $3
  23. system_id.gsub!(/[A-z]/, '') # strip chars
  24. end
  25. assert_equal( system_id, Setting.get('system_id'), 'system_id' )
  26. assert_equal( fqdn, Setting.get('fqdn'), 'fqdn' )
  27. assert_equal( http, Setting.get('http_type'), 'http_type' )
  28. assert_equal( 'Example Company', Setting.get('organization'), 'organization' )
  29. end
  30. test 'check dynamic fields' do
  31. local_objects = ObjectManager::Attribute.list_full
  32. object_attribute_names = local_objects.reject { |local_object|
  33. local_object[:object] != 'Ticket'
  34. }.collect { |local_object|
  35. local_object['name']
  36. }
  37. expected_object_attribute_names = %w(vertriebsweg te_test sugar_crm_remote_no sugar_crm_company_selected_no sugar_crm_company_selection combine itsm_criticality customer_id itsm_impact itsm_review_required itsm_decision_result itsm_repair_start_time itsm_recovery_start_time itsm_decision_date title itsm_due_date topic_no open_exchange_ticket_number hostname ticket_free_key11 type ticket_free_text11 open_exchange_tn topic zarafa_tn group_id scom_hostname checkbox_example scom_uuid scom_state scom_service location owner_id department customer_location state_id pending_time priority_id tags)
  38. assert_equal(expected_object_attribute_names, object_attribute_names, 'dynamic field names')
  39. end
  40. # check count of imported items
  41. test 'check counts' do
  42. assert_equal( 603, Ticket.count, 'tickets' )
  43. assert_equal( 3182, Ticket::Article.count, 'ticket articles' )
  44. assert_equal( 274, Store.count, 'ticket article attachments' )
  45. assert_equal( 10, Ticket::State.count, 'ticket states' )
  46. assert_equal( 24, Group.count, 'groups' )
  47. end
  48. # check imported users and permission
  49. test 'check users' do
  50. role_admin = Role.where( name: 'Admin' ).first
  51. role_agent = Role.where( name: 'Agent' ).first
  52. role_customer = Role.where( name: 'Customer' ).first
  53. #role_report = Role.where( :name => 'Report' ).first
  54. user1 = User.find(2)
  55. assert_equal( 'agent-1 firstname', user1.firstname )
  56. assert_equal( 'agent-1 lastname', user1.lastname )
  57. assert_equal( 'agent-1', user1.login )
  58. assert_equal( 'agent-1@example.com', user1.email )
  59. assert_equal( true, user1.active )
  60. assert( user1.roles.include?( role_agent ) )
  61. assert( !user1.roles.include?( role_admin ) )
  62. assert( !user1.roles.include?( role_customer ) )
  63. #assert( !user1.roles.include?( role_report ) )
  64. group_dasa = Group.where( name: 'dasa' ).first
  65. group_raw = Group.where( name: 'Raw' ).first
  66. assert( !user1.groups.include?( group_dasa ) )
  67. assert( user1.groups.include?( group_raw ) )
  68. user2 = User.find(3)
  69. assert_equal( 'agent-2 firstname äöüß', user2.firstname )
  70. assert_equal( 'agent-2 lastname äöüß', user2.lastname )
  71. assert_equal( 'agent-2', user2.login )
  72. assert_equal( 'agent-2@example.com', user2.email )
  73. assert_equal( true, user2.active )
  74. assert( user2.roles.include?( role_agent ) )
  75. assert( user2.roles.include?( role_admin ) )
  76. assert( !user2.roles.include?( role_customer ) )
  77. #assert( user2.roles.include?( role_report ) )
  78. assert( user2.groups.include?( group_dasa ) )
  79. assert( user2.groups.include?( group_raw ) )
  80. user3 = User.find(7)
  81. assert_equal( 'invalid', user3.firstname )
  82. assert_equal( 'invalid', user3.lastname )
  83. assert_equal( 'invalid', user3.login )
  84. assert_equal( 'invalid@example.com', user3.email )
  85. assert_equal( false, user3.active )
  86. assert( user3.roles.include?( role_agent ) )
  87. assert( !user3.roles.include?( role_admin ) )
  88. assert( !user3.roles.include?( role_customer ) )
  89. #assert( user3.roles.include?( role_report ) )
  90. assert( !user3.groups.include?( group_dasa ) )
  91. assert( !user3.groups.include?( group_raw ) )
  92. user4 = User.find(8)
  93. assert_equal( 'invalid-temp', user4.firstname )
  94. assert_equal( 'invalid-temp', user4.lastname )
  95. assert_equal( 'invalid-temp', user4.login )
  96. assert_equal( 'invalid-temp@example.com', user4.email )
  97. assert_equal( false, user4.active )
  98. assert( user4.roles.include?( role_agent ) )
  99. assert( !user4.roles.include?( role_admin ) )
  100. assert( !user4.roles.include?( role_customer ) )
  101. #assert( user4.roles.include?( role_report ) )
  102. assert( !user4.groups.include?( group_dasa ) )
  103. assert( !user4.groups.include?( group_raw ) )
  104. end
  105. # check all synced states and state types
  106. test 'check ticket stats' do
  107. state = Ticket::State.find(1)
  108. assert_equal( 'new', state.name )
  109. assert_equal( 'new', state.state_type.name )
  110. state = Ticket::State.find(2)
  111. assert_equal( 'closed successful', state.name )
  112. assert_equal( 'closed', state.state_type.name )
  113. state = Ticket::State.find(6)
  114. assert_equal( 'pending reminder', state.name )
  115. assert_equal( 'pending reminder', state.state_type.name )
  116. end
  117. # check groups/queues
  118. test 'check groups' do
  119. group1 = Group.find(1)
  120. assert_equal( 'Postmaster', group1.name )
  121. assert_equal( true, group1.active )
  122. group2 = Group.find(19)
  123. assert_equal( 'UnitTestQueue20668', group2.name )
  124. assert_equal( false, group2.active )
  125. end
  126. # check imported customers and organization relation
  127. test 'check customers / organizations' do
  128. user1 = User.where( login: 'jn' ).first
  129. assert_equal( 'Johannes', user1.firstname )
  130. assert_equal( 'Nickel', user1.lastname )
  131. assert_equal( 'jn', user1.login )
  132. assert_equal( 'jn@example.com', user1.email )
  133. organization1 = user1.organization
  134. assert_equal( 'Znuny GmbH Berlin', organization1.name )
  135. assert_equal( 'äöüß', organization1.note )
  136. user2 = User.where( login: 'test90133' ).first
  137. assert_equal( 'test90133', user2.firstname )
  138. assert_equal( 'test90133', user2.lastname )
  139. assert_equal( 'test90133', user2.login )
  140. assert_equal( 'qa4711@t-online.de', user2.email )
  141. organization2 = user2.organization
  142. assert( organization2, nil )
  143. end
  144. # check imported tickets
  145. test 'check tickets' do
  146. # ticket is open
  147. ticket = Ticket.find(728)
  148. assert_equal( 'test #1', ticket.title )
  149. assert_equal( 'open', ticket.state.name )
  150. assert_equal( 'Misc', ticket.group.name )
  151. assert_equal( '4 high', ticket.priority.name )
  152. assert_equal( 'agent-2', ticket.owner.login )
  153. assert_equal( 'partner', ticket.customer.login )
  154. assert_equal( 'Partner der betreut', ticket.organization.name )
  155. assert_equal( Time.zone.parse('2014-11-20 22:33:41 +0000').gmtime.to_s, ticket.created_at.to_s )
  156. assert_equal( nil, ticket.close_at )
  157. # check history
  158. # - create entry
  159. # ticket is created with state closed
  160. ticket = Ticket.find(729)
  161. assert_equal( 'test #2', ticket.title )
  162. assert_equal( 'closed successful', ticket.state.name )
  163. assert_equal( 'Raw', ticket.group.name )
  164. assert_equal( '3 normal', ticket.priority.name )
  165. assert_equal( 'agent-2', ticket.owner.login )
  166. assert_equal( 'jn2', ticket.customer.login )
  167. assert_equal( 'Znuny GmbH', ticket.organization.name )
  168. assert_equal( Time.zone.parse('2014-11-20 23:24:20 +0000').gmtime.to_s, ticket.created_at.to_s )
  169. assert_equal( Time.zone.parse('2014-11-20 23:24:20 +0000').gmtime.to_s, ticket.close_at.to_s )
  170. # check history
  171. # - create entry
  172. # ticket is created open and now closed
  173. ticket = Ticket.find(730)
  174. assert_equal( 'test #3', ticket.title )
  175. assert_equal( 'closed successful', ticket.state.name )
  176. assert_equal( 'Postmaster', ticket.group.name )
  177. assert_equal( '3 normal', ticket.priority.name )
  178. assert_equal( 'agent-2', ticket.owner.login )
  179. assert_equal( 'betreuterkunde2', ticket.customer.login )
  180. assert_equal( 'Noch ein betreuter Kunde', ticket.organization.name )
  181. assert_equal( Time.zone.parse('2014-11-21 00:17:40 +0000').gmtime.to_s, ticket.created_at.to_s )
  182. assert_equal( Time.zone.parse('2014-11-21 00:21:08 +0000').gmtime.to_s, ticket.close_at.to_s )
  183. # ticket dynamic fields
  184. ticket = Ticket.find(591)
  185. assert_equal( 'Some other smart subject!', ticket.title )
  186. assert_equal( '488', ticket.vertriebsweg )
  187. assert_equal( '["193"]', ticket.te_test ) # TODO: multiselect
  188. assert_equal( '358', ticket.sugar_crm_remote_no )
  189. assert_equal( '69', ticket.sugar_crm_company_selected_no )
  190. assert_equal( '["382"]', ticket.sugar_crm_company_selection ) # TODO: multiselect
  191. assert_equal( '310', ticket.topic_no )
  192. assert_equal( '495', ticket.open_exchange_ticket_number )
  193. assert_equal( '208', ticket.hostname )
  194. # check history
  195. # - create entry
  196. # - state change entry
  197. end
  198. test 'check article attachments' do
  199. article = Ticket::Article.find(149)
  200. assert_equal( 5, article.attachments.count )
  201. attachment = article.attachments.first
  202. assert_equal( 'image/jpeg', attachment[:preferences]['Mime-Type'] )
  203. assert_equal( 'Cursor_und_Banners_and_Alerts_und_Paket-Verwaltung_-_Admin_-_otrs336_und_otrs336.jpg', attachment.filename )
  204. article = Ticket::Article.find(156)
  205. assert_equal( 2, article.attachments.count )
  206. attachment = article.attachments.second
  207. assert_equal( 'application/pdf; name="=?UTF-8?B?5ZSQ6K+X5LiJ55m+6aaWLnBkZg==?="', attachment[:preferences]['Mime-Type'] )
  208. assert_equal( '唐诗三百首.pdf', attachment.filename )
  209. end
  210. end