示例#1
0
 def test_add_duplicate_rollsback_changes(self):
     lasertag.add_value(["a", "b", "c"], "v")
     with self.assertRaises(AttributeError):
         lasertag.add_value(["c", "d", "e", "f"], "v")
     self.assertEqual([], lasertag.query("d"))
     self.assertEqual([], lasertag.query("e"))
     self.assertEqual([], lasertag.query("f"))
示例#2
0
 def test_add_duplicate_rollsback_changes(self):
     lasertag.add_value(["a", "b", "c"], "v")
     with self.assertRaises(AttributeError):
         lasertag.add_value(["c", "d", "e", "f"], "v")
     self.assertEqual([], lasertag.query("d"))
     self.assertEqual([], lasertag.query("e"))
     self.assertEqual([], lasertag.query("f"))
示例#3
0
    def test_add_with_value_transformer(self):
        lasertag.add_value(["t1", "t2"], "value",
                           transformers=[self.TestValueTransfomer()])

        self.assertEqual([], lasertag.query("new"))
        self.assertEqual([], lasertag.query("tags"))
        self.assertEqual(["new value"], lasertag.query(["t1", "t2"]))
示例#4
0
    def test_add_with_value_transformer(self):
        lasertag.add_value(["t1", "t2"],
                           "value",
                           transformers=[self.TestValueTransfomer()])

        self.assertEqual([], lasertag.query("new"))
        self.assertEqual([], lasertag.query("tags"))
        self.assertEqual(["new value"], lasertag.query(["t1", "t2"]))
示例#5
0
 def test_rename_with_value(self):
     lasertag.rename_tag("userid:345", "userid:999", with_value="image2.jpg")
     self.assertTrue(len(lasertag.query("userid:345")) == 1)
     self.assertTrue(len(lasertag.query("userid:999")) == 1)
     self.assertEqual(["source:http", "userid:345", "type:description"],
                      lasertag.tags("desc1"))
     self.assertEqual(["source:http", "userid:999", "type:image"],
                      lasertag.tags("image2.jpg"))
示例#6
0
    def test_add_with_both_tag_and_value_transformer(self):
        lasertag.add_value(["t1", "t2"], "value",
                           transformers=[self.TestTransfomer()])

        self.assertEqual([], lasertag.query("t1"))
        self.assertEqual([], lasertag.query("t2"))
        self.assertEqual([], lasertag.tags("value"))
        self.assertEqual(["new value"], lasertag.query(["new", "tags"]))
示例#7
0
    def test_add_with_both_tag_and_value_transformer(self):
        lasertag.add_value(["t1", "t2"],
                           "value",
                           transformers=[self.TestTransfomer()])

        self.assertEqual([], lasertag.query("t1"))
        self.assertEqual([], lasertag.query("t2"))
        self.assertEqual([], lasertag.tags("value"))
        self.assertEqual(["new value"], lasertag.query(["new", "tags"]))
示例#8
0
 def test_rename_with_value(self):
     lasertag.rename_tag("userid:345",
                         "userid:999",
                         with_value="image2.jpg")
     self.assertTrue(len(lasertag.query("userid:345")) == 1)
     self.assertTrue(len(lasertag.query("userid:999")) == 1)
     self.assertEqual(["source:http", "userid:345", "type:description"],
                      lasertag.tags("desc1"))
     self.assertEqual(["source:http", "userid:999", "type:image"],
                      lasertag.tags("image2.jpg"))
示例#9
0
    def test_add_with_multiple_transfomers(self):
        lasertag.add_value(["t1", "t2"], "value",
                           transformers=[
                               self.TestTagTransformer(),
                               self.TestValueTransfomer()
                           ])

        self.assertEqual([], lasertag.query("t1"))
        self.assertEqual([], lasertag.query("t2"))
        self.assertEqual([], lasertag.tags("value"))
        self.assertEqual(["new value"], lasertag.query(["new", "tags"]))
示例#10
0
    def test_add_with_multiple_transfomers(self):
        lasertag.add_value(["t1", "t2"],
                           "value",
                           transformers=[
                               self.TestTagTransformer(),
                               self.TestValueTransfomer()
                           ])

        self.assertEqual([], lasertag.query("t1"))
        self.assertEqual([], lasertag.query("t2"))
        self.assertEqual([], lasertag.tags("value"))
        self.assertEqual(["new value"], lasertag.query(["new", "tags"]))
示例#11
0
 def test_query_existing_tag_with_no_results(self):
     self.assertListEqual([],
                          lasertag.query(["source:http", "host:bank.com"]))
示例#12
0
 def test_rename_no_occurrence_tag(self):
     lasertag.rename_tag("invalid", to="invalid2")
     self.assertTrue(len(lasertag.query("invalid")) == 0)
     self.assertTrue(len(lasertag.query("invalid2")) == 0)
示例#13
0
 def test_query_invalid_tag(self):
     self.assertListEqual([], lasertag.query(["invalid"]))
示例#14
0
 def test_query_multiple_tags_with_multiple_matching_values(self):
     self.assertListEqual(["desc1", "image2.jpg"],
                          lasertag.query(["source:http", "userid:345"]))
