示例#1
0
 def test_list(self):
     mock_db = riak.RiakClient()
     instance = ProjectStore(mock_db)
     (project, id) = instance.create("Sample", ["sample1", "sample2",])
     self.assertEqual(instance.active_projects[id], project)
     instance.stop(id)
     self.assertEqual(instance.active_projects, {})
示例#2
0
 def test_create(self):
     mock_db = riak.RiakClient()
     mock_bucket = mock_db.bucket("message")
     mock_id = "proj-1"
     instance = ProjectStore(mock_db)
     (project, id) = instance.create("Sample", ["sample1", "sample2",], id_key=mock_id)
     self.assertEqual(project.name, "Sample")
     self.assertTrue(project.id, mock_id)
示例#3
0
 def test_examine_and_save_message(self):
     mock_db = riak.RiakClient()
     mock_bucket = mock_db.bucket("message")
     ps = ProjectStore(mock_db)
     project, id = ps.create("Sample", ["test1", "test2", ], mock_bucket)
     def sample_algorithm(keyword_counts, total):
         return [k for (k,v) in keyword_counts.iteritems() if v / total >= 1]
     self.assertEqual(project.calculate_new_keywords(sample_algorithm), ["test1", "test2",])
     sample_message1 = {
         "message" : "A sample test1",
         "sent_at" : "now",
     }
     sample_message2 = {
         "message" : "A sample test2",
         "sent_at" : "now",
     }
     self.assertTrue(project.examine_and_save_message(sample_message1, ["test1", "fake1",]))
     self.assertFalse(project.examine_and_save_message(sample_message2, ["fake2", "fake1",]))
示例#4
0
    def test_examine_and_save_message(self):
        mock_db = riak.RiakClient()
        mock_bucket = mock_db.bucket("message")
        ps = ProjectStore(mock_db)
        project, id = ps.create("Sample", [
            "test1",
            "test2",
        ], mock_bucket)

        def sample_algorithm(keyword_counts, total):
            return [
                k for (k, v) in keyword_counts.iteritems() if v / total >= 1
            ]

        self.assertEqual(project.calculate_new_keywords(sample_algorithm), [
            "test1",
            "test2",
        ])
        sample_message1 = {
            "message": "A sample test1",
            "sent_at": "now",
        }
        sample_message2 = {
            "message": "A sample test2",
            "sent_at": "now",
        }
        self.assertTrue(
            project.examine_and_save_message(sample_message1, [
                "test1",
                "fake1",
            ]))
        self.assertFalse(
            project.examine_and_save_message(sample_message2, [
                "fake2",
                "fake1",
            ]))