'Test QueryDict with one key/value pair'

def test_single_key_value(self):

    q = QueryDict(str(u'foo=bar'))
    self.assertEqual(q[u'foo'], u'bar')
    self.assertRaises(KeyError, q.__getitem__, u'bar')
    self.assertRaises(AttributeError, q.__setitem__, u'something', u'bar')
    self.assertEqual(q.get(u'foo', u'default'), u'bar')
    self.assertEqual(q.get(u'bar', u'default'), u'default')
    self.assertEqual(q.getlist(u'foo'), [u'bar'])
    self.assertEqual(q.getlist(u'bar'), [])
    self.assertRaises(AttributeError, q.setlist, u'foo', [u'bar'])
    self.assertRaises(AttributeError, q.appendlist, u'foo', [u'bar'])
    if six.PY2:
        self.assertTrue(q.has_key(u'foo'))
    self.assertTrue((u'foo' in q))
    if six.PY2:
        self.assertFalse(q.has_key(u'bar'))
    self.assertFalse((u'bar' in q))
    self.assertEqual(list(six.iteritems(q)), [(u'foo', u'bar')])
    self.assertEqual(list(six.iterlists(q)), [(u'foo', [u'bar'])])
    self.assertEqual(list(six.iterkeys(q)), [u'foo'])
    self.assertEqual(list(six.itervalues(q)), [u'bar'])
    self.assertEqual(len(q), 1)
    self.assertRaises(AttributeError, q.update, {u'foo': u'bar'})
    self.assertRaises(AttributeError, q.pop, u'foo')
    self.assertRaises(AttributeError, q.popitem)
    self.assertRaises(AttributeError, q.clear)
    self.assertRaises(AttributeError, q.setdefault, u'foo', u'bar')
    self.assertEqual(q.urlencode(), u'foo=bar')
