def test_deleted_relationships(db, dummy_event): event = dummy_event assert not event.contributions assert not event.sessions s = Session(event=event, title='s') sd = Session(event=event, title='sd', is_deleted=True) c = Contribution(event=event, title='c', session=sd, duration=timedelta(minutes=30)) cd = Contribution(event=event, title='cd', session=sd, duration=timedelta(minutes=30), is_deleted=True) sc = SubContribution(contribution=c, title='sc', duration=timedelta(minutes=10)) scd = SubContribution(contribution=c, title='scd', duration=timedelta(minutes=10), is_deleted=True) db.session.flush() db.session.expire_all() # reload all the objects from the db event = Event.get(event.id) s = Session.get(s.id) sd = Session.get(sd.id) c = Contribution.get(c.id) cd = Contribution.get(cd.id) sc = SubContribution.get(sc.id) scd = SubContribution.get(scd.id) # deleted items should not be in the lists assert event.sessions == [s] assert event.contributions == [c] assert sd.contributions == [c] assert c.subcontributions == [sc] # the other direction should work fine even in case of deletion assert s.event == event assert sd.event == event assert c.event == event assert cd.event == event assert sc.contribution == c assert scd.contribution == c
def test_deleted_relationships(db, dummy_event_new): event = dummy_event_new assert not event.contributions assert not event.sessions s = Session(event_new=event, title='s') sd = Session(event_new=event, title='sd', is_deleted=True) c = Contribution(event_new=event, title='c', session=sd, duration=timedelta(minutes=30)) cd = Contribution(event_new=event, title='cd', session=sd, duration=timedelta(minutes=30), is_deleted=True) sc = SubContribution(contribution=c, title='sc', duration=timedelta(minutes=10)) scd = SubContribution(contribution=c, title='scd', duration=timedelta(minutes=10), is_deleted=True) db.session.flush() db.session.expire_all() # reload all the objects from the db event = Event.get(event.id) s = Session.get(s.id) sd = Session.get(sd.id) c = Contribution.get(c.id) cd = Contribution.get(cd.id) sc = SubContribution.get(sc.id) scd = SubContribution.get(scd.id) # deleted items should not be in the lists assert event.sessions == [s] assert event.contributions == [c] assert sd.contributions == [c] assert c.subcontributions == [sc] # the other direction should work fine even in case of deletion assert s.event_new == event assert sd.event_new == event assert c.event_new == event assert cd.event_new == event assert sc.contribution == c assert scd.contribution == c
def _clone_sessions(self, new_event): attrs = get_simple_column_attrs(Session) | {'own_room', 'own_venue'} query = (Session.query.with_parent(self.old_event) .options(joinedload('blocks'), joinedload('own_venue'), joinedload('own_room').lazyload('*'), subqueryload('acl_entries'))) for old_sess in query: sess = Session() sess.populate_from_attrs(old_sess, attrs) sess.blocks = list(self._clone_session_blocks(old_sess.blocks)) sess.acl_entries = clone_principals(SessionPrincipal, old_sess.acl_entries) new_event.sessions.append(sess) self._session_map[old_sess] = sess
def test_event_export(db, dummy_event, monkeypatch): monkeypatch.setattr('indico.modules.events.export.now_utc', lambda: as_utc(datetime(2017, 8, 24, 9, 0, 0))) f = BytesIO() dummy_event.created_dt = as_utc(datetime(2017, 8, 24, 0, 0, 0)) dummy_event.start_dt = as_utc(datetime(2017, 8, 24, 10, 0, 0)) dummy_event.end_dt = as_utc(datetime(2017, 8, 24, 12, 0, 0)) s = Session(event=dummy_event, title='sd', is_deleted=True) Contribution(event=dummy_event, title='c1', duration=timedelta(minutes=30)) Contribution(event=dummy_event, title='c2', session=s, duration=timedelta(minutes=30), is_deleted=True) db.session.flush() export_event(dummy_event, f) f.seek(0) with open(os.path.join(os.path.dirname(__file__), 'export_test_1.yaml'), 'r') as ref_file: data_yaml_content = ref_file.read() # check composition of tarfile and data.yaml content with tarfile.open(fileobj=f) as tarf: assert tarf.getnames() == ['data.yaml'] assert tarf.extractfile('data.yaml').read() == data_yaml_content
def test_event_attachment_export(db, dummy_event, dummy_attachment): s = Session(event=dummy_event, title='sd', is_deleted=True) Contribution(event=dummy_event, title='c1', duration=timedelta(minutes=30)) Contribution(event=dummy_event, title='c2', session=s, duration=timedelta(minutes=30), is_deleted=True) dummy_attachment.folder.event = dummy_event dummy_attachment.folder.linked_event = dummy_event dummy_attachment.folder.link_type = LinkType.event dummy_attachment.file.save(BytesIO(b'hello world')) db.session.flush() f = BytesIO() export_event(dummy_event, f) f.seek(0) with tarfile.open(fileobj=f) as tarf: data_file = tarf.extractfile('data.yaml') data = yaml.unsafe_load(data_file) objs = data['objects'] event_uid = objs[0][1]['id'][1] # check that the exported metadata contains all the right objects assert [obj[0] for obj in objs] == [ u'events.events', u'events.sessions', u'events.contributions', u'events.contributions', u'attachments.folders', u'attachments.attachments', u'attachments.files' ] # check that the attached file's metadata is included assert objs[5][1]['title'] == 'dummy_attachment' assert objs[5][1]['folder_id'] is not None assert objs[4][1]['title'] == 'dummy_folder' assert objs[4][1]['linked_event_id'][1] == event_uid file_ = objs[6][1]['__file__'][1] assert file_['filename'] == 'dummy_file.txt' assert file_['content_type'] == 'text/plain' assert file_['size'] == 11 assert file_['md5'] == '5eb63bbbe01eeed093cb22bb8f5acdc3' # check that the file itself was included (and verify content) assert tarf.getnames() == [ '00000000-0000-4000-8000-000000000013', 'data.yaml' ] assert tarf.extractfile( '00000000-0000-4000-8000-000000000013').read() == 'hello world'
def _clone_sessions(self, new_event): attrs = get_simple_column_attrs(Session) | {'own_room', 'own_venue'} query = (Session.query.with_parent(self.old_event).options( joinedload('blocks'), joinedload('own_venue'), joinedload('own_room').lazyload('*'), subqueryload('acl_entries'))) for old_sess in query: sess = Session() sess.populate_from_attrs(old_sess, attrs) sess.blocks = list(self._clone_session_blocks(old_sess.blocks)) sess.acl_entries = clone_principals(SessionPrincipal, old_sess.acl_entries) new_event.sessions.append(sess) self._session_map[old_sess] = sess