def _marshall_group_response(group: DbFeedGroupMetadata): if not group: raise ValueError(group) g = FeedGroupMetadata() g.name = group.name g.last_sync = group.last_sync.isoformat() if group.last_sync else None g.created_at = group.created_at.isoformat() if group.created_at else None g.updated_at = group.last_update.isoformat() if group.last_update else None g.enabled = group.enabled g.record_count = group.count return g.to_json()
def _marshall_group_response(group: DbFeedGroupMetadata) -> FeedGroupMetadata: if not group: raise ValueError(group) g = FeedGroupMetadata() g.name = group.name g.last_sync = group.last_sync g.created_at = group.created_at g.updated_at = group.last_update g.enabled = group.enabled g.record_count = group.count return g
def test_groups(): d1 = datetime.datetime.utcnow() d2 = datetime.datetime.utcnow() - datetime.timedelta(days=1) g = FeedGroupMetadata() g.name = 'group' g.enabled = True g.created_at = d2 g.updated_at = d1 g.last_sync = d1 g.record_count = 0 assert g.to_json() == { 'name': 'group', 'enabled': True, 'created_at': d2.isoformat(timespec='microseconds') + UTC_OFFSET, 'updated_at': d1.isoformat(timespec='microseconds') + UTC_OFFSET, 'last_sync': d1.isoformat(timespec='microseconds') + UTC_OFFSET, 'record_count': 0, }
def test_groups(): d1 = datetime.datetime.utcnow() d2 = datetime.datetime.utcnow() - datetime.timedelta(days=1) g = FeedGroupMetadata() g.name = "group" g.enabled = True g.created_at = d2 g.updated_at = d1 g.last_sync = d1 g.record_count = 0 assert g.to_json() == { "name": "group", "enabled": True, "created_at": datetime_to_rfc3339(d2), "updated_at": datetime_to_rfc3339(d1), "last_sync": datetime_to_rfc3339(d1), "record_count": 0, }
def test_groups(): d1 = datetime.datetime.utcnow() d2 = datetime.datetime.utcnow() - datetime.timedelta(days=1) g = FeedGroupMetadata() g.name = "group" g.enabled = True g.created_at = d2 g.updated_at = d1 g.last_sync = d1 g.record_count = 0 assert g.to_json() == { "name": "group", "enabled": True, "created_at": d2.isoformat(timespec="microseconds") + UTC_OFFSET, "updated_at": d1.isoformat(timespec="microseconds") + UTC_OFFSET, "last_sync": d1.isoformat(timespec="microseconds") + UTC_OFFSET, "record_count": 0, }
def list_feeds(include_counts=False): """ GET /feeds :return: """ f = DataFeeds.instance() meta = f.list_metadata() response = [] for feed in meta: i = FeedMetadata() i.name = feed.name i.last_full_sync = feed.last_full_sync.isoformat( ) if feed.last_full_sync else None i.created_at = feed.created_at.isoformat() if feed.created_at else None i.updated_at = feed.last_update.isoformat( ) if feed.last_update else None i.groups = [] for group in feed.groups: g = FeedGroupMetadata() g.name = group.name g.last_sync = group.last_sync.isoformat( ) if group.last_sync else None g.created_at = group.created_at.isoformat( ) if group.created_at else None if include_counts: # Compute count (this is slow) g.record_count = f.records_for(i.name, g.name) else: g.record_count = None i.groups.append(g.to_dict()) response.append(i.to_dict()) return jsonify(response)
def test_feeds(): f = FeedMetadata() f.name = 'feed1' d1 = datetime.datetime.utcnow() f.updated_at = d1 assert f.to_json() == { 'name': 'feed1', 'updated_at': d1.isoformat(timespec='microseconds') + UTC_OFFSET, 'groups': None, 'enabled': None, 'last_full_sync': None } f.groups = [] g = FeedGroupMetadata() g.name = 'group1' g.record_count = 10 g.enabled = True f.groups.append(g) assert f.to_json() == { 'name': 'feed1', 'updated_at': d1.isoformat(timespec='microseconds') + UTC_OFFSET, 'enabled': None, 'last_full_sync': None, 'groups': [{ 'name': 'group1', 'enabled': True, 'record_count': 10, 'created_at': None, 'updated_at': None, 'last_sync': None }] }
def test_feeds(): f = FeedMetadata() f.name = "feed1" d1 = datetime.datetime.utcnow() f.updated_at = d1 assert f.to_json() == { "name": "feed1", "updated_at": datetime_to_rfc3339(d1), "groups": None, "enabled": None, "last_full_sync": None, } f.groups = [] g = FeedGroupMetadata() g.name = "group1" g.record_count = 10 g.enabled = True f.groups.append(g) assert f.to_json() == { "name": "feed1", "updated_at": datetime_to_rfc3339(d1), "enabled": None, "last_full_sync": None, "groups": [{ "name": "group1", "enabled": True, "record_count": 10, "created_at": None, "updated_at": None, "last_sync": None, }], }
def test_feeds(): f = FeedMetadata() f.name = "feed1" d1 = datetime.datetime.utcnow() f.updated_at = d1 assert f.to_json() == { "name": "feed1", "updated_at": d1.isoformat(timespec="microseconds") + UTC_OFFSET, "groups": None, "enabled": None, "last_full_sync": None, } f.groups = [] g = FeedGroupMetadata() g.name = "group1" g.record_count = 10 g.enabled = True f.groups.append(g) assert f.to_json() == { "name": "feed1", "updated_at": d1.isoformat(timespec="microseconds") + UTC_OFFSET, "enabled": None, "last_full_sync": None, "groups": [{ "name": "group1", "enabled": True, "record_count": 10, "created_at": None, "updated_at": None, "last_sync": None, }], }