Пример #1
0
    def test_resource_init_by_properties(self):
        r = Resource(MagicMock(), properties={
            'href': 'test/resource',
            'createdAt': '2014-07-16T13:48:22.378Z',
            'modifiedAt': '2014-07-16T13:48:22.378+01:00',
            'name': 'Test Resource',
            'someProperty': 'value'
        })

        # it's not new (has href)
        self.assertFalse(r.is_new())
        # it knows what it is
        self.assertEqual(r.href, 'test/resource')
        # we can access the attributes
        self.assertEqual(r.name, 'Test Resource')
        # there is created_at attribute
        self.assertEqual(
            r.created_at,
            datetime(2014, 7, 16, 13, 48, 22, 378000, tzinfo=tzutc()))
        # there is modified_at attribute
        self.assertEqual(
            r.modified_at,
            datetime(
                2014, 7, 16, 13, 48, 22, 378000, tzinfo=tzoffset(None, 3600)))
        # attribute name was correctly converted
        self.assertEqual(r.some_property, 'value')
        # there are no writable attributes
        with self.assertRaises(AttributeError):
            r.name = 5
        with self.assertRaises(AttributeError):
            r.created_at = 'whatever'
        with self.assertRaises(AttributeError):
            r.modified_at = 'whatever'
Пример #2
0
    def test_resource_init_by_href(self):
        r = Resource(MagicMock(), href='test/resource')

        # it's not new (has href)
        self.assertFalse(r.is_new())
        # it know what it is
        self.assertEqual(r.href, 'test/resource')
        # href is not writable
        with self.assertRaises(AttributeError):
            r.href = 'abc'
        # non-existing attribute access is handled correctly
        with self.assertRaises(AttributeError):
            r.foo
Пример #3
0
    def test_resource_init_by_href(self):
        r = Resource(MagicMock(), href='test/resource')

        # it's not new (has href)
        self.assertFalse(r.is_new())
        # it know what it is
        self.assertEqual(r.href, 'test/resource')
        # href is not writable
        with self.assertRaises(AttributeError):
            r.href = 'abc'
        # non-existing attribute access is handled correctly
        with self.assertRaises(AttributeError):
            r.foo
    def test_resource_init_by_properties(self):
        r = Resource(MagicMock(), properties={
            'href': 'test/resource',
            'name': 'Test Resource',
            'someProperty': 'value'
        })

        # it's not new (has href)
        self.assertFalse(r.is_new())
        # it knows what it is
        self.assertEqual(r.href, 'test/resource')
        # we can access the attributes
        self.assertEqual(r.name, 'Test Resource')
        # attribute name was correctly converted
        self.assertEqual(r.some_property, 'value')
        # there are no writable attributes
        with self.assertRaises(AttributeError):
            r.name = 5
Пример #5
0
    def test_resource_init_by_properties(self):
        r = Resource(MagicMock(),
                     properties={
                         'href': 'test/resource',
                         'name': 'Test Resource',
                         'someProperty': 'value'
                     })

        # we have the resource data
        self.assertTrue(r.is_materialized())
        # it's not new (has href)
        self.assertFalse(r.is_new())
        # it knows what it is
        self.assertEqual(r.href, 'test/resource')
        # we can access the attributes
        self.assertEqual(r.name, 'Test Resource')
        # attribute name was correctly converted
        self.assertEqual(r.some_property, 'value')
        # there are no writable attributes
        with self.assertRaises(AttributeError):
            r.name = 5
Пример #6
0
    def test_resource_init_by_properties(self):
        r = Resource(MagicMock(),
                     properties={
                         'href': 'test/resource',
                         'createdAt': '2014-07-16T13:48:22.378Z',
                         'modifiedAt': '2014-07-16T13:48:22.378+01:00',
                         'name': 'Test Resource',
                         'someProperty': 'value'
                     })

        # it's not new (has href)
        self.assertFalse(r.is_new())
        # it knows what it is
        self.assertEqual(r.href, 'test/resource')
        # we can access the attributes
        self.assertEqual(r.name, 'Test Resource')
        # there is created_at attribute
        self.assertEqual(
            r.created_at,
            datetime(2014, 7, 16, 13, 48, 22, 378000, tzinfo=tzutc()))
        # there is modified_at attribute
        self.assertEqual(
            r.modified_at,
            datetime(2014,
                     7,
                     16,
                     13,
                     48,
                     22,
                     378000,
                     tzinfo=tzoffset(None, 3600)))
        # attribute name was correctly converted
        self.assertEqual(r.some_property, 'value')
        # there are no writable attributes
        with self.assertRaises(AttributeError):
            r.name = 5
        with self.assertRaises(AttributeError):
            r.created_at = 'whatever'
        with self.assertRaises(AttributeError):
            r.modified_at = 'whatever'