summaryrefslogtreecommitdiff
path: root/templates/python/context_tests.py
blob: 24d8f512e895aea79e44c90e6b846b442e725593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import unittest

from context import Context


class ContextTests(unittest.TestCase):
    def test_converts_to_empty_dict_initially(self):
        ctx = Context()
        self.assertEqual(ctx.as_dict(), {})

    def test_set_item(self):
        ctx = Context()
        ctx["foo"] = "bar"
        self.assertEqual(ctx["foo"], "bar")

    def test_does_not_contain_item(self):
        ctx = Context()
        self.assertFalse("foo" in ctx)

    def test_no_longer_contains_item(self):
        ctx = Context()
        ctx["foo"] = "bar"
        del ctx["foo"]
        self.assertFalse("foo" in ctx)

    def test_contains_item(self):
        ctx = Context()
        ctx["foo"] = "bar"
        self.assertTrue("foo" in ctx)

    def test_get_returns_default_if_item_does_not_exist(self):
        ctx = Context()
        self.assertEqual(ctx.get("foo"), None)

    def test_get_returns_specified_default_if_item_does_not_exist(self):
        ctx = Context()
        self.assertEqual(ctx.get("foo", "bar"), "bar")

    def test_get_returns_value_if_item_exists(self):
        ctx = Context()
        ctx["foo"] = "bar"
        self.assertEqual(ctx.get("foo", "yo"), "bar")


unittest.main()