jhtimmins commented on a change in pull request #13859:
URL: https://github.com/apache/airflow/pull/13859#discussion_r575766870



##########
File path: tests/www/test_views.py
##########
@@ -254,6 +254,66 @@ def test_prefill_form_null_extra(self):
         cmv.prefill_form(form=mock_form, pk=1)
 
 
+class TestCopyConnectionModelView(TestBase):
+    def setUp(self):
+        super().setUp()
+        conn1 = Connection(
+            conn_id='aws_mongo',
+            conn_type='FTP',
+            description='MongoDB',
+            host='192.168.55.11',
+            schema='airflow',
+            port='5566',
+        )
+
+        # Already copied and modified
+        conn2 = Connection(
+            conn_id='aws_mongo__1',
+            conn_type='FTP',
+            description='MongoDB2',
+            host='192.168.55.12',
+            schema='airflow',
+            port='5567',
+        )
+
+        conn3 = Connection(
+            conn_id='aws_mysql',
+            conn_type='FTP',
+            description='MongoDB2',
+            host='192.168.55.12',
+            schema='airflow',
+            port='5567',
+        )
+
+        self.clear_table(Connection)
+        self.session.add_all([conn1, conn2, conn3])
+        self.session.commit()
+
+    def tearDown(self):
+        self.clear_table(Connection)
+        super().tearDown()
+
+    def test_copy_connection(self):
+        """ Test copy multiple connection with suffix(already copied )"""
+
+        mock_form = mock.Mock()
+        mock_form.data = {"action": "mulcopy", "rowid": [1, 2, 3]}
+        resp = self.client.post('/connection/action_post', 
data=mock_form.data, follow_redirects=True)
+
+        expected_result = {
+            'aws_mongo',
+            'aws_mongo__1',
+            'aws_mongo__2',
+            'aws_mongo__3',

Review comment:
       Is it fair to treat all `aws_mongo` variants as essentially 
interchangeable in terms of numbering them? Would `aws_mongo__1__1` make more 
sense than `aws_mongo__3` to make clear that it's a copy of `aws_mongo__1`? It 
doesn't look as nice, but it seems like people would copy `aws_mongo__1` 
because they want a copy of that exact variant.

##########
File path: airflow/www/views.py
##########
@@ -2896,6 +2897,49 @@ def action_muldelete(self, items):
         self.update_redirect()
         return redirect(self.get_redirect())
 
+    @action('mulcopy', 'Copy', 'Are you sure you want to Duplicate selected 
connections?', single=False)

Review comment:
       ```suggestion
       @action('mulcopy', 'Copy', 'Are you sure you want to duplicate the 
selected connections?', single=False)
   ```

##########
File path: airflow/www/views.py
##########
@@ -2896,6 +2897,49 @@ def action_muldelete(self, items):
         self.update_redirect()
         return redirect(self.get_redirect())
 
+    @action('mulcopy', 'Copy', 'Are you sure you want to Duplicate selected 
connections?', single=False)
+    @provide_session
+    @auth.has_access(
+        [
+            (permissions.ACTION_CAN_CREATE, permissions.RESOURCE_CONNECTION),
+        ]
+    )
+    def action_mulcopy(self, connections, session=None):
+        """Copy multiple connections"""
+        for selected_con in connections:

Review comment:
       It might make sense to change `selected_con` to `selected_conn` since 
'connection' is abbreviated as 'conn' in the rest of your code.

##########
File path: tests/www/test_views.py
##########
@@ -254,6 +254,66 @@ def test_prefill_form_null_extra(self):
         cmv.prefill_form(form=mock_form, pk=1)
 
 
+class TestCopyConnectionModelView(TestBase):

Review comment:
       You may want to add `Multi` to this class name to clarify what this is 
testing




----------------------------------------------------------------
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