Exemple #1
0
 def test_put_bad_opml(self):
     mb = self.create_test_mailbox()
     slug = get_mailbox_slug(self.config, mb.name)
     c = self.get_test_app()
     opml_url = self.url_for('subscriptions_opml', mailbox_slug=slug)
     opml = "this ain't opml"
     c.put(opml_url, opml, content_type='text/xml', status=400)
Exemple #2
0
    def test_opml_post(self):
        mb = self.create_test_mailbox()
        slug = get_mailbox_slug(self.config, mb.name)
        c = self.get_test_app()
        
        opml_url = self.url_for('subscriptions_opml', mailbox_slug=slug)
    
        feeds = {'http://www.example.org/feeds/1': 'feed 1',
                 'http://www.example.org/feeds/2': 'feed 2',
                 'http://www.example.org/feeds/3': 'feed 3'
                 }
        opml = make_opml(feeds)
        response = c.post(opml_url, opml, content_type='text/xml', status=200)
        info = json.loads(response.body)
        assert info['errors'] == 0
        assert info['deleted'] == 0
        assert info['imported'] == 3

        response = c.get(opml_url, status=200)
        out_feeds = feeds_in_opml(response.body)
        
        for url, title in out_feeds.items():
            assert url in feeds
            assert feeds[url] == title
            
        for url, title in feeds.items():
            assert url in out_feeds
            assert out_feeds[url] == title
Exemple #3
0
    def test_message_delete(self):
        """
        test deleting a message by DELETE
        """
        from radarpost.mailbox import Message
        
        message1 = Message(title='Message 1')
        message2 = Message(title='Message 2')
        
        mb = self.create_test_mailbox()
        slug =  get_mailbox_slug(self.config, mb.name)

        c = self.get_test_app()
        self.login_as_admin(c)

        message1.store(mb)
        message2.store(mb)

        assert message1.id in mb
        assert message2.id in mb
        
        c.delete(self.url_for('message_rest', mailbox_slug=slug, message_slug=message1.id))
        
        assert message1.id not in mb
        assert message2.id in mb
Exemple #4
0
    def test_sub_get(self):
        """
        test GET to subscription slug to retrieve info
        """
        
        url = 'http://example.com/feed/1'
        title = 'The Example Feed'

        mb = self.create_test_mailbox()
        slug =  get_mailbox_slug(self.config, mb.name)

        c = self.get_test_app()
        self.login_as_admin(c)

        subs_url = self.url_for('subscriptions_rest', mailbox_slug=slug)

        response = c.get(subs_url)
        all_subs = json.loads(response.body)
        assert len(all_subs) == 0

        info = {'type': 'feed', 'title': title, 'url': url}
        response = c.post(subs_url, json.dumps(info), content_type='application/json', status=201)
        sub_slug = json.loads(response.body)['slug']
        info_url = self.url_for('subscription_rest', mailbox_slug=slug, 
                                sub_slug=sub_slug)

        response = c.get(info_url)
        subinfo = json.loads(response.body)
        assert subinfo['type'] == 'feed'
        assert subinfo['title'] == title
        assert subinfo['url'] == url
Exemple #5
0
    def test_mailbox_head_etag(self):

        mb = self.create_test_mailbox()
        slug = get_mailbox_slug(self.config, mb.name)
        url = self.url_for('mailbox_rest', mailbox_slug=slug)

        c = self.get_test_app()

        response = c.head(url, status=200)

        assert 'etag' in response.headers
        etag = response.headers['etag']

        # check with wrong etag
        response = c.head(url, headers=[('if-none-match', 'bogus')], status=200)

        # with correct etag, we should get 304
        c.head(url, headers=[('if-none-match', '"%s"' % etag)], status=304)

        # also with * etag
        c.head(url, headers=[('if-none-match', '*')], status=304)

        # modifying the mailbox should invalidate the etag
        mb.save({})
        # with correct etag, we should get 304
        c.head(url, headers=[('if-none-match', '"%s"' % etag)], status=200)
