def make_mock_photo(self, photo_id): r = random.Random(photo_id) format = r.choice(('jpg', 'gif', 'png')) h, w, s = map(r.randint, (1, 1, 512), (5000, 5000, sys.maxint)) url = "http://test_%s_o.%s" % (photo_id, format) # The PhotoIndex refresh gives a photo ID. self.photos.refresh.mock_returns.append(photo_id) # The fake photo ID points at the PhotoIndex record. self.photos[photo_id] = { 'id': photo_id, 'originalformat': format, 'o_height': str(h), 'o_width': str(w), 'size': str(s), 'url_o': url, } # The record's URL points at the request. tail = 'tail data' + photo_id request = Mock("Request(%s)" % url) request.code = urllib2.httplib.PARTIAL_CONTENT request.headers = {'content-range': "%u-%u/%u" % (s - 512, s, s)} request.read.mock_returns = tail self.urls[url] = request # The tail data points at the fake shorthash. shorthash = 'short hash' + photo_id self.tails[tail] = shorthash return shorthash