|
15 | 15 | SetComments, SetAuthors, Announce, ConfirmAuthorship, ConfirmPolicy, \ |
16 | 16 | SetUploadPackage |
17 | 17 | from .. import init_app, create_all, drop_all, models, DBEvent, \ |
18 | | - get_submission, current_session, get_licenses, exceptions, store_event, \ |
19 | | - transaction |
| 18 | + get_submission, get_user_submissions_fast, current_session, get_licenses, \ |
| 19 | + exceptions, store_event, transaction |
20 | 20 |
|
21 | 21 | from .util import in_memory_db |
22 | 22 |
|
@@ -157,3 +157,92 @@ def test_get_submission_with_hold_and_reclass(self): |
157 | 157 | self.assertTrue(submission_loaded.is_on_hold, |
158 | 158 | "Hold status should reflect hold action performed" |
159 | 159 | " outside the purview of the event model.") |
| 160 | + |
| 161 | + def test_get_submission_list(self): |
| 162 | + """Test that the set of submissions for a user can be retrieved.""" |
| 163 | + user = User( 42, '[email protected]', |
| 164 | + endorsements=['astro-ph.GA', 'astro-ph.EP']) |
| 165 | + events1 = [ |
| 166 | + # first submission |
| 167 | + CreateSubmission(creator=user), |
| 168 | + SetTitle(creator=user, title='Foo title'), |
| 169 | + SetAbstract(creator=user, abstract='Indeed' * 20), |
| 170 | + SetAuthors(creator=user, authors=[ |
| 171 | + Author(order=0, forename='Arthur', surname='Dent', |
| 172 | + |
| 173 | + Author(order=1, forename='Ford', surname='Prefect', |
| 174 | + |
| 175 | + ]), |
| 176 | + SetLicense(creator=user, license_uri='http://creativecommons.org/publicdomain/zero/1.0/', |
| 177 | + license_name='Foo zero 1.0'), |
| 178 | + SetPrimaryClassification(creator=user, category='astro-ph.GA'), |
| 179 | + ConfirmPolicy(creator=user), |
| 180 | + SetUploadPackage(creator=user, identifier='1'), |
| 181 | + ConfirmContactInformation(creator=user), |
| 182 | + FinalizeSubmission(creator=user) |
| 183 | + ] |
| 184 | + events2 = [ |
| 185 | + # second submission |
| 186 | + CreateSubmission(creator=user), |
| 187 | + SetTitle(creator=user, title='Bar title'), |
| 188 | + SetAbstract(creator=user, abstract='Indubitably' * 20), |
| 189 | + SetAuthors(creator=user, authors=[ |
| 190 | + Author(order=0, forename='Jane', surname='Doe', |
| 191 | + |
| 192 | + Author(order=1, forename='John', surname='Doe', |
| 193 | + |
| 194 | + ]), |
| 195 | + SetLicense(creator=user, license_uri='http://creativecommons.org/publicdomain/zero/1.0/', |
| 196 | + license_name='Foo zero 1.0'), |
| 197 | + SetPrimaryClassification(creator=user, category='astro-ph.GA'), |
| 198 | + ConfirmPolicy(creator=user), |
| 199 | + SetUploadPackage(creator=user, identifier='1'), |
| 200 | + ConfirmContactInformation(creator=user), |
| 201 | + FinalizeSubmission(creator=user) |
| 202 | + ] |
| 203 | + |
| 204 | + with in_memory_db(): |
| 205 | + # User creates and finalizes submission. |
| 206 | + with transaction(): |
| 207 | + before = None |
| 208 | + for i, event in enumerate(list(events1)): |
| 209 | + event.created = datetime.now(UTC) |
| 210 | + after = event.apply(before) |
| 211 | + event, after = store_event(event, before, after) |
| 212 | + events1[i] = event |
| 213 | + before = after |
| 214 | + submission1 = after |
| 215 | + ident1 = submission1.submission_id |
| 216 | + |
| 217 | + before = None |
| 218 | + for i, event in enumerate(list(events2)): |
| 219 | + event.created = datetime.now(UTC) |
| 220 | + after = event.apply(before) |
| 221 | + event, after = store_event(event, before, after) |
| 222 | + events2[i] = event |
| 223 | + before = after |
| 224 | + submission2 = after |
| 225 | + ident2 = submission2.submission_id |
| 226 | + |
| 227 | + classic_sub = models.Submission( |
| 228 | + type='new', |
| 229 | + submitter_id=42) |
| 230 | + session = current_session() |
| 231 | + session.add(classic_sub) |
| 232 | + |
| 233 | + # Now get the submissions for this user. |
| 234 | + submissions = get_user_submissions_fast(42) |
| 235 | + submission_loaded1, _ = get_submission(ident1) |
| 236 | + submission_loaded2, _ = get_submission(ident2) |
| 237 | + |
| 238 | + self.assertEqual(submission1.metadata.title, |
| 239 | + submission_loaded1.metadata.title, |
| 240 | + "Event-derived metadata for submission 1 should be preserved.") |
| 241 | + self.assertEqual(submission2.metadata.title, |
| 242 | + submission_loaded2.metadata.title, |
| 243 | + "Event-derived metadata for submission 2 should be preserved.") |
| 244 | + |
| 245 | + self.assertEqual(len(submissions), |
| 246 | + 2, |
| 247 | + "There should be exactly two NG submissions.") |
| 248 | + |
0 commit comments