def test_regrab_miro_bugs_refreshes_older_bugs_even_when_missing_from_csv(self, mock_csv_maker, mock_xml_opener): mock_xml_opener.return_value = open(os.path.join( settings.MEDIA_ROOT, 'sample-data', 'miro-2294-2009-08-06.xml')) # Situation: Assume there are zero bitesized bugs today. # Desire: We re-get old bugs that don't show up in the CSV. # Prereq: We have some bug with lame data: bug = Bug() bug.people_involved = 1 bug.canonical_bug_link = 'http://bugzilla.pculture.org/show_bug.cgi?id=2294' bug.date_reported = datetime.datetime.now() bug.last_touched = datetime.datetime.now() bug.last_polled = datetime.datetime.now() bug.project, _ = Project.objects.get_or_create(name='Miro') bug.save() # Prepare a fake CSV that is empty mock_csv_maker.return_value = StringIO('') # Now, do a crawl and notice that we updated the bug even though the CSV is empty mysite.customs.miro.grab_miro_bugs() # refreshes no bugs since CSV is empty! all_bugs = Bug.all_bugs.all() self.assertEqual(len(all_bugs), 1) bug = all_bugs[0] self.assertEqual(bug.people_involved, 5)
def bug_update(bug_data): # Get or create a Bug object to put the parsed data in. try: bug = Bug.all_bugs.get( canonical_bug_link=bug_data['canonical_bug_link']) except Bug.DoesNotExist: bug = Bug(canonical_bug_link=bug_data['canonical_bug_link']) # Fill the Bug. for key in bug_data: value = bug_data[key] setattr(bug, key, value) # Save the project onto it. # Project name is just the TrackerModel's tracker_name, as due to the # way Roundup is set up, there is almost always one project per tracker. # This could in theory not be the case, but until we find a Roundup # tracker handling bugs for multiple projects, we will just support one # project per tracker. project_from_name, _ = Project.objects.get_or_create( name=bug_data['tracker'].tracker_name) # Manually save() the Project to ensure that if it was created then it has # a display_name. if not project_from_name.display_name: project_from_name.save() bug.project = project_from_name # Store the tracker that generated the Bug, update last_polled and save it! bug.last_polled = datetime.utcnow() bug.save()
def bug_update(bug_data): # Get or create a Bug object to put the parsed data in. try: bug = Bug.all_bugs.get( canonical_bug_link=bug_data['canonical_bug_link']) except Bug.DoesNotExist: bug = Bug(canonical_bug_link=bug_data['canonical_bug_link']) # Fill the Bug. for key in bug_data: # Filter out any keys starting with _ if key.startswith('_'): continue # Okay, good, it looks like a normal key. Apply it to # the Bug object. value = bug_data[key] setattr(bug, key, value) # Save the project onto it. # Every bug data dictionary comes back with a _project_name key, which # is a way the parsed bug data indicates the project name to use. project_from_name, _ = Project.objects.get_or_create( name=bug_data['_project_name']) # Manually save() the Project to ensure that if it was created then it has # a display_name. if not project_from_name.display_name: project_from_name.save() bug.project = project_from_name # Store the tracker that generated the Bug, update last_polled and save it! bug.last_polled = datetime.utcnow() bug.save()
bug.submitter_realname = '' # FIXME: Find an example of this having a value bug.date_reported = decode_datetime(metadata_dict['Submit Date']) bug.last_touched = decode_datetime(metadata_dict['Last Update Date']) bug.canonical_bug_link = remote_bug_url bug.good_for_newcomers = 'oss-bite-size' in metadata_dict['Keywords'] bug.status = metadata_dict['State'] status_number = int(bug.status.split('-')[0]) bug.looks_closed = (status_number in (8, 10, 11)) bug.title = metadata_dict['Synopsis'] bug.importance = '' # No importance, as far as I can tell. # For description, just grab the first "message" bug.description = metadata_dict['Description'] # We are always the project called Python. bug.project, _ = Project.objects.get_or_create(name='OpenSolaris OS/Net', language='C') # How many people participated? bug.people_involved = None # This tracker has no idea. bug.last_polled = datetime.datetime.utcnow() return bug BUG_URL_PREFIX = 'http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=' def get_remote_bug_ids_to_read(): remote_bug_list = 'http://hub.opensolaris.org/bin/view/Main/oss_bite_size' tree = lxml.html.document_fromstring(urllib2.urlopen(remote_bug_list).read()) for a in tree.cssselect('a'): if BUG_URL_PREFIX in (