コード例 #1
0
    def test_validate_and_prepare_peer_sync_job__authentication_failed(
        self,
        get_dataset_id,
        get_client_and_server_certs,
        NetworkClient,
        MorangoProfileController,
    ):
        req = Mock(
            spec=Request,
            data=dict(
                facility=123,
                baseurl="https://some.server.test/extra/stuff",
                username="******",
                password="******",
            ),
        )

        client = NetworkClient.return_value
        client.base_url = "https://some.server.test/"

        network_connection = Mock()
        controller = MorangoProfileController.return_value
        controller.create_network_connection.return_value = network_connection

        get_dataset_id.return_value = 456
        get_client_and_server_certs.side_effect = CommandError()

        with self.assertRaises(AuthenticationFailed):
            validate_and_prepare_peer_sync_job(
                req, extra_metadata=dict(type="test"))
コード例 #2
0
    def test_validate_and_prepare_peer_sync_job__no_baseurl(self):
        req = Mock(
            spec=Request,
            data=dict(facility=123, ),
        )

        with self.assertRaises(ParseError, msg="Missing `baseurl` parameter"):
            validate_and_prepare_peer_sync_job(req)
コード例 #3
0
    def test_validate_and_prepare_peer_sync_job__cannot_connect(
            self, NetworkClient):
        req = Mock(spec=Request,
                   data=dict(facility=123,
                             baseurl="https://www.notfound.never"))

        NetworkClient.side_effect = NetworkLocationNotFound()

        with self.assertRaises(ResourceGoneError):
            validate_and_prepare_peer_sync_job(req)
コード例 #4
0
    def test_validate_and_prepare_peer_sync_job__bad_url(self):
        req = Mock(
            spec=Request,
            data=dict(
                facility=123,
                baseurl="/com.bad.url.www//:sptth",
            ),
        )

        with self.assertRaises(ParseError, msg="Invalid URL"):
            validate_and_prepare_peer_sync_job(req)
コード例 #5
0
    def test_validate_and_prepare_peer_sync_job(
        self,
        get_dataset_id,
        get_client_and_server_certs,
        NetworkClient,
        MorangoProfileController,
    ):
        dataset_id = 456
        req = Mock(
            spec=Request,
            data=dict(
                facility=123,
                baseurl="https://some.server.test/extra/stuff",
                username="******",
                password="******",
            ),
        )

        client = NetworkClient.return_value
        client.base_url = "https://some.server.test/"

        network_connection = Mock()
        controller = MorangoProfileController.return_value
        controller.create_network_connection.return_value = network_connection

        get_dataset_id.return_value = dataset_id
        get_client_and_server_certs.return_value = None

        expected = dict(
            baseurl="https://some.server.test/",
            facility=123,
            chunk_size=200,
            noninteractive=True,
            track_progress=True,
            cancellable=False,
            extra_metadata=dict(type="test"),
        )
        actual = validate_and_prepare_peer_sync_job(
            req, extra_metadata=dict(type="test"))
        self.assertEqual(expected, actual)

        MorangoProfileController.assert_called_with(PROFILE_FACILITY_DATA)
        controller.create_network_connection.assert_called_with(
            "https://some.server.test/")

        get_dataset_id.assert_called_with("https://some.server.test/",
                                          identifier=123,
                                          noninteractive=True)

        get_client_and_server_certs.assert_called_with("tester",
                                                       "mypassword",
                                                       dataset_id,
                                                       network_connection,
                                                       noninteractive=True)