示例#15
0
 def test_query_single_tag_with_multiple_matching_values(self):
     self.assertListEqual(["image1.jpg", "image2.jpg", "image3.jpg"],
                          lasertag.query(["type:image"]))
示例#16
0
 def test_rename_multi_occurrence_tag(self):
     lasertag.rename_tag("userid:345", to="userid:999")
     self.assertTrue(len(lasertag.query("userid:345")) == 0)
     self.assertTrue(len(lasertag.query("userid:999")) == 2)
示例#17
0
 def test_empty_query(self):
     with self.assertRaises(AttributeError):
         lasertag.query([])
示例#18
0
 def test_add_empty_transformer_list(self):
     lasertag.add_value(["t1", "t2"], "hello world", transformers=[])
     self.assertTrue("hello world" in lasertag.query(["t1"]))
     self.assertTrue("hello world" in lasertag.query(["t2"]))
     self.assertTrue("hello world" in lasertag.query(["t1", "t2"]))
示例#19
0
 def test_query_single_tag_with_single_matching_value(self):
     self.assertListEqual(["bank-thing1"],
                          lasertag.query(["host:bank.com"]))
示例#20
0
 def test_query_existing_tag_with_no_results(self):
     self.assertListEqual([],
                          lasertag.query(["source:http", "host:bank.com"]))
示例#21
0
 def test_query_invalid_tag(self):
     self.assertListEqual([], lasertag.query(["invalid"]))
示例#22
0
 def test_query_single_tag_given_as_string(self):
     self.assertListEqual(["desc1", "image2.jpg"],
                          lasertag.query("userid:345"))
示例#23
0
 def test_individual_tags_are_added(self):
     lasertag.add_value(["t1", "t2"], "hello world")
     self.assertTrue("hello world" in lasertag.query(["t1"]))
     self.assertTrue("hello world" in lasertag.query(["t2"]))
     self.assertTrue("hello world" in lasertag.query(["t1", "t2"]))
示例#24
0
 def test_rename_single_occurrence_tag(self):
     lasertag.rename_tag("host:bank.com", to="host:anotherbank.com")
     self.assertTrue(len(lasertag.query("host:bank.com")) == 0)
     self.assertTrue(len(lasertag.query("host:anotherbank.com")) == 1)
示例#25
0
 def test_query_single_tag_given_as_string(self):
     self.assertListEqual(["desc1", "image2.jpg"],
                          lasertag.query("userid:345"))
示例#26
0
 def test_query_single_tag_with_single_matching_value(self):
     self.assertListEqual(["bank-thing1"],
                          lasertag.query(["host:bank.com"]))
示例#27
0
 def test_rename_single_occurrence_tag(self):
     lasertag.rename_tag("host:bank.com", to="host:anotherbank.com")
     self.assertTrue(len(lasertag.query("host:bank.com")) == 0)
     self.assertTrue(len(lasertag.query("host:anotherbank.com")) == 1)
示例#28
0
 def test_query_single_tag_with_multiple_matching_values(self):
     self.assertListEqual(["image1.jpg", "image2.jpg", "image3.jpg"],
                          lasertag.query(["type:image"]))
示例#29
0
 def test_rename_no_occurrence_tag(self):
     lasertag.rename_tag("invalid", to="invalid2")
     self.assertTrue(len(lasertag.query("invalid")) == 0)
     self.assertTrue(len(lasertag.query("invalid2")) == 0)
示例#30
0
 def test_query_multiple_tags_with_single_matching_value(self):
     self.assertListEqual(["bank-thing1"],
                          lasertag.query(["host:bank.com", "source:sftp"]))
示例#31
0
 def test_individual_tags_are_added(self):
     lasertag.add_value(["t1", "t2"], "hello world")
     self.assertTrue("hello world" in lasertag.query(["t1"]))
     self.assertTrue("hello world" in lasertag.query(["t2"]))
     self.assertTrue("hello world" in lasertag.query(["t1", "t2"]))
示例#32
0
 def test_query_multiple_tags_with_multiple_matching_values(self):
     self.assertListEqual(["desc1", "image2.jpg"],
                          lasertag.query(["source:http", "userid:345"]))
示例#33
0
 def test_query_multiple_tags_with_single_matching_value(self):
     self.assertListEqual(["bank-thing1"],
                          lasertag.query(["host:bank.com", "source:sftp"]))
示例#34
0
 def test_empty_query(self):
     with self.assertRaises(AttributeError):
         lasertag.query([])
示例#35
0
 def test_add_empty_transformer_list(self):
     lasertag.add_value(["t1", "t2"], "hello world", transformers=[])
     self.assertTrue("hello world" in lasertag.query(["t1"]))
     self.assertTrue("hello world" in lasertag.query(["t2"]))
     self.assertTrue("hello world" in lasertag.query(["t1", "t2"]))
示例#36
0
 def test_rename_multi_occurrence_tag(self):
     lasertag.rename_tag("userid:345", to="userid:999")
     self.assertTrue(len(lasertag.query("userid:345")) == 0)
     self.assertTrue(len(lasertag.query("userid:999")) == 2)