Example #1
0
def _marshall_feed_response(feed: DbFeedMetadata):
    if not feed:
        return ValueError(feed)

    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.enabled = feed.enabled
    i.groups = []

    for group in feed.groups:
        i.groups.append(_marshall_group_response(group))

    return i.to_json()
Example #2
0
def _marshall_feed_response(feed: DbFeedMetadata) -> FeedMetadata:
    if not feed:
        return ValueError(feed)

    i = FeedMetadata()
    i.name = feed.name
    i.last_full_sync = feed.last_full_sync
    i.created_at = feed.created_at
    i.updated_at = feed.last_update
    i.enabled = feed.enabled
    i.groups = []

    for group in feed.groups:
        i.groups.append(_marshall_group_response(group))

    return i
Example #3
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
        }]
    }
Example #5
0
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,
        }],
    }
Example #6
0
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,
        }],
    }