Exemple #6
0
    def test_create_sub_post(self):
        """
        test create subscription by POST to <mbid>/subscriptions
        """
        url = 'http://example.com/feed/1'
        title = 'The Example Feed'
        
        mb = self.create_test_mailbox()
        slug =  get_mailbox_slug(self.config, mb.name)
        
        c = self.get_test_app()
        self.login_as_admin(c)

        subs_url = self.url_for('subscriptions_rest', mailbox_slug=slug)

        response = c.get(subs_url)
        all_subs = json.loads(response.body)
        
        assert len(all_subs) == 0
        
        info = {'type': 'feed', 'title': title, 'url': url}
        c.post(subs_url, json.dumps(info), content_type='application/json', status=201)

        response = c.get(subs_url)
        all_subs = json.loads(response.body)

        assert len(all_subs) == 1
        assert all_subs[0]['type'] == 'feed'
        assert all_subs[0]['title'] == title
        assert all_subs[0]['url'] == url
Exemple #7
0
 def test_opml_empty_get(self):
     mb = self.create_test_mailbox()
     slug = get_mailbox_slug(self.config, mb.name)
     c = self.get_test_app()
     opml_url = self.url_for('subscriptions_opml', mailbox_slug=slug)
     response = c.get(opml_url, status=200)
     feeds = feeds_in_opml(response.body)
     
     assert len(feeds.keys()) == 0
Exemple #8
0
    def test_update_sub_post(self):
        """
        test updating a subscription by POST'ing to its url
        """
        
        url = 'http://example.com/feed/1'
        title = 'The Example Feed'

        url2 = 'http://example.com/feed/2'
        title2 = 'The Example Feed 2'

        mb = self.create_test_mailbox()
        slug =  get_mailbox_slug(self.config, mb.name)

        c = self.get_test_app()
        self.login_as_admin(c)

        subs_url = self.url_for('subscriptions_rest', mailbox_slug=slug)

        response = c.get(subs_url)
        all_subs = json.loads(response.body)

        assert len(all_subs) == 0

        info = {'type': 'feed', 'title': title, 'url': url}
        response = c.post(subs_url, json.dumps(info), content_type='application/json', status=201)
        sub_slug = json.loads(response.body)['slug']

        sub_url = self.url_for('subscription_rest', mailbox_slug=slug, 
                               sub_slug=sub_slug)

        response = c.get(sub_url)
        sub_info = json.loads(response.body)
        assert sub_info['type'] == 'feed'
        assert sub_info['title'] == title
        assert sub_info['url'] == url

        # POST some bad info, should fail and leave the sub unchanged
        info = {'title': title2, 'url': url2, 'some_bad-key': 'val'}
        c.post(sub_url, json.dumps(info), content_type='application/json', status=400)
        response = c.get(sub_url)
        sub_info = json.loads(response.body)
        assert sub_info['type'] == 'feed'
        assert sub_info['title'] == title
        assert sub_info['url'] == url

        # POST to change title and URL, valid, should change the sub
        info = {'title': title2, 'url': url2}
        c.post(sub_url, json.dumps(info), content_type='application/json')
        response = c.get(sub_url)
        sub_info = json.loads(response.body)
        assert sub_info['type'] == 'feed'
        assert sub_info['title'] == title2
        assert sub_info['url'] == url2
Exemple #9
0
 def test_mailbox_delete(self):
     """
     test deleting a mailbox
     """
     mb = self.create_test_mailbox()
     slug = get_mailbox_slug(self.config, mb.name)
     mb_url = self.url_for('mailbox_rest', mailbox_slug=slug)
     c = self.get_test_app()
     self.login_as_admin(c)
     c.head(mb_url, status=200)
     c.delete(mb_url, status=200)
     c.head(mb_url, status=404)
     c.delete(mb_url, status=404)
