@@ -1,176 +1,178 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class IssueImportTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :projects, :enabled_modules, |
|
22 | 22 | :users, :email_addresses, |
|
23 | 23 | :roles, :members, :member_roles, |
|
24 | 24 | :issues, :issue_statuses, |
|
25 | 25 | :trackers, :projects_trackers, |
|
26 | 26 | :versions, |
|
27 | 27 | :issue_categories, |
|
28 | 28 | :enumerations, |
|
29 | 29 | :workflows, |
|
30 | 30 | :custom_fields, |
|
31 | 31 | :custom_values, |
|
32 | 32 | :custom_fields_projects, |
|
33 | 33 | :custom_fields_trackers |
|
34 | 34 | |
|
35 | include Redmine::I18n | |
|
36 | ||
|
35 | 37 | def setup |
|
36 | 38 | set_language_if_valid 'en' |
|
37 | 39 | end |
|
38 | 40 | |
|
39 | 41 | def test_create_versions_should_create_missing_versions |
|
40 | 42 | import = generate_import_with_mapping |
|
41 | 43 | import.mapping.merge!('fixed_version' => '9', 'create_versions' => '1') |
|
42 | 44 | import.save! |
|
43 | 45 | |
|
44 | 46 | version = new_record(Version) do |
|
45 | 47 | assert_difference 'Issue.count', 3 do |
|
46 | 48 | import.run |
|
47 | 49 | end |
|
48 | 50 | end |
|
49 | 51 | assert_equal '2.1', version.name |
|
50 | 52 | end |
|
51 | 53 | |
|
52 | 54 | def test_create_categories_should_create_missing_categories |
|
53 | 55 | import = generate_import_with_mapping |
|
54 | 56 | import.mapping.merge!('category' => '10', 'create_categories' => '1') |
|
55 | 57 | import.save! |
|
56 | 58 | |
|
57 | 59 | category = new_record(IssueCategory) do |
|
58 | 60 | assert_difference 'Issue.count', 3 do |
|
59 | 61 | import.run |
|
60 | 62 | end |
|
61 | 63 | end |
|
62 | 64 | assert_equal 'New category', category.name |
|
63 | 65 | end |
|
64 | 66 | |
|
65 | 67 | def test_mapping_with_fixed_tracker |
|
66 | 68 | import = generate_import_with_mapping |
|
67 | 69 | import.mapping.merge!('tracker' => 'value:2') |
|
68 | 70 | import.save! |
|
69 | 71 | |
|
70 | 72 | issues = new_records(Issue, 3) { import.run } |
|
71 | 73 | assert_equal [2], issues.map(&:tracker_id).uniq |
|
72 | 74 | end |
|
73 | 75 | |
|
74 | 76 | def test_mapping_with_mapped_tracker |
|
75 | 77 | import = generate_import_with_mapping |
|
76 | 78 | import.mapping.merge!('tracker' => '13') |
|
77 | 79 | import.save! |
|
78 | 80 | |
|
79 | 81 | issues = new_records(Issue, 3) { import.run } |
|
80 | 82 | assert_equal [1, 2, 1], issues.map(&:tracker_id) |
|
81 | 83 | end |
|
82 | 84 | |
|
83 | 85 | def test_should_not_import_with_default_tracker_when_tracker_is_invalid |
|
84 | 86 | Tracker.find_by_name('Feature request').update!(:name => 'Feature') |
|
85 | 87 | |
|
86 | 88 | import = generate_import_with_mapping |
|
87 | 89 | import.mapping.merge!('tracker' => '13') |
|
88 | 90 | import.save! |
|
89 | 91 | import.run |
|
90 | 92 | |
|
91 | 93 | assert_equal 1, import.unsaved_items.count |
|
92 | 94 | item = import.unsaved_items.first |
|
93 | 95 | assert_include "Tracker cannot be blank", item.message |
|
94 | 96 | end |
|
95 | 97 | |
|
96 | 98 | def test_status_should_be_set |
|
97 | 99 | import = generate_import_with_mapping |
|
98 | 100 | import.mapping.merge!('status' => '14') |
|
99 | 101 | import.save! |
|
100 | 102 | |
|
101 | 103 | issues = new_records(Issue, 3) { import.run } |
|
102 | 104 | assert_equal ['New', 'New', 'Assigned'], issues.map(&:status).map(&:name) |
|
103 | 105 | end |
|
104 | 106 | |
|
105 | 107 | def test_parent_should_be_set |
|
106 | 108 | import = generate_import_with_mapping |
|
107 | 109 | import.mapping.merge!('parent_issue_id' => '5') |
|
108 | 110 | import.save! |
|
109 | 111 | |
|
110 | 112 | issues = new_records(Issue, 3) { import.run } |
|
111 | 113 | assert_nil issues[0].parent |
|
112 | 114 | assert_equal issues[0].id, issues[1].parent_id |
|
113 | 115 | assert_equal 2, issues[2].parent_id |
|
114 | 116 | end |
|
115 | 117 | |
|
116 | 118 | def test_assignee_should_be_set |
|
117 | 119 | import = generate_import_with_mapping |
|
118 | 120 | import.mapping.merge!('assigned_to' => '11') |
|
119 | 121 | import.save! |
|
120 | 122 | |
|
121 | 123 | issues = new_records(Issue, 3) { import.run } |
|
122 | 124 | assert_equal [User.find(3), nil, nil], issues.map(&:assigned_to) |
|
123 | 125 | end |
|
124 | 126 | |
|
125 | 127 | def test_user_custom_field_should_be_set |
|
126 | 128 | field = IssueCustomField.generate!(:field_format => 'user', :is_for_all => true, :trackers => Tracker.all) |
|
127 | 129 | import = generate_import_with_mapping |
|
128 | 130 | import.mapping.merge!("cf_#{field.id}" => '11') |
|
129 | 131 | import.save! |
|
130 | 132 | |
|
131 | 133 | issues = new_records(Issue, 3) { import.run } |
|
132 | 134 | assert_equal '3', issues.first.custom_field_value(field) |
|
133 | 135 | end |
|
134 | 136 | |
|
135 | 137 | def test_is_private_should_be_set_based_on_user_locale |
|
136 | 138 | import = generate_import_with_mapping |
|
137 | 139 | import.mapping.merge!('is_private' => '6') |
|
138 | 140 | import.save! |
|
139 | 141 | |
|
140 | 142 | issues = new_records(Issue, 3) { import.run } |
|
141 | 143 | assert_equal [false, true, false], issues.map(&:is_private) |
|
142 | 144 | end |
|
143 | 145 | |
|
144 | 146 | def test_dates_should_be_parsed_using_date_format_setting |
|
145 | 147 | field = IssueCustomField.generate!(:field_format => 'date', :is_for_all => true, :trackers => Tracker.all) |
|
146 | 148 | import = generate_import_with_mapping('import_dates.csv') |
|
147 | 149 | import.settings.merge!('date_format' => Import::DATE_FORMATS[1]) |
|
148 | 150 | import.mapping.merge!('tracker' => 'value:1', 'subject' => '0', 'start_date' => '1', 'due_date' => '2', "cf_#{field.id}" => '3') |
|
149 | 151 | import.save! |
|
150 | 152 | |
|
151 | 153 | issue = new_record(Issue) { import.run } # only 1 valid issue |
|
152 | 154 | assert_equal "Valid dates", issue.subject |
|
153 | 155 | assert_equal Date.parse('2015-07-10'), issue.start_date |
|
154 | 156 | assert_equal Date.parse('2015-08-12'), issue.due_date |
|
155 | 157 | assert_equal '2015-07-14', issue.custom_field_value(field) |
|
156 | 158 | end |
|
157 | 159 | |
|
158 | 160 | def test_date_format_should_default_to_user_language |
|
159 | 161 | user = User.generate!(:language => 'fr') |
|
160 | 162 | import = Import.new |
|
161 | 163 | import.user = user |
|
162 | 164 | assert_nil import.settings['date_format'] |
|
163 | 165 | |
|
164 | 166 | import.set_default_settings |
|
165 | 167 | assert_equal '%d/%m/%Y', import.settings['date_format'] |
|
166 | 168 | end |
|
167 | 169 | |
|
168 | 170 | def test_run_should_remove_the_file |
|
169 | 171 | import = generate_import_with_mapping |
|
170 | 172 | file_path = import.filepath |
|
171 | 173 | assert File.exists?(file_path) |
|
172 | 174 | |
|
173 | 175 | import.run |
|
174 | 176 | assert !File.exists?(file_path) |
|
175 | 177 | end |
|
176 | 178 | end |
General Comments 0
You need to be logged in to leave comments.
Login now