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()