Exemple #1
0
    def test_model(self):
        data = {
            u'provider_url': u'http://www.google.com/',
            u'safe': True,
            u'description': u'Google',
            u'original_url': u'http://google.com/',
            u'url': u'http://www.google.com/',
            u'type': u'html',
            u'object': {},
            u'provider_display': u'www.google.com',
            u'author_name': None,
            u'favicon_url': u'http://www.google.com/favicon.ico',
            u'place': {},
            u'author_url': None,
            u'images': [
                {u'url': u'http://www.google.com/intl/en_ALL/images/srpr/logo1w.png',
                 u'width': 275,
                 u'height': 95}],
            u'title': u'Google',
            u'provider_name': u'Google',
            u'cache_age': 86400,
            u'embeds': []
        }
        
        obj = Url(data, 'preview', 'http://google.com/')

        self.assert_(len(obj) is 17)
        self.assert_(len(obj.values()) is 17)
        self.assert_(len(obj.keys()) is 17)
        self.assert_(len(obj.items()) is 17)

        self.assert_('type' in obj.keys())
        self.assert_('html' in obj.values())

        #Get the object
        self.assert_(obj.type == 'html')
        self.assert_(obj['type'] == 'html')
        self.assert_(obj.get('type') == 'html')
        
        #nope
        self.assert_(obj.nothing is None)
        
        obj.nothing = 'something'
        self.assert_(obj.nothing == 'something')
        
        obj['nothing'] = 'maybe'
        self.assert_(obj['nothing'] == 'maybe')
        
        del obj['nothing']
        self.assert_(obj.nothing is None)
        
        #Deep Get attrs
        self.assert_(obj.images[0].width is 275)
        self.assert_(obj.images[0].nothing is None)
        self.assert_(obj.object.type is None)
Exemple #2
0
    def test_model(self):
        data = {
            u"provider_url": u"http://www.google.com/",
            u"safe": True,
            u"description": u"Google",
            u"original_url": u"http://google.com/",
            u"url": u"http://www.google.com/",
            u"type": u"html",
            u"object": {},
            u"provider_display": u"www.google.com",
            u"author_name": None,
            u"favicon_url": u"http://www.google.com/favicon.ico",
            u"place": {},
            u"author_url": None,
            u"images": [
                {u"url": u"http://www.google.com/intl/en_ALL/images/srpr/logo1w.png", u"width": 275, u"height": 95}
            ],
            u"title": u"Google",
            u"provider_name": u"Google",
            u"cache_age": 86400,
            u"embeds": [],
        }

        obj = Url(data, "preview", "http://google.com/")

        self.assert_(len(obj) is 17)
        self.assert_(len(obj.values()) is 17)
        self.assert_(len(obj.keys()) is 17)
        self.assert_(len(obj.items()) is 17)

        self.assert_("type" in obj.keys())
        self.assert_("html" in obj.values())

        # Get the object
        self.assert_(obj.type == "html")
        self.assert_(obj["type"] == "html")
        self.assert_(obj.get("type") == "html")

        # nope
        self.assert_(obj.nothing is None)

        obj.nothing = "something"
        self.assert_(obj.nothing == "something")

        obj["nothing"] = "maybe"
        self.assert_(obj["nothing"] == "maybe")

        del obj["nothing"]
        self.assert_(obj.nothing is None)

        # Deep Get attrs
        self.assert_(obj.images[0].width is 275)
        self.assert_(obj.images[0].nothing is None)
        self.assert_(obj.object.type is None)
Exemple #3
0
    def test_model(self):
        data = {
            'provider_url': 'http://www.google.com/',
            'safe': True,
            'description': 'Google',
            'url': 'http://www.google.com/',
            'type': 'html',
            'object': {},
            'provider_display': 'www.google.com',
            'author_name': None,
            'favicon_url': 'http://www.google.com/favicon.ico',
            'place': {},
            'author_url': None,
            'images': [
                {'url': 'http://www.google.com/intl/en_ALL/images/srpr/logo1w.png',
                 'width': 275,
                 'height': 95}],
            'title': 'Google',
            'provider_name': 'Google',
            'cache_age': 86400,
            'embeds': []
        }
        obj = Url(data, 'preview', 'http://original.url.com/')

        self.assertEqual(len(obj), 16)
        self.assertEqual(len(list(obj.values())), 16)
        self.assertEqual(len(list(obj.keys())), 16)
        self.assertEqual(len(list(obj.items())), 16)

        # check for expected data
        self.assertTrue('type' in list(obj.keys()))
        self.assertTrue('html' in list(obj.values()))
        self.assertEqual(obj['type'], 'html')
        self.assertEqual(obj.get('type'), 'html')
        self.assertEqual(obj.data['type'], 'html')
        self.assertEqual(obj.data.get('type'), 'html')

        # our special attrs shouldn't be in the data dict
        self.assertFalse('method' in list(obj.keys()))
        with self.assertRaises(KeyError):
            obj['method']

        # attrs and data dict values should be separate
        self.assertEqual(obj.original_url, 'http://original.url.com/')

        obj.new_attr = 'attr value'
        obj['new_key'] = 'dict value'
        self.assertEqual(obj.new_attr, 'attr value')
        self.assertEqual(obj['new_key'], 'dict value')
