Exemplo n.º 1
0
 def test_bad_username(self):
     with patch('r2.models.account.Account') as MockAccount:
         MockAccount._by_name.side_effect = NotFound
         self.assertEqual(
             utils.url_to_thing('http://reddit.local/user/missing_user'),
             None,
         )
Exemplo n.º 2
0
    def GET_oembed(self, url, parent, live):
        """Get the oEmbed response for a URL, if any exists.

        Spec: http://www.oembed.com/

        Optional parameters (parent, live) are passed through as embed options
        to oEmbed renderers.
        """
        response.content_type = "application/json"

        thing = url_to_thing(url)
        if not thing:
            abort(404)

        embed_options = {
            "parent": parent,
            "live": live,
        }

        try:
            return scriptsafe_dumps(_oembed_for(thing, **embed_options))
        except ForbiddenError:
            abort(403)
        except NotImplementedError:
            abort(404)
Exemplo n.º 3
0
 def test_short_username(self):
     with patch('r2.models.account.Account') as MockAccount:
         MockAccount._by_name.return_value = s.Account
         self.assertEqual(
             utils.url_to_thing('https://reddit.local/u/wting'),
             s.Account,
         )
Exemplo n.º 4
0
 def test_short_username(self):
     with patch('r2.models.account.Account') as MockAccount:
         MockAccount._by_name.return_value = s.Account
         self.assertEqual(
             utils.url_to_thing('https://reddit.local/u/wting'),
             s.Account,
         )
Exemplo n.º 5
0
    def GET_oembed(self, url, parent, live):
        """Get the oEmbed response for a URL, if any exists.

        Spec: http://www.oembed.com/

        Optional parameters (parent, live) are passed through as embed options
        to oEmbed renderers.
        """
        response.content_type = "application/json"

        thing = url_to_thing(url)
        if not thing:
            abort(404)

        embed_options = {
            "parent": parent,
            "live": live,
        }

        try:
            return scriptsafe_dumps(_oembed_for(thing, **embed_options))
        except ForbiddenError:
            abort(403)
        except NotImplementedError:
            abort(404)
Exemplo n.º 6
0
 def test_bad_username(self):
     with patch('r2.models.account.Account') as MockAccount:
         MockAccount._by_name.side_effect = NotFound
         self.assertEqual(
             utils.url_to_thing('http://reddit.local/user/missing_user'),
             None,
         )
Exemplo n.º 7
0
 def test_subreddit(self):
     with patch('r2.models.Subreddit') as MockSubreddit:
         MockSubreddit._by_name.return_value = s.Subreddit
         self.assertEqual(
             utils.url_to_thing('http://reddit.local/r/pics/'),
             s.Subreddit,
         )
Exemplo n.º 8
0
 def test_subreddit(self):
     with patch('r2.models.Subreddit') as MockSubreddit:
         MockSubreddit._by_name.return_value = s.Subreddit
         self.assertEqual(
             utils.url_to_thing('http://reddit.local/r/pics/'),
             s.Subreddit,
         )
Exemplo n.º 9
0
 def test_username_subcategories(self):
     user_categories = [
         'comments', 'submitted', 'gilded', 'upvoted', 'downvoted',
         'hidden', 'saved'
     ]
     with patch('r2.models.account.Account') as MockAccount:
         MockAccount._by_name.return_value = s.Account
         for category in user_categories:
             self.assertEqual(
                 utils.url_to_thing('https://reddit.local/u/wting/%s/' %
                                    category),
                 s.Account,
             )
Exemplo n.º 10
0
 def test_username_subcategories(self):
     user_categories = [
         'comments', 'submitted', 'gilded', 'upvoted', 'downvoted',
         'hidden', 'saved'
     ]
     with patch('r2.models.account.Account') as MockAccount:
         MockAccount._by_name.return_value = s.Account
         for category in user_categories:
             self.assertEqual(
                 utils.url_to_thing(
                     'https://reddit.local/u/wting/%s/' %
                     category
                 ),
                 s.Account,
             )
Exemplo n.º 11
0
    def get_content_id():
        from r2.lib import utils
        thing = utils.url_to_thing(request.fullurl)

        if not thing:
            return None, None

        content_id = None
        type_name = getattr(thing, '_type_name', None)
        if type_name == 'comment':
            # We use the parent link for comment permalink pages, since
            # they share a canonical URL
            link = getattr(thing, 'link', thing.link_slow)
            content_id = link._fullname
        elif type_name == 'link':
            content_id = thing._fullname
        elif type_name == 'subreddit':
            content_id = thing._fullname
        return content_id, type_name
Exemplo n.º 12
0
 def test_frontpage(self):
     self.assertEqual(
         utils.url_to_thing('http://reddit.local/'),
         None,
     )
Exemplo n.º 13
0
 def test_frontpage(self):
     self.assertEqual(
         utils.url_to_thing('http://reddit.local/'),
         None,
     )