mik-laj commented on a change in pull request #8535:
URL: https://github.com/apache/airflow/pull/8535#discussion_r415205547



##########
File path: tests/cli/commands/test_variable_command.py
##########
@@ -124,10 +82,78 @@ def test_variables(self):
         self.assertEqual(False, Variable.get('false', deserialize_json=True))
         self.assertEqual(None, Variable.get('null', deserialize_json=True))
 
-        os.remove('variables1.json')
-        os.remove('variables2.json')
-        os.remove('variables3.json')
+        os.remove('variables_types.json')
 
-    def test_get_missing_variable(self):
+    @unittest.mock.patch('sys.stdout', new_callable=io.StringIO)
+    def test_variables_get(self, mock_stdout):
+        """"Test variable_get command"""
+        # Test conventional get call
+        variable_command.variables_set(self.parser.parse_args([
+            'variables', 'set', 'foo', '{"foo":"bar"}']))
+        variable_command.variables_get(self.parser.parse_args([
+            'variables', 'get', 'foo']))
+        self.assertEqual(mock_stdout.getvalue(), '{"foo":"bar"}\n')
         with self.assertRaises(SystemExit):
-            
variable_command.variables_get(self.parser.parse_args(['variables', 'get', 
'no-existing-VAR']))
+            
variable_command.variables_get(self.parser.parse_args(['variables', 'get', 
'no-existing-VAR'])
+
+        # Test default functionality for get call
+        variable_command.variables_get(self.parser.parse_args([
+            'variables', 'get', 'baz', '--default', 'bar']))
+        self.assertEqual(mock_stdout.getvalue(), '{"foo":"bar"}\nbar\n')
+
+    def test_variables_list(self):
+        """Test variable_list command"""
+        # Test command is received
+        variable_command.variables_list(self.parser.parse_args([
+            'variables', 'list']))
+
+    def test_variables_delete(self):
+        """Test variable_delete command"""
+        variable_command.variables_set(self.parser.parse_args([
+            'variables', 'set', 'foo', 'bar']))
+        variable_command.variables_delete(self.parser.parse_args([
+            'variables', 'delete', 'foo']))
+        self.assertRaises(KeyError, Variable.get, "foo")
+
+    def test_variables_import(self):
+        """Test variables_import command"""
+        variable_command.variables_import(self.parser.parse_args([
+            'variables', 'import', os.devnull]))
+
+    def test_variables_export(self):
+        """Test variables_export command"""
+        variable_command.variables_export(self.parser.parse_args([
+            'variables', 'export', os.devnull]))
+
+    def test_variables_isolation(self):
+        """Test isolation of variables"""
+        variable_command.variables_set(self.parser.parse_args([
+            'variables', 'set', 'bar', 'original']))
+        variable_command.variables_export(self.parser.parse_args([
+            'variables', 'export', 'variables1.json']))
+
+        first_exp = open('variables1.json', 'r')

Review comment:
       Can you use NamedTemporaryFile? This deletes the file even if the test 
fails.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to