def test_meeting(self): # Body is mandatory for organization self.converter.import_anything("https://oparl.example.org/body/1") self.converter.ensure_organization_type() meeting = Meeting() data = self.api_data["https://oparl.example.org/meeting/281"] self.converter.meeting(data, meeting) self.assertEqual(meeting.cancelled, False) self.assertEqual( meeting.start, self.utils.parse_datetime("2013-01-04T08:00:00+01:00")) self.assertEqual( meeting.end, self.utils.parse_datetime("2013-01-04T12:00:00+01:00")) self.assertEqual(meeting.location.locality, "Berlin") self.assertEqual(meeting.invitation.filename, "einladung.pdf") self.assertEqual(meeting.results_protocol.filename, "protokoll.pdf") self.assertEqual(meeting.verbatim_protocol.filename, "wortprotokoll.pdf") self.assertEqual(meeting.public, 0) meeting.save() self.converter.meeting_related(data, meeting) self.assertEqual(meeting.organizations.count(), 1) self.assertEqual(meeting.persons.count(), 0) self.assertEqual(meeting.auxiliary_files.count(), 1)
def meeting(self, libobject: JSON, meeting: Meeting) -> Meeting: meeting.start = self.utils.parse_datetime(libobject.get("start")) meeting.end = self.utils.parse_datetime(libobject.get("end")) meeting.location = self.retrieve(Location, libobject.get("location")) meeting.invitation = self.retrieve(File, libobject.get("invitation")) meeting.verbatim_protocol = self.retrieve( File, libobject.get("verbatimProtocol")) meeting.results_protocol = self.retrieve( File, libobject.get("resultsProtocol")) meeting.cancelled = libobject.get("cancelled", False) return meeting
def add_missing_associations(self): logging.info("Adding missing meeting <-> persons associations") for meeting_id, person_ids in self.meeting_person_queue.items(): meeting = Meeting.by_oparl_id(meeting_id) meeting.persons = [ Person.by_oparl_id(person_id) for person_id in person_ids ] meeting.save() logging.info("Adding missing agenda item <-> paper associations") for item_id, paper_id in self.agenda_item_paper_queue.items(): item = AgendaItem.objects_with_deleted.get(oparl_id=item_id) item.paper = Paper.objects_with_deleted.filter( oparl_id=paper_id).first() if not item.paper: message = "Missing Paper: {}, ({})".format(paper_id, item_id) self.errorlist.append(message) item.save() logging.info("Adding missing memberships") for organization, libobject in self.membership_queue: self.membership(organization, libobject) logging.info("Adding missing papper to consultations") for consultation, paper in self.consultation_paper_queue: consultation.paper = Paper.by_oparl_id(paper) consultation.save() logging.info("Adding missing meetings to consultations") for consultation, meeting in self.consultation_meeting_queue: consultation.meeting = Meeting.by_oparl_id(meeting) consultation.save() logging.info("Adding missing organizations to papers") for paper, organization_url in self.paper_organization_queue: paper.organizations.add(Organization.by_oparl_id(organization_url))
def check_basic_import(self): self.new_timestamp = (self.base_timestamp + relativedelta(years=-100)).isoformat() self.create_fake_cache() importer = OParlImport(self.options, self.resolver) importer.run_singlethread() now = timezone.now() for table in self.tables: self.assertEqual(table.objects.count(), 1) self.assertLess(table.objects.first().modified, now) self.assertEqual(File.objects.count(), 2) # Test for #56 self.assertEqual( Meeting.by_oparl_id( "https://oparl.example.org/meeting/281").organizations.count(), 1)
def check_basic_import(self): self.new_timestamp = (self.base_timestamp + relativedelta(years=-100)).isoformat() self.init_mock_loader() importer = Importer(self.loader, force_singlethread=True) importer.run(self.body_id) now = timezone.now() for table, count in self.tables.items(): self.assertEqual( table.objects.count(), count, "{}: {} vs. {}".format(table, count, table.objects.all()), ) self.assertLess(table.objects.first().modified, now) self.assertEqual(File.objects.count(), 6) # Test for #56 self.assertEqual( Meeting.by_oparl_id( "https://oparl.example.org/meeting/281").organizations.count(), 1, )
def add_missing_associations(self): self.logger.info( "Adding {} missing meeting <-> persons associations".format( len(self.meeting_person_queue.items()))) for meeting_id, person_ids in self.meeting_person_queue.items(): meeting = Meeting.by_oparl_id(meeting_id) meeting.persons = [ Person.by_oparl_id(person_id) for person_id in person_ids ] meeting.save() self.logger.info( "Adding {} missing agenda item <-> paper associations".format( len(self.agenda_item_paper_queue.items()))) for item_id, paper_id in self.agenda_item_paper_queue.items(): item = AgendaItem.objects_with_deleted.get(oparl_id=item_id) item.paper = Paper.objects_with_deleted.filter( oparl_id=paper_id).first() if not item.paper: message = "Missing Paper: {}, ({})".format(paper_id, item_id) self.errorlist.append(message) item.save() self.logger.info("Adding {} missing memberships".format( len(self.membership_queue))) for organization, libobject in self.membership_queue: person = Person.objects_with_deleted.filter( oparl_id=libobject.get_person().get_id()).first() if not person: self.logger.warn("The person {} is missing".format( libobject.get_id())) self.person(libobject.get_person()) self.membership(organization, libobject) self.logger.info("Adding {} missing paper to consultations".format( len(self.consultation_paper_queue))) for consultation, paper in self.consultation_paper_queue: consultation.paper = Paper.objects_with_deleted.filter( oparl_id=paper).first() consultation.save() self.logger.info("Adding {} missing meetings to consultations".format( len(self.consultation_meeting_queue))) for consultation, meeting in self.consultation_meeting_queue: consultation.meeting = Meeting.objects_with_deleted.filter( oparl_id=meeting).first() consultation.save() self.logger.info("Adding {} missing organizations to papers".format( len(self.paper_organization_queue))) for paper, organization_url in self.paper_organization_queue: org = Organization.objects_with_deleted.filter( oparl_id=organization_url).first() if not org: org = self.organization_without_embedded( self.client.parse_url(organization_url)) paper.organizations.add(org) self._add_organizations(self.consultation_organization_queue, Consultation) self._add_organizations(self.meeting_organization_queue, Meeting)