def then_item_has_current_date(context): response = get_json_data(context.response) assert "planning_date" in response, 'planning_date field not defined' response_date_time = datetime.strptime(response["planning_date"], DATETIME_FORMAT) assert response_date_time.date() == get_local_end_of_day().date( ), 'Planning Item has not got current date'
def then_coverage_has_current_date(context, index): index = int(index) response = get_json_data(context.response) assert len(response.get('coverages')), 'Coverages are not defined' coverage = response.get('coverages')[index] response_date_time = datetime.strptime(coverage['planning']['scheduled'], DATETIME_FORMAT) assert response_date_time.date() == get_local_end_of_day().date(), 'Coverage is not schedule for current date'
def _duplicate_planning(self, original): new_plan = deepcopy(original) if new_plan.get('expired') and new_plan.get('event_item'): # If the Planning item has expired and is associated with an Event # then we remove the link to the associated Event as the Event would have # been expired also del new_plan['event_item'] for f in ('_id', 'guid', 'lock_user', 'lock_time', 'original_creator', '_planning_schedule' 'lock_session', 'lock_action', '_created', '_updated', '_etag', 'pubstatus', 'expired', 'featured'): new_plan.pop(f, None) new_plan[ITEM_STATE] = WORKFLOW_STATE.DRAFT new_plan['guid'] = generate_guid(type=GUID_NEWSML) planning_datetime = new_plan.get('planning_date') current_date = get_local_end_of_day().date() if planning_datetime.date() < current_date: new_plan['planning_date'] = planning_datetime.replace( day=current_date.day, month=current_date.month, year=current_date.year) for cov in new_plan.get('coverages') or []: cov.pop('assigned_to', None) cov.get('planning', {})['scheduled'] = new_plan.get('planning_date') cov['coverage_id'] = generate_guid(type=GUID_NEWSML) cov['workflow_status'] = WORKFLOW_STATE.DRAFT cov['news_coverage_status'] = {'qcode': 'ncostat:int'} return new_plan
def then_assignment_scheduled_for_end_of_day(context, index): index = int(index) response = get_json_data(context.response) assert len(response.get('coverages')), 'Coverages are not defined' coverage = response.get('coverages')[index] eod = get_local_end_of_day().strftime(DATETIME_FORMAT) assert coverage['planning']['scheduled'] == eod, 'Coverage is not schedule to end of day'
def duplicate_assignment_on_create_archive_rewrite(self, items): """Duplicates the coverage/assignment for the archive rewrite If any errors occur at this point in time, the rewrite is still created with an error notification shown in the browser. """ archive_service = get_resource_service('archive') delivery_service = get_resource_service('delivery') planning_service = get_resource_service('planning') assignment_link_service = get_resource_service('assignments_link') for doc in items: item = archive_service.find_one(req=None, _id=doc.get(config.ID_FIELD)) original_item = archive_service.find_one( req=None, _id=item.get('rewrite_of')) # Skip items not linked to an Assignment/Coverage if not original_item.get('assignment_id'): continue assignment = self.find_one(req=None, _id=str(original_item['assignment_id'])) if not assignment: raise SuperdeskApiError.badRequestError( 'Assignment not found.') delivery = delivery_service.find_one( req=None, item_id=original_item[config.ID_FIELD]) if not delivery: raise SuperdeskApiError.badRequestError( 'Delivery record not found.') # Duplicate the coverage, which will generate our new assignment for us updated_plan, new_coverage = planning_service.duplicate_coverage_for_article_rewrite( planning_id=delivery.get('planning_id'), coverage_id=delivery.get('coverage_id'), updates={ 'planning': { 'g2_content_type': item.get('type'), 'slugline': item.get('slugline'), 'scheduled': get_local_end_of_day(), }, 'news_coverage_status': { 'qcode': 'ncostat:int' }, 'assigned_to': { 'user': (item.get('task') or {}).get('user'), 'desk': (item.get('task') or {}).get('desk'), 'state': ASSIGNMENT_WORKFLOW_STATE.IN_PROGRESS, 'priority': DEFAULT_ASSIGNMENT_PRIORITY, } }) new_assignment_id = new_coverage['assigned_to'].get( 'assignment_id') assignment_link_service.post([{ 'assignment_id': str(new_assignment_id), 'item_id': str(item[config.ID_FIELD]), 'reassign': True }])