Exemple #4
0
    def test_model(self):
        data = {
            'provider_url': 'http://www.google.com/',
            'safe': True,
            'description': 'Google',
            'url': 'http://www.google.com/',
            'type': 'html',
            'object': {},
            'provider_display': 'www.google.com',
            'author_name': None,
            'favicon_url': 'http://www.google.com/favicon.ico',
            'place': {},
            'author_url': None,
            'images': [
                {'url': 'http://www.google.com/intl/en_ALL/images/srpr/logo1w.png',
                 'width': 275,
                 'height': 95}],
            'title': 'Google',
            'provider_name': 'Google',
            'cache_age': 86400,
            'embeds': []
        }
        obj = Url(data, 'preview', 'http://original.url.com/')

        self.assertEqual(len(obj), 16)
        self.assertEqual(len(obj.values()), 16)
        self.assertEqual(len(obj.keys()), 16)
        self.assertEqual(len(obj.items()), 16)

        # check for expected data
        self.assertTrue('type' in obj.keys())
        self.assertTrue('html' in obj.values())
        self.assertEqual(obj['type'], 'html')
        self.assertEqual(obj.get('type'), 'html')
        self.assertEqual(obj.data['type'], 'html')
        self.assertEqual(obj.data.get('type'), 'html')

        # our special attrs shouldn't be in the data dict
        self.assertFalse('method' in obj.keys())
        with self.assertRaises(KeyError):
            obj['method']

        # attrs and data dict values should be separate
        self.assertEqual(obj.original_url, 'http://original.url.com/')

        obj.new_attr = 'attr value'
        obj['new_key'] = 'dict value'
        self.assertEqual(obj.new_attr, 'attr value')
        self.assertEqual(obj['new_key'], 'dict value')
Exemple #5
0
    def test_model(self):
        data = {
            u'provider_url':
            u'http://www.google.com/',
            u'safe':
            True,
            u'description':
            u'Google',
            u'original_url':
            u'http://google.com/',
            u'url':
            u'http://www.google.com/',
            u'type':
            u'html',
            u'object': {},
            u'provider_display':
            u'www.google.com',
            u'author_name':
            None,
            u'favicon_url':
            u'http://www.google.com/favicon.ico',
            u'place': {},
            u'author_url':
            None,
            u'images': [{
                u'url':
                u'http://www.google.com/intl/en_ALL/images/srpr/logo1w.png',
                u'width': 275,
                u'height': 95
            }],
            u'title':
            u'Google',
            u'provider_name':
            u'Google',
            u'cache_age':
            86400,
            u'embeds': []
        }

        obj = Url(data, 'preview', 'http://google.com/')

        self.assert_(len(obj) is 17)
        self.assert_(len(obj.values()) is 17)
        self.assert_(len(obj.keys()) is 17)
        self.assert_(len(obj.items()) is 17)

        self.assert_('type' in obj.keys())
        self.assert_('html' in obj.values())

        #Get the object
        self.assert_(obj.type == 'html')
        self.assert_(obj['type'] == 'html')
        self.assert_(obj.get('type') == 'html')

        #nope
        self.assert_(obj.nothing is None)

        obj.nothing = 'something'
        self.assert_(obj.nothing == 'something')

        obj['nothing'] = 'maybe'
        self.assert_(obj['nothing'] == 'maybe')

        del obj['nothing']
        self.assert_(obj.nothing is None)

        #Deep Get attrs
        self.assert_(obj.images[0].width is 275)
        self.assert_(obj.images[0].nothing is None)
        self.assert_(obj.object.type is None)