Best Python code snippet using Kiwi_python
test_copy_move.py
Source:test_copy_move.py  
...63            status, response = await self.get('http://localhost:8080/vospace/nodes/root1/test2',64                                              params=params)65            self.assertEqual(200, status, msg=response)66            node = Node.fromstring(response)67            node.remove_property('ivo://ivoa.net/vospace/core#length')68            node.remove_property('ivo://ivoa.net/vospace/core#btime')69            node.remove_property('ivo://ivoa.net/vospace/core#ctime')70            node.remove_property('ivo://ivoa.net/vospace/core#mtime')71            node.remove_property('ivo://icrar.org/vospace/core#statfs')72            orig_node = ContainerNode('/root1/test2',73                                      properties=properties,74                                      nodes=[ContainerNode('/root1/test2/test3'),75                                             ContainerNode('/root1/test2/test4')])76            self.assertEqual(node, orig_node)77            params = {'detail': 'max'}78            status, response = await self.get('http://localhost:8080/vospace/nodes/root2',79                                              params=params)80            self.assertEqual(200, status, msg=response)81            node = Node.fromstring(response)82            node.remove_property('ivo://ivoa.net/vospace/core#length')83            node.remove_property('ivo://ivoa.net/vospace/core#btime')84            node.remove_property('ivo://ivoa.net/vospace/core#ctime')85            node.remove_property('ivo://ivoa.net/vospace/core#mtime')86            node.remove_property('ivo://icrar.org/vospace/core#statfs')87            orig_node = ContainerNode('/root2')88            self.assertEqual(node, orig_node)89            # Move tree from node1 to root290            mv = Move(ContainerNode('/root1/test2'), ContainerNode('/root2/test2'))91            job = await self.transfer_node(mv)92            await self.change_job_state(job.job_id, 'PHASE=RUN')93            await self.poll_job(job.job_id, expected_status='COMPLETED')94            # Check tree has been moved from node1 to root295            params = {'detail': 'max'}96            status, response = await self.get('http://localhost:8080/vospace/nodes/root2/test2',97                                              params=params)98            self.assertEqual(200, status, msg=response)99            node = Node.fromstring(response)100            node.remove_property('ivo://ivoa.net/vospace/core#length')101            node.remove_property('ivo://ivoa.net/vospace/core#btime')102            node.remove_property('ivo://ivoa.net/vospace/core#ctime')103            node.remove_property('ivo://ivoa.net/vospace/core#mtime')104            node.remove_property('ivo://icrar.org/vospace/core#statfs')105            moved_node = ContainerNode('/root2/test2',106                                       properties=properties,107                                       nodes=[ContainerNode('/root2/test2/test3'),108                                              ContainerNode('/root2/test2/test4')])109            self.assertEqual(node, moved_node)110            params = {'detail': 'max'}111            status, response = await self.get('http://localhost:8080/vospace/nodes/root1',112                                              params=params)113            self.assertEqual(200, status, msg=response)114            node = Node.fromstring(response)115            node.remove_property('ivo://ivoa.net/vospace/core#length')116            node.remove_property('ivo://ivoa.net/vospace/core#btime')117            node.remove_property('ivo://ivoa.net/vospace/core#ctime')118            node.remove_property('ivo://ivoa.net/vospace/core#mtime')119            node.remove_property('ivo://icrar.org/vospace/core#statfs')120            orig_node = ContainerNode('/root1')121            self.assertEqual(node, orig_node)122        self.loop.run_until_complete(run())123    def test_move_to_existing_child_node(self):124        async def run():125            node1 = ContainerNode('/data1')126            node3 = ContainerNode('/data3')127            node12 = Node('/data1/data2')128            node32 = Node('/data3/data2')129            await self.create_node(node1)130            await self.create_node(node3)131            await self.create_node(node12)132            await self.create_node(node32)133            mv = Move(node12, node3)134            job = await self.transfer_node(mv)135            await self.change_job_state(job.job_id, 'PHASE=RUN')136            await self.poll_job(job.job_id, expected_status='ERROR')137            await self.get_error_summary(job.job_id, error_contains='Duplicate')138        self.loop.run_until_complete(run())139    def test_rename_node(self):140        async def run():141            node0 = Node('/data0')142            await self.create_node(node0)143            mv = Move(Node('/data0'), Node('/newnode'))144            job = await self.transfer_node(mv)145            await self.change_job_state(job.job_id, 'PHASE=RUN')146            await self.poll_job(job.job_id, expected_status='COMPLETED')147            mv = Move(Node('/newnode'), Node('/newnode/newnode'))148            job = await self.transfer_node(mv)149            await self.change_job_state(job.job_id, 'PHASE=RUN')150            await self.poll_job(job.job_id, expected_status='ERROR')151            node0 = ContainerNode('/data0')152            await self.create_node(node0)153            mv = Move(Node('/newnode'), Node('/data0/newnode'))154            job = await self.transfer_node(mv)155            await self.change_job_state(job.job_id, 'PHASE=RUN')156            await self.poll_job(job.job_id, expected_status='COMPLETED')157        self.loop.run_until_complete(run())158    def test_invalid_copy_move(self):159        async def run():160            node0 = Node('/data0')161            node1 = ContainerNode('/data1')162            node2 = ContainerNode('/data2')163            node3 = ContainerNode('/data1/data4')164            node4 = Node('/data2/data4')165            # create nodes for invalid tests166            await self.create_node(node0)167            await self.create_node(node1)168            await self.create_node(node2)169            await self.create_node(node3)170            await self.create_node(node4)171            # Invalid Jobid172            await self.change_job_state(1234, 'PHASE=RUN', expected_status=400)173            # Source node doesn't exist174            mv = Move(Node('/data11'), node2)175            job = await self.transfer_node(mv)176            await self.change_job_state(job.job_id, 'PHASE=RUN')177            await self.poll_job(job.job_id, expected_status='ERROR')178            await self.get_error_summary(job.job_id, "Node Not Found")179            # Destination node doesn't exist180            mv = Move(Node('/data0'), ContainerNode('/doesnotexist/data0'))181            job = await self.transfer_node(mv)182            await self.change_job_state(job.job_id, 'PHASE=RUN')183            await self.poll_job(job.job_id, expected_status='ERROR')184            await self.get_error_summary(job.job_id, "Node Not Found")185            # move node1 -> node2186            mv = Move(node1, node2)187            job = await self.transfer_node(mv)188            # Invalid Phase189            await self.change_job_state(job.job_id, 'PHASE=STOP', expected_status=400)190            # delete node before move191            await self.delete('http://localhost:8080/vospace/nodes/data1')192            # start move job193            await self.change_job_state(job.job_id, 'PHASE=RUN')194            await self.poll_job(job.job_id, expected_status='ERROR')195            # Check error, node should not exist196            await self.get_error_summary(job.job_id, "Node Not Found")197            # Create the deleted node from previous test198            await self.create_node(node1)199            # Invalid move to a non-container200            mv = Move(node1, node0)201            job = await self.transfer_node(mv)202            await self.change_job_state(job.job_id, 'PHASE=RUN')203            await self.poll_job(job.job_id, expected_status='ERROR')204            await self.get_error_summary(job.job_id, error_contains='Duplicate Node')205            # Invalid move if node already exists in destination tree206            await self.create_node(node3)207            mv = Move(node3, node2)208            job = await self.transfer_node(mv)209            await self.change_job_state(job.job_id, 'PHASE=RUN')210            await self.poll_job(job.job_id, expected_status='ERROR')211            await self.get_error_summary(job.job_id, error_contains='Duplicate Node')212            # Move parent to child which should be invalid because node1 is node3s parent213            mv = Move(node1, node3)214            job = await self.transfer_node(mv)215            await self.change_job_state(job.job_id, 'PHASE=RUN')216            await self.poll_job(job.job_id, expected_status='ERROR')217            await self.get_error_summary(job.job_id, error_contains='Invalid URI.')218        self.loop.run_until_complete(run())219    def test_copy_node(self):220        async def run():221            root1 = ContainerNode('/root3')222            await self.create_node(root1)223            root2 = ContainerNode('/root4')224            await self.create_node(root2)225            properties = [Property('ivo://ivoa.net/vospace/core#title', "Test1", True),226                          Property('ivo://ivoa.net/vospace/core#description', "Test2", True)]227            node1 = ContainerNode('/root3/test1', properties=properties)228            await self.create_node(node1)229            properties1 = [Property('ivo://ivoa.net/vospace/core#title', "Hello", True),230                           Property('ivo://ivoa.net/vospace/core#description', "There", True)]231            node2 = Node('/root3/test1/test2', properties=properties1)232            await self.create_node(node2)233            # Copy tree from node1 to root2234            mv = Copy(ContainerNode('/root3/test1'), ContainerNode('/root4/test1'))235            job = await self.transfer_node(mv)236            await self.change_job_state(job.job_id, 'PHASE=RUN')237            await self.poll_job(job.job_id, expected_status='COMPLETED')238            # Just chek there isn't any transfer details for a move or copy239            await self.get_transfer_details(job.job_id, expected_status=400)240            # Check tree has been moved from node1 to root2241            params = {'detail': 'max'}242            node = await self.get_node('root4/test1', params)243            copy_node = ContainerNode('/root4/test1',244                                      properties=properties,245                                      nodes=[Node('/root4/test1/test2')])246            node.remove_property('ivo://ivoa.net/vospace/core#length')247            node.remove_property('ivo://ivoa.net/vospace/core#btime')248            node.remove_property('ivo://ivoa.net/vospace/core#ctime')249            node.remove_property('ivo://ivoa.net/vospace/core#mtime')250            node.remove_property('ivo://icrar.org/vospace/core#statfs')251            self.assertEqual(node, copy_node)252            # check original node is still there253            params = {'detail': 'max'}254            node = await self.get_node('root3/test1', params)255            orig_node = ContainerNode('/root3/test1',256                                      properties=properties,257                                      nodes=[Node('/root3/test1/test2')])258            node.remove_property('ivo://ivoa.net/vospace/core#length')259            node.remove_property('ivo://ivoa.net/vospace/core#btime')260            node.remove_property('ivo://ivoa.net/vospace/core#ctime')261            node.remove_property('ivo://ivoa.net/vospace/core#mtime')262            node.remove_property('ivo://icrar.org/vospace/core#statfs')263            self.assertEqual(node, orig_node)264        self.loop.run_until_complete(run())265if __name__ == '__main__':...urls.py
Source:urls.py  
1from django.urls import path2from .views import index, properties, search, landlord, property_detail, login, sign_up, logout, edit_property, add_property, remove_property3urlpatterns = [4    path('index/', index, name="index"),5    path('properties/', properties, name="properties"),6    path('properties/<int:id>/', property_detail, name="property"),7    path('search_results/', search, name="search"),8    path('landlord/', landlord, name="landlord"),9    path('', login, name="login"),10    path('sign_up/', sign_up, name="sign_up"),11    path('logout/', logout, name = "logout"),12    path('edit_property/<slug:id>/', edit_property, name="edit_property"),13    path('create_property/', add_property, name="create_property"),14    path('remove_property/<slug:id>/', remove_property, name="remove_property"),...remove_property.py
Source:remove_property.py  
...6    'POST',7    'http://purl.org/la/dp/remove_property',8    'remove_property',9    'application/json')10def remove_property(11        body,12        ctype,13        prop,14        action="remove_property",15        ):16    try:17        data = json.loads(body)18    except Exception, err:19        response.code = 50020        response.add_header('content-type', 'text/plain')21        return "Unable to parse body as JSON: " + str(err)22    delprop(data, prop, True)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
