Example #1
0
def parse_feed(text, base):
    """parse_feed(string) -> (feed, posts)"""
    # This little hack tells feedparser the base URL of this feed, so it
    # can resolve links for us.
    f = StringIO(text)
    f.url = base
    parsed = feedparser.parse(f)
    return sanitize_feed(parsed['feed']), sanitize_posts(parsed['entries'])
Example #2
0
 def _makeFakePostForm(self, base_url, page=None):
     """Create a fake `urllib2.urlopen` result."""
     content = "<bugzilla>%s</bugzilla>" % self.factory.getUniqueString()
     fake_form = StringIO(content)
     if page is None:
         page = self.factory.getUniqueString()
     fake_form.url = base_url + page
     return fake_form
 def _makeFakePostForm(self, base_url, page=None):
     """Create a fake `urllib2.urlopen` result."""
     content = "<bugzilla>%s</bugzilla>" % self.factory.getUniqueString()
     fake_form = StringIO(content)
     if page is None:
         page = self.factory.getUniqueString()
     fake_form.url = base_url + page
     return fake_form
 def _makeInstrumentedBugzilla(self, page=None, content=None):
     """Create a `Bugzilla` with a fake urlopen."""
     if page is None:
         page = self.factory.getUniqueString()
     bugzilla = Bugzilla(self.base_url)
     if content is None:
         content = "<bugzilla>%s</bugzilla>" % (self.factory.getUniqueString())
     fake_page = StringIO(content)
     fake_page.url = self.base_url + page
     bugzilla.urlopen = FakeMethod(result=fake_page)
     return bugzilla
Example #5
0
 def _makeInstrumentedBugzilla(self, page=None, content=None):
     """Create a `Bugzilla` with a fake urlopen."""
     if page is None:
         page = self.factory.getUniqueString()
     bugzilla = Bugzilla(self.base_url)
     if content is None:
         content = "<bugzilla>%s</bugzilla>" % (
             self.factory.getUniqueString())
     fake_page = StringIO(content)
     fake_page.url = self.base_url + page
     bugzilla.urlopen = FakeMethod(result=fake_page)
     return bugzilla
Example #6
0
def get_in_memory_image_file():
    """Returns a fake image file. Faster than using file system."""
    image_file = StringIO()
    image = PILImage.new("RGBA", size=(50, 50), color=(256, 0, 0))
    image.save(image_file, 'png')
    name = '%s.png' % generate_random_string()
    image_file.name = name
    image_file.width = 200
    image_file.height = 200
    image_file._committed = False
    image_file.save = Mock()
    image_file.url = '/uploads/%s' % name
    image_file.__unicode__ = Mock(return_value=name)
    image_file.seek(0)
    return image_file
Example #7
0
 def fake_file(self, string='{}', url='http://bogus', info=None):
     sio = StringIO(string)
     sio.info = lambda: FakeFileInfo(info)
     sio.url = url
     return sio