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"))
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"]))
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"))
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"]))
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"]))
def test_query_existing_tag_with_no_results(self): self.assertListEqual([], lasertag.query(["source:http", "host:bank.com"]))
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)
def test_query_invalid_tag(self): self.assertListEqual([], lasertag.query(["invalid"]))
def test_query_multiple_tags_with_multiple_matching_values(self): self.assertListEqual(["desc1", "image2.jpg"], lasertag.query(["source:http", "userid:345"]))
def test_query_single_tag_with_multiple_matching_values(self): self.assertListEqual(["image1.jpg", "image2.jpg", "image3.jpg"], lasertag.query(["type:image"]))
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)
def test_empty_query(self): with self.assertRaises(AttributeError): lasertag.query([])
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"]))
def test_query_single_tag_with_single_matching_value(self): self.assertListEqual(["bank-thing1"], lasertag.query(["host:bank.com"]))
def test_query_single_tag_given_as_string(self): self.assertListEqual(["desc1", "image2.jpg"], lasertag.query("userid:345"))
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"]))
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)
def test_query_multiple_tags_with_single_matching_value(self): self.assertListEqual(["bank-thing1"], lasertag.query(["host:bank.com", "source:sftp"]))