Esempio n. 1
0
def test_stats_returned(mock_pymongo):
    #db.track.aggregate({ $group: { _id: { "year":{$year:"$createdDate"},"month":{$month:"$createdDate"},"day":{$dayOfMonth: "$createdDate"}},createdDate: { $sum: 1 } } })
    

    

    mock_pymongo.dead.track.find.return_value= get_sample_stats()
    dead = DropHandler(mock_pymongo)
    val = dead.stats()
    expected =[
            {"$group": 
            { "_id": { "year":{"$year":"$createdDate"},"month":{"$month":"$createdDate"},"day":{"$dayOfMonth": "$createdDate"},"userHash":"$userHash"},
                "count": { "$sum": 1 } ,
            } 
            },
            {"$group": 
                { "_id": { "year":"$_id.year","month":"$_id.month","day":"$_id.day"},
                "count": { "$sum": "$count" },
                "distinctCount": { "$sum": 1 }
                } 
            },
            {"$sort":  {"_id.year":1,"_id.month":1,"_id.day":1}},
            
        ];
    mock_pymongo.dead.track.aggregate.assert_called_with(expected)
Esempio n. 2
0
def test_stats_returned(mock_pymongo):
    """See if stats are returned properly."""
    mock_pymongo.dead.track.find.return_value = get_sample_stats()
    dead = DropHandler(mock_pymongo)
    stats = dead.stats()
    expected = [
        {
            "$group": {
                "_id": {
                    "year": {
                        "$year": "$createdDate"
                    },
                    "month": {
                        "$month": "$createdDate"
                    },
                    "day": {
                        "$dayOfMonth": "$createdDate"
                    },
                    "userHash": "$userHash"
                },
                "count": {
                    "$sum": 1
                }
            }
        },
        {
            "$group": {
                "_id": {
                    "year": "$_id.year",
                    "month": "$_id.month",
                    "day": "$_id.day"
                },
                "count": {
                    "$sum": "$count"
                },
                "distinctCount": {
                    "$sum": 1
                }
            }
        },
        {
            "$sort": {
                "_id.year": 1,
                "_id.month": 1,
                "_id.day": 1
            }
        },
    ]
    pprint.pprint(expected)
    pprint.pprint(stats)

    mock_pymongo.dead.track.aggregate.assert_called_with(expected)