Exemple #1
0
    def test_update(self):
        node = Node(ElementTree.fromstring(NODE_XML))

        resp = Mock()
        resp.headers.get = Mock(return_value="https://www.canfar.phys.uvic.ca/vospace")

        client = Client()
        client.get_node_url = Mock(return_value='https://www.canfar.phys.uvic.ca/vospace')
        client.conn = Mock()
        client.conn.session.post = Mock(return_value=resp)
        client.get_transfer_error = Mock()
        client.protocol = 'https'

        data = str(node)
        property_url = 'https://www.canfar.phys.uvic.ca/vospace/nodeprops'
        result = client.update(node, False)
        self.assertEqual(result, 0)
        client.conn.session.post.assert_called_with('https://www.canfar.phys.uvic.ca/vospace',
                                                      data=data, allow_redirects=False)

        call1 = call(property_url, allow_redirects=False, data=data,
                     headers={'Content-type': 'text/xml'})
        call2 = call('https://www.canfar.phys.uvic.ca/vospace/phase', allow_redirects=False, data="PHASE=RUN",
                     headers={'Content-type': "text/text"})
        calls = [call1, call2]

        client.conn = Mock()
        client.conn.session.post = Mock(return_value=resp)
        with patch('vos.vos.EndPoints.properties', property_url):
            result = client.update(node, True)
        self.assertEqual(result, 0)
        client.conn.session.post.assert_has_calls(calls)
Exemple #2
0
    def test_transfer_error(self, mock_vofile):
        vofile = MagicMock()
        mock_vofile.return_value = vofile

        vospace_url = 'https://somevospace.server/vospace'
        session = Mock()
        session.get.side_effect = [Mock(content='COMPLETED')]
        conn = Mock(spec=Connection)
        conn.session = session

        test_client = Client()

        # use the mocked connection instead of the real one
        test_client.conn = conn

        # job successfully completed
        vofile.read.side_effect = [b'QUEUED', b'COMPLETED']
        self.assertFalse(test_client.get_transfer_error(
            vospace_url + '/results/transferDetails', 'vos://vospace'))
        session.get.assert_called_once_with(vospace_url + '/phase',
                                            allow_redirects=False)

        # job suspended
        session.reset_mock()
        session.get.side_effect = [Mock(content=b'COMPLETED')]
        vofile.read.side_effect = [b'QUEUED', b'SUSPENDED']
        with self.assertRaises(OSError):
            test_client.get_transfer_error(
                vospace_url + '/results/transferDetails', 'vos://vospace')
        # check arguments for session.get calls
        self.assertEquals(
            [call(vospace_url + '/phase', allow_redirects=False)],
            session.get.call_args_list)

        # job encountered an internal error
        session.reset_mock()
        vofile.read.side_effect = Mock(side_effect=[b'QUEUED', b'ERROR'])
        session.get.side_effect = [Mock(content=b'COMPLETED'),
                                   Mock(text='InternalFault')]
        with self.assertRaises(OSError):
            test_client.get_transfer_error(
                vospace_url + '/results/transferDetails', 'vos://vospace')
        self.assertEquals([call(vospace_url + '/phase', allow_redirects=False),
                           call(vospace_url + '/error')],
                          session.get.call_args_list)

        # job encountered an unsupported link error
        session.reset_mock()
        link_file = 'testlink.fits'
        vofile.read.side_effect = Mock(side_effect=[b'QUEUED', b'ERROR'])
        session.get.side_effect = [Mock(content=b'COMPLETED'),
                                   Mock(
                                       text="Unsupported link target: " +
                                            link_file)]
        self.assertEquals(link_file, test_client.get_transfer_error(
            vospace_url + '/results/transferDetails', 'vos://vospace'))
        self.assertEquals([call(vospace_url + '/phase', allow_redirects=False),
                           call(vospace_url + '/error')],
                          session.get.call_args_list)
