示例#1
0
def test_news_sampling():
    fake_news(STANDARD_DISTRIBUTION)
    session.commit()
    res = sample()
    for c, num in STANDARD_DISTRIBUTION.iteritems():
        assert len(res[c]) == num

    try:
        count = NewsEntry.query.count()
        d = dict((c, count) for c, _ in STANDARD_DISTRIBUTION.iteritems())

        sample(d)
    except CantSampleEnough:
        pass
    else:
        assert Fail, "Shouldn't be able to sample this"
示例#2
0
    def test_sampling(self):
        res = self.app.get("/sample")
        json = loads(res.body)
        news = json["news"]
        d = defaultdict(list)
        for n in news:
            d[n["category"]].append(n)

        for c, num in STANDARD_DISTRIBUTION.iteritems():
            assert c in d, "not in result: " + c
            assert len(d[c]) == num