class_docstr: Unit tests for DagCode.
class_docstr_tok: ["Unit","tests","for","DagCode","."]
docstr: Test if DagCode is updated in DB when DAG file is changed
docstr_tok: ["Test","if","DagCode","is","updated","in","DB","when","DAG","file","is","changed"]
code: def test_db_code_updated_on_dag_file_change(self):
      """Test if DagCode is updated in DB when DAG file is changed"""
      example_dag = make_example_dags(example_dags_module).get(
          "example_bash_operator"
      )
      example_dag.sync_to_db()
  
      with create_session() as session:
          result = (
              session.query(DagCode)
              .filter(DagCode.fileloc == example_dag.fileloc)
              .one()
          )
  
          assert result.fileloc == example_dag.fileloc
          assert result.source_code is not None
  
      with patch(
          "airflow.models.dagcode.os.path.getmtime"
      ) as mock_mtime:
          mock_mtime.return_value = (
              result.last_updated + timedelta(seconds=1)
          ).timestamp()
  
          with patch(
              "airflow.models.dagcode.DagCode._get_code_from_file"
          ) as mock_code:
              mock_code.return_value = "# dummy code"
              example_dag.sync_to_db()
  
              with create_session() as session:
                  new_result = (
                      session.query(DagCode)
                      .filter(DagCode.fileloc == example_dag.fileloc)
                      .one()
                  )
  
                  assert new_result.fileloc == example_dag.fileloc
                  assert new_result.source_code == "# dummy code"
                  assert new_result.last_updated > result.last_updated
  
imports: from __future__ import annotations
  from datetime import timedelta
  from unittest.mock import patch
  import pytest
  import airflow.example_dags
  from airflow.exceptions import AirflowException
  from airflow.models import DagBag
  from airflow.models.dagcode import DagCode
  from airflow.utils.file import open_maybe_zipped
  from airflow.utils.session import create_session
  from tests.test_utils.db import clear_db_dag_code
label_desc: Use image node_id 11 for calling the TestDagCode obj's underlying member method code with example usage: obj.test_db_code_updated_on_dag_file_change() without return types