Exemple #3
0
    def test_transfer_error(self, mock_vofile):
        vofile = MagicMock()
        mock_vofile.return_value = vofile

        vospace_url = 'https://somevospace.server/vospace'
        session = Mock()
        session.get.side_effect = [Mock(content='COMPLETED')] 
        conn = Mock(spec=Connection)
        conn.session = session

        test_client = Client()

        # use the mocked connection instead of the real one
        test_client.conn = conn
        
        # job successfully completed
        vofile.read.side_effect = [b'QUEUED', b'COMPLETED']
        self.assertFalse(test_client.get_transfer_error(
                vospace_url +'/results/transferDetails', 'vos://vospace'))
        session.get.assert_called_once_with(vospace_url + '/phase', allow_redirects=False)
        
        # job suspended
        session.reset_mock()
        session.get.side_effect = [Mock(content=b'COMPLETED')]
        vofile.read.side_effect = [b'QUEUED', b'SUSPENDED']
        with self.assertRaises(OSError):
            test_client.get_transfer_error(
                vospace_url +'/results/transferDetails', 'vos://vospace')
        #check arguments for session.get calls
        self.assertEquals([call(vospace_url + '/phase', allow_redirects=False)], 
                          session.get.call_args_list )

        # job encountered an internal error
        session.reset_mock()
        vofile.read.side_effect = Mock(side_effect=[b'QUEUED', b'ERROR'])
        session.get.side_effect = [Mock(content=b'COMPLETED'), Mock(text='InternalFault')]
        with self.assertRaises(OSError):
            test_client.get_transfer_error(
                vospace_url +'/results/transferDetails', 'vos://vospace')
        self.assertEquals([call(vospace_url + '/phase', allow_redirects=False),
                           call(vospace_url + '/error')], 
                          session.get.call_args_list )

        # job encountered an unsupported link error
        session.reset_mock()
        link_file = 'testlink.fits'
        vofile.read.side_effect = Mock(side_effect=[b'QUEUED', b'ERROR'])
        session.get.side_effect = [Mock(content=b'COMPLETED'),
                                   Mock(text="Unsupported link target: " + link_file)]
        self.assertEquals(link_file, test_client.get_transfer_error(
            vospace_url +'/results/transferDetails', 'vos://vospace'))
        self.assertEquals([call(vospace_url + '/phase', allow_redirects=False),
                   call(vospace_url + '/error')], 
                  session.get.call_args_list )
Exemple #4
0
    def test_update(self):
        node = Node(ElementTree.fromstring(NODE_XML))

        resp = Mock()
        resp.headers.get = Mock(
            return_value="https://www.canfar.phys.uvic.ca/vospace")

        conn = Mock(spec=vos.Connection)
        conn.session.post = Mock(return_value=resp)
        client = Client(conn=conn)
        client.get_node_url = Mock(
            return_value='https://www.canfar.phys.uvic.ca/vospace')
        client.get_transfer_error = Mock()
        client.protocol = 'https'

        data = str(node)
        property_url = 'https://www.canfar.phys.uvic.ca/vospace/nodeprops'
        endpoints_mock = Mock()
        endpoints_mock.properties = property_url
        client.get_endpoints = Mock(return_value=endpoints_mock)
        result = client.update(node, False)
        self.assertEqual(result, 0)
        client.conn.session.post.assert_called_with(
            'https://www.canfar.phys.uvic.ca/vospace',
            data=data,
            allow_redirects=False)

        call1 = call(property_url,
                     allow_redirects=False,
                     data=data,
                     headers={'Content-type': 'text/xml'})
        call2 = call(
            'https://www.canfar.phys.uvic.ca/vospace/phase',
            allow_redirects=False,
            data="PHASE=RUN",
            headers={'Content-type': 'application/x-www-form-urlencoded'})
        calls = [call1, call2]

        client.conn = Mock(spec=vos.Connection)
        client.conn.session.post = Mock(return_value=resp)
        result = client.update(node, True)
        self.assertEqual(result, 0)
        client.conn.session.post.assert_has_calls(calls)
Exemple #5
0
    def test_update(self):
        node = Node(ElementTree.fromstring(NODE_XML))

        resp = Mock()
        resp.headers.get = Mock(
            return_value="https://www.canfar.phys.uvic.ca/vospace")

        conn = Mock(spec=vos.Connection)
        conn.session.post = Mock(return_value=resp)
        client = Client(conn=conn)
        client.get_node_url = Mock(
            return_value='https://www.canfar.phys.uvic.ca/vospace')
        client.get_transfer_error = Mock()
        client.protocol = 'https'

        data = str(node)
        property_url = 'https://www.canfar.phys.uvic.ca/vospace/nodeprops'
        endpoints_mock = Mock()
        endpoints_mock.properties = property_url
        client.get_endpoints = Mock(return_value=endpoints_mock)
        result = client.update(node, False)
        self.assertEqual(result, 0)
        client.conn.session.post.assert_called_with(
            'https://www.canfar.phys.uvic.ca/vospace',
            data=data, allow_redirects=False)

        call1 = call(property_url, allow_redirects=False, data=data,
                     headers={'Content-type': 'text/xml'})
        call2 = call('https://www.canfar.phys.uvic.ca/vospace/phase',
                     allow_redirects=False, data="PHASE=RUN",
                     headers={'Content-type': "text/text"})
        calls = [call1, call2]

        client.conn = Mock(spec=vos.Connection)
        client.conn.session.post = Mock(return_value=resp)
        result = client.update(node, True)
        self.assertEqual(result, 0)
        client.conn.session.post.assert_has_calls(calls)