def test_compute_md5sum(self): """ Verify that the Object.compute_md5sum() class method returns an accurate md5 sum value. """ f = open('/bin/ls', 'r') m = md5() m.update(f.read()) sum1 = m.hexdigest() f.seek(0) try: sum2 = Object.compute_md5sum(f) self.assert_(sum1 == sum2, "%s != %s" % (sum1, sum2)) finally: f.close()
def test_bad_name(self): """ Ensure you can't assign an invalid object name. """ obj = Object(self.container) # name is None self.assertRaises(InvalidObjectName, obj.read) self.assertRaises(InvalidObjectName, obj.stream) self.assertRaises(InvalidObjectName, obj.sync_metadata) self.assertRaises(InvalidObjectName, obj.write, '') obj.name = '' # name is zero-length string self.assertRaises(InvalidObjectName, obj.read) self.assertRaises(InvalidObjectName, obj.stream) self.assertRaises(InvalidObjectName, obj.sync_metadata) self.assertRaises(InvalidObjectName, obj.write, '') obj.name = 'a'*(object_name_limit+1) # too-long string self.assertRaises(InvalidObjectName, obj.read) self.assertRaises(InvalidObjectName, obj.stream().next) self.assertRaises(InvalidObjectName, obj.sync_metadata) self.assertRaises(InvalidObjectName, obj.write, '') obj.name = 'a'*(object_name_limit) # ok name obj.read() obj.stream() obj.sync_metadata() obj.write('')