示例#1
0
    def test_get_top(self):
        countstore = CountStore()
        countstore.put("entity1", "test_entity", "test_seg")
        countstore.put("entity2", "test_entity", "test_seg")
        countstore.put("entity2", "test_entity", "test_seg")
        actual = countstore.get_top("test_entity", "test_seg", 10)
        expected = [("entity2", 2), ("entity1", 1)]

        self.assertEqual(expected, actual)

        fixture.setup_mock_time(fixture.jan_1st_2013_midday + 3600)

        countstore.put("entity1", "test_entity", "test_seg")
        countstore.put("entity1", "test_entity", "test_seg")
        countstore.put("entity3", "test_entity", "test_seg")
        actual = countstore.get_top("test_entity", "test_seg", 10)
        expected = [("entity1", 3), ("entity2", 2), ("entity3", 1)]

        self.assertEqual(expected, actual)

        fixture.setup_mock_time(fixture.jan_1st_2013_midday + 2*3600)

        countstore.put("entity3", "test_entity", "test_seg")
        countstore.put("entity3", "test_entity", "test_seg")
        actual = countstore.get_top("test_entity", "test_seg", 10)
        expected = [("entity3", 3), ("entity1", 2)]

        self.assertEqual(expected, actual)
示例#2
0
    def test_put_with_total_count(self):
        countstore = CountStore()
        countstore.put("entity1", "test_entity", "test_seg", total_count = 10)
        docs = self.get_all_docs()

        self.assertEqual(9, len(docs))

        expected = self.build_timeslice_docs({
            "entity_id"   : "entity1",
            "entity_type" : "test_entity",
            "segmentation": "test_seg",
            "base_count"  : 10,
            "count"       : 1,
        })
        self.assertEqual(expected, docs)

        fixture.setup_mock_time(fixture.jan_1st_2013_midday + 60*15)

        countstore.put("entity1", "test_entity", "test_seg", total_count = 15)
        docs = self.get_all_docs()

        self.assertEqual(10, len(docs))

        expected = self.build_timeslice_docs({
            "entity_id"   : "entity1",
            "entity_type" : "test_entity",
            "segmentation": "test_seg",
            "count"       : 6,
	        "base_count"  : 10,
        })
        expected[0]["count"] = 1
        expected[0]["base_count"] = 10
        last_doc = copy(expected[-1])
        last_doc["count"] = 1
        last_doc["base_count"] = 15
        last_doc["timeslice"] = fixture.jan_1st_2013_midday + 60*15
        expected.append(last_doc)

        self.assertEqual(expected, docs)
示例#3
0
 def setUp(self):
     fixture.setup_database_settings()
     fixture.setup_mock_time()
     self._mongo = Mongo("CountStore")
     self._mongo.clear()