'Test key metadata operations.'

def test_metadata(self):

    bucket = self._MakeBucket()
    k = self._MakeKey(bucket=bucket)
    key_name = k.name
    s1 = 'This    is    a    test    of    file    upload    and    download'
    mdkey1 = 'meta1'
    mdval1 = 'This    is    the    first    metadata    value'
    k.set_metadata(mdkey1, mdval1)
    mdkey2 = 'meta2'
    mdval2 = 'This    is    the    second    metadata    value'
    k.set_metadata(mdkey2, mdval2)
    mdval3 = u'f\xf6\xf6'
    mdkey3 = 'meta3'
    k.set_metadata(mdkey3, mdval3)
    k.set_contents_from_string(s1)
    k = bucket.lookup(key_name)
    self.assertEqual(k.get_metadata(mdkey1), mdval1)
    self.assertEqual(k.get_metadata(mdkey2), mdval2)
    self.assertEqual(k.get_metadata(mdkey3), mdval3)
    k = bucket.new_key(key_name)
    k.get_contents_as_string()
    self.assertEqual(k.get_metadata(mdkey1), mdval1)
    self.assertEqual(k.get_metadata(mdkey2), mdval2)
    self.assertEqual(k.get_metadata(mdkey3), mdval3)
