def fetch_stories(refresh_clients=False): """ fetch userstories from pivotaltracker and add some information into the database. """ redis.flushdb() request = PivotalRequest() pipe = redis.pipeline(transaction=True) for iteration in request.iter_iterations(): iteration_id = iteration['id'] Iteration.create(iteration, pipe=pipe) app.logger.info('Processing iteration: %s', iteration_id) for story in request.iter_stories(iteration['stories']): story_id = story['id'] Story.create(story, pipe=pipe) Iteration.add_story(iteration_id, story_id, pipe=pipe) app.logger.info(story_id) app.logger.info('retrieve stories in the icebox') for story in request.iter_icebox(): story_id = story['id'] Story.create(story, pipe=pipe) app.logger.info(story_id) pipe.execute() if refresh_clients: from wafwfy.events import refresh_clients as refresh_clients_fun refresh_clients_fun()
def test_iter_icebox(self): self.assertEqual(len(list(Story.iter_icebox())), 0) self.create_story(id_=20, status="unscheduled") self.create_story(id_=21, status="unscheduled") self.create_story(id_=22, status="unscheduled") self.assertEqual(len(list(Story.iter_icebox())), 3)
def test_count_icebox(self): self.assertEqual(Story.count_icebox(), 0) self.create_story(id_=20, status="unscheduled") self.create_story(id_=21, status="unscheduled") self.create_story(id_=22, status="unscheduled") self.assertEqual(Story.count_icebox(), 3)
def tags(): from wafwfy.models import Story from collections import defaultdict stories = Story.all() tags = defaultdict(list) for story in stories: for label in story.get('labels', []): tags[label].append(story) return jsonify(objects=tags)
def tags_count(): from wafwfy.models import Story from collections import defaultdict stories = Story.all() # build a mapping tag -> id of the epic epics = app.config.get('EPICS') tag_to_id = {} for cnt, epic_label in enumerate(epics): for tag in epics[epic_label]: tag_to_id[tag] = cnt tags = defaultdict(lambda:defaultdict(lambda: 0)) for story in stories: for label in story.get('labels', []): if label not in tag_to_id: continue tags[tag_to_id[label]][story['current_state']] += \ story.get('estimate', 0.5) return jsonify(objects=tags)
def story_current(): from wafwfy.models import Story stories = Story.current() return jsonify(objects=list(stories))
def story(): from wafwfy.models import Story stories = Story.all() return jsonify(objects=list(stories))
def create_story(id_=27, status='accepted'): Story.create(dict( id=id_, current_state=status, ))