Пример #1
0
 def setUp(self):
     self.q = QueuedScriptCollection()
     pass
Пример #2
0
class QueuedScriptCollection_Tests(unittest.TestCase):

    longMessage = True

    def setUp(self):
        self.q = QueuedScriptCollection()
        pass

    def assert_sorted_data_equals(self, expected):
        d = self.q.get_sorted_scripts()
        self.assertEqual(expected, d, "data")

    def test_single_script(self):
        self.q.add_script("a.txt", "1", "content")
        self.assert_sorted_data_equals([("a.txt", "1", "content")])

    def test_no_scripts(self):
        self.assert_sorted_data_equals([])

    def test_multiple_scripts_sorted(self):
        self.q.add_script("a.txt", "1", "content_a")
        self.q.add_script("b.txt", "1", "content_b")
        self.assert_sorted_data_equals([("a.txt", "1", "content_a"), ("b.txt", "1", "content_b")])

    def test_two_scripts_with_same_name_are_further_sorted_by_db_name(self):
        self.q.add_script("a.txt", "2", "content_b")
        self.q.add_script("a.txt", "1", "content_a")
        self.assert_sorted_data_equals([("a.txt", "1", "content_a"), ("a.txt", "2", "content_b")])

    def test_cannot_add_the_same_script_for_the_same_db_twice(self):
        self.q.add_script("a.txt", "1", "content_b")
        self.assertRaises(ScriptRunnerException, self.q.add_script, "a.txt", "1", "content_b")

    def test_many_scripts_many_databases(self):
        self.q.add_script("a.txt", "2", "a_2")
        self.q.add_script("c.txt", "1", "c_1")
        self.q.add_script("a.txt", "1", "a_1")
        self.q.add_script("b.txt", "2", "b_2")
        self.q.add_script("b.txt", "1", "b_1")
        self.q.add_script("a.txt", "3", "a_3")

        self.assert_sorted_data_equals(
            [("a.txt", "1", "a_1"),
             ("a.txt", "2", "a_2"),
             ("a.txt", "3", "a_3"),
             ("b.txt", "1", "b_1"),
             ("b.txt", "2", "b_2"),
             ("c.txt", "1", "c_1")])

    def test_script_name_cannot_exceed_255_chars(self):
        self.q.add_script("x" * 255, "1", "255 ok")
        self.assertRaises(ScriptRunnerException, self.q.add_script, "x" * 256, "1", "256 bad")