Skip to content

Commit

Permalink
Simplify tests for CLI connections commands (#21983)
Browse files Browse the repository at this point in the history
The tests (particularly with the export subcommand) were doing a fair bit of unnecessary mocking. In particular they mocked builtins.open. But there's no good reason that we can't actually write out the file and read the file in the assert (which is a much better way to test this). There were also a number of assertions re splittext which are not really relevant.

I suspect the reason that the author did this is because the file wasn't closed, so when you read the value from the exported file (if the process has not been exited) then the buffer may not be fully written to disk. I fix this by closing the file after writing the connections.

As part of this change I also update to use current pytest techniques for parameterization and temp files.
  • Loading branch information
dstandish authored Mar 4, 2022
1 parent b153a2e commit e81527c
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 285 deletions.
1 change: 1 addition & 0 deletions airflow/cli/commands/connection_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def connections_export(args):
connections = session.query(Connection).order_by(Connection.conn_id).all()
msg = _format_connections(connections, filetype)
args.file.write(msg)
args.file.close()

if _is_stdout(args.file):
print("Connections successfully exported.", file=sys.stderr)
Expand Down
Loading

0 comments on commit e81527c

Please sign in to comment.