Exemple #10
0
    def test_delete_sub(self):
        """
        test deleting a subscription by DELETE
        """
        
        url = 'http://example.com/feed/1'
        title = 'The Example Feed'

        url2 = 'http://example.com/feed/2'
        title2 = 'The Example Feed 2'

        mb = self.create_test_mailbox()
        slug =  get_mailbox_slug(self.config, mb.name)

        c = self.get_test_app()
        self.login_as_admin(c)

        subs_url = self.url_for('subscriptions_rest', mailbox_slug=slug)

        response = c.get(subs_url)
        all_subs = json.loads(response.body)
        assert len(all_subs) == 0
        
        # create two subscriptions
        info = {'type': 'feed', 'title': title, 'url': url}
        c.post(subs_url, json.dumps(info), content_type='application/json', status=201)
        
        info = {'type': 'feed', 'title': title2, 'url': url2}
        c.post(subs_url, json.dumps(info), content_type='application/json', status=201)

        response = c.get(subs_url)
        all_subs = json.loads(response.body)

        assert len(all_subs) == 2

        # delete the second subscription
        for sub in all_subs: 
            if sub['url'] == url2: 
                del_url = self.url_for('subscription_rest',
                                       mailbox_slug=slug,
                                       sub_slug=sub['slug'])
                c.delete(del_url)
        
        # check that the first subscription is the only thing there
        response = c.get(subs_url)
        all_subs = json.loads(response.body)
        assert len(all_subs) == 1
        assert all_subs[0]['type'] == 'feed'
        assert all_subs[0]['title'] == title
        assert all_subs[0]['url'] == url
Exemple #11
0
    def test_mailbox_update(self):
        mb = self.create_test_mailbox()
        slug = get_mailbox_slug(self.config, mb.name)
        mb_url = self.url_for('mailbox_rest', mailbox_slug=slug)
        c = self.get_test_app()
        self.login_as_admin(c)
        
        new_title = "The Test Mailbox's New Title"
        mbinfo = MailboxInfo.get(mb)
        assert mbinfo.title != new_title
        
        c.post(mb_url, json.dumps({'title': new_title}), 
               content_type="application/json", status=200)

        mbinfo = MailboxInfo.get(mb)
        assert mbinfo.title == new_title
Exemple #12
0
    def test_opml_post_appends(self):
        from radarpost.feed import FeedSubscription
        
        mb = self.create_test_mailbox()
        slug = get_mailbox_slug(self.config, mb.name)
        c = self.get_test_app()
        
        opml_url = self.url_for('subscriptions_opml', mailbox_slug=slug)
    
        feeds1 = {'http://www.example.org/feeds/1': 'feed 1',
                 'http://www.example.org/feeds/2': 'feed 2',
                 'http://www.example.org/feeds/3': 'feed 3'
                 }
        opml = make_opml(feeds1)
        c.post(opml_url, opml, content_type='text/xml', status=200)

        feeds2 = {'http://www.example.org/feeds/3': 'feed 3',
                 'http://www.example.org/feeds/4': 'feed 4',
                 'http://www.example.org/feeds/5': 'feed 5'
                 }
        opml = make_opml(feeds2)
        response = c.post(opml_url, opml, content_type='text/xml', status=200)
        info = json.loads(response.body)
        assert info['errors'] == 0
        assert info['deleted'] == 0
        assert info['imported'] == 2

        response = c.get(opml_url, status=200)
        out_feeds = feeds_in_opml(response.body)
        
        all_feeds = {}
        all_feeds.update(feeds1)
        all_feeds.update(feeds2) 
        
        for url, title in out_feeds.items():
            assert url in all_feeds
            assert all_feeds[url] == title
            
        for url, title in all_feeds.items():
            assert url in out_feeds
            assert out_feeds[url] == title
            
        count = 0
        for r in mb.view(FeedSubscription.by_url):
            count += 1
        assert count == 5