Exemple #1
0
    def test_show_cluster_no_endpoint(self):
        """Ensure that the correct message is returned when a cluster is not set"""
        old_endpoint = get_mock_endpoint()

        set_mock_endpoint('')

        self.assertEqual(None, sf_c.show_connection())

        set_mock_endpoint(str(old_endpoint))
Exemple #2
0
    def test_show_cluster(self):
        """Ensure that the correct message is returned when a cluster is set"""
        old_endpoint = get_mock_endpoint()

        set_mock_endpoint('https://testUrl.com')

        self.assertEqual('https://testUrl.com', sf_c.show_connection())

        set_mock_endpoint(str(old_endpoint))
    def test_paths_generation(self):
        """ This test calls all commands that exist within sfctl.
        The commands are routed to a mock cluster which always returns
        success.We then read the values of the URL and other request
        features to determine that the command is working as expected
        (generating the correct URL). """

        # Set test URL path to that of our mock server
        set_mock_endpoint('http://localhost:' + str(self.port))

        # Call test
        self.paths_generation_helper()
Exemple #4
0
    def test_upload_image_store_timeout_overall(self):  #pylint: disable=invalid-name
        """
        Test to make sure that we end the overall upload process when it times out.

        Things we check for:
        - Where the timeout is not sufficient - too small for one file
            - Should get SFCTLInternalException
            - Manually make sure there is only one outgoing request with the correct timeout
              since it's hard to record the http request from another process.
        """

        # Doing patch here because patching outside of the function does not work
        with patch('sfctl.config.CLIConfig', new=MOCK_CONFIG):

            current_directory = os.path.dirname(os.path.realpath(__file__))
            # 4 files total in sample_nested_folders
            path_to_upload_file = os.path.join(current_directory,
                                               'sample_nested_folders')
            endpoint = 'http://localhost:' + str(self.port)
            set_mock_endpoint(endpoint)

            # Mock server will take 3 seconds to respond to each request, simulating
            # a large file.

            exception_triggered = False
            try:
                timeout = 2
                sf_c.upload(path_to_upload_file, timeout=timeout)
            except SFCTLInternalException as ex:
                self.assertIn(
                    'Upload has timed out. Consider passing a longer timeout duration.',
                    ex.message,
                    msg=
                    'Application upload to image store returned the incorrect timeout message'
                )
                exception_triggered = True
            # ConnectionResetError will be returned when the process cuts off, but we expect
            # upload to swallow that and return SFCTLInternalException

            self.assertTrue(exception_triggered,
                            msg='A timeout exception is expected during '
                            'application upload timeout test with '
                            'response time 2 on the server side. '
                            'And timeout 2 overall.')
Exemple #5
0
    def tearDownClass(cls):
        """A class method called after tests in an individual class have run"""

        set_mock_endpoint(cls.old_endpoint)
 def __exit__(self, exception_type, exception_value, traceback):
     # Revert the environment variables we changed during the test to what the user set.
     set_mock_endpoint(self.old_endpoint)