def data(self, data): """Sets the data for the form. Iterates through all the fields on the form and injects the value. Args: data (dict|watson.http.messages.Request): A dict of key/value pairs to populate the form with. """ self.invalidate() if hasattr(data, 'post'): raw_data = MultiDict() raw_data.update(data.post.items()) try: raw_data.update(data.json_body) except: pass for key, value in data.files.items(): # need to do this rather than .update due to File objects # being named tuples raw_data[key] = value else: raw_data = data self._set_data_on_fields(raw_data)
def test_update(self): d = MultiDict() d.update({'test': 'test'}) assert 'test' in d