Example #1
0
    def test_restore(self):
        class A(object):
            def __init__(self, context):
                self.context = context

        class B(object):
            def __init__(self, context):
                self.context = context

        class C(object):
            def __init__(self, context):
                self.context = context

        ctxt = Context()
        ctxt.service = "http://example.org/service.atomsvc"
        ctxt.collection = "http://example.org/collection/1/"
        ctxt.entry = "http://example.org/collection/1/1"

        a, b, c = ctxt.restore(A, B, C)
        self.assertEqual(type(a), A)
        self.assertEqual(type(b), B)
        self.assertEqual(type(c), C)

        ctxt.service = None
        a, b, c = ctxt.restore(A, B, C)
        self.assertEqual(a, None)
        self.assertEqual(b, None)
        self.assertEqual(c, None)
Example #2
0
    def test_attribs(self):
        c = Context()
        c.service = "http://example.org/service.atomsvc"
        c.collection = "http://example.org/collection/1/"
        c.entry = "http://example.org/collection/1/1"
        self.assertEqual(c.service, "http://example.org/service.atomsvc")
        self.assertEqual(c.collection, "http://example.org/collection/1/")
        self.assertEqual(c.entry, "http://example.org/collection/1/1")

        c.collection = "http://example.org/collection/2/"
        self.assertEqual(c.service, "http://example.org/service.atomsvc")
        self.assertEqual(c.collection, "http://example.org/collection/2/")
        self.assertEqual(c.entry, None)

        c.service = "http://example.org/some_other_service.atomsvc"
        self.assertEqual(c.service, "http://example.org/some_other_service.atomsvc")
        self.assertEqual(c.collection, None)
        self.assertEqual(c.entry, None)
Example #3
0
    def test_push_pop(self):
        c = Context()
        c.service = "http://example.org/service.atomsvc"
        c.collection = "http://example.org/collection/1/"
        c.entry = "http://example.org/collection/1/1"

        c.collpush("http://fred.org/")

        # Test pickle and un-pickle while were at it.
        file = StringIO()
        pickle.dump(c, file)
        file.seek(0)
        c = pickle.load(file)

        self.assertEqual(c.collection, "http://fred.org/")
        self.assertEqual(c.entry, None)
        c.collpop()
        self.assertEqual(c.collection, "http://example.org/collection/1/")
        self.assertEqual(c.entry, "http://example.org/collection/1/1")