def test_record_metadata_json(self):
        """Test inclusion of json metadata in records."""

        # Need unique app_id per test as they may be run in parallel and have
        # same ids.
        chain, recorder = self._create_basic_chain(app_name="metajson")

        message, _ = self._get_question_and_answers(0)
        meta = dict(field1="hello", field2="there")

        with recorder as recording:
            recording.record_metadata = meta
            chain.invoke(input=dict(question=message))
        record = recording.get()

        # Check record has metadata.
        self.assertEqual(record.meta, meta)

        # Check the record has the metadata when retrieved back from db.
        recs, _ = core_session.TruSession().get_records_and_feedback([
            recorder.app_id
        ])
        self.assertGreater(len(recs), 0)
        rec = self._load_first_record(recs)
        self.assertEqual(rec.meta, meta)

        # Check updating the record metadata in the db.
        new_meta = dict(hello="this is new meta")
        rec.meta = new_meta
        core_session.TruSession().update_record(rec)

        recs, _ = core_session.TruSession().get_records_and_feedback([
            recorder.app_id
        ])
        self.assertGreater(len(recs), 0)
        rec = self._load_first_record(recs)
        self.assertNotEqual(rec.meta, meta)
        self.assertEqual(rec.meta, new_meta)
Test inclusion of json metadata in records.
tests/e2e/test_tru_chain.py