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()
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 test_snapshot_bug(self): # data capture, woo fake_stdout = StringIO() # make fake bug b = Bug.create_dummy_with_project() b.title = 'fire-ant' b.save() # snapshot fake bug into fake stdout command = mysite.customs.management.commands.snapshot_public_data.Command( ) command.handle(output=fake_stdout) #now, delete bug... b.delete() # let's see if we can re-import fire-ant! for obj in django.core.serializers.deserialize('json', fake_stdout.getvalue()): obj.save() # testing to see if there are ANY bugs self.assertTrue(Bug.all_bugs.all()) # testing to see if fire-ant is there mysite.search.models.Bug.all_bugs.get(title='fire-ant')
def test_snapshot_bug(self): # data capture, woo fake_stdout = StringIO() # make fake bug b = Bug.create_dummy_with_project() b.title = 'fire-ant' b.save() # snapshot fake bug into fake stdout command = mysite.customs.management.commands.snapshot_public_data.Command() command.handle(output=fake_stdout) #now, delete bug... b.delete() # let's see if we can re-import fire-ant! for obj in django.core.serializers.deserialize('json', fake_stdout.getvalue()): obj.save() # testing to see if there are ANY bugs self.assertTrue(Bug.all_bugs.all()) # testing to see if fire-ant is there mysite.search.models.Bug.all_bugs.get(title='fire-ant')
def decode_datetime(s): return datetime.datetime.strptime(s, '%d-%B-%Y') def create_bug_object_for_remote_bug_id(remote_bug_id): '''Create but don't save a bug.''' remote_bug_url = "http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=%d" % remote_bug_id try: tree = lxml.html.document_fromstring(urllib2.urlopen(remote_bug_url).read()) except urllib2.HTTPError, e: if e.code == 404: return None # otherwise, bubble that crazy error up. raise e bug = Bug() metadata_dict = view_bug_table2dict(tree) bug.submitter_username = '' # FIXME: Find an example of this having a value 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.