コード例 #1
0
    def test_ocp_route_file(self, mock_post):
        """Test that a response is good."""
        insights_user = os.environ.get('INSIGHTS_USER')
        insights_password = os.environ.get('INSIGHTS_PASSWORD')

        temp_file = NamedTemporaryFile(mode='w', delete=False)
        headers = ['col1', 'col2']
        data = [{
            'col1': 'r1c1',
            'col2': 'r1c2'
        }, {
            'col1': 'r2c1',
            'col2': 'r2c2'
        }]
        _write_csv(temp_file.name, data, headers)

        insights_upload = 'test'

        auth = (insights_user, insights_password)

        mock_post.return_value.status_code = 202
        ocp_route_file(insights_upload, temp_file.name)

        self.assertEqual(mock_post.call_args[1].get('auth'), auth)
        self.assertNotIn('headers', mock_post.call_args[1])
コード例 #2
0
    def test_post_payload_to_ingest_service_with_identity_header(
            self, mock_post):
        """Test that the identity header path is taken."""
        insights_account_id = os.environ.get('INSIGHTS_ACCOUNT_ID')
        insights_org_id = os.environ.get('INSIGHTS_ORG_ID')

        temp_file = NamedTemporaryFile(mode='w', delete=False)
        headers = ['col1', 'col2']
        data = [{
            'col1': 'r1c1',
            'col2': 'r1c2'
        }, {
            'col1': 'r2c1',
            'col2': 'r2c2'
        }]
        _write_csv(temp_file.name, data, headers)

        insights_upload = {}
        header = {
            'identity': {
                'account_number': insights_account_id,
                'internal': {
                    'org_id': insights_org_id
                }
            }
        }
        headers = {
            'x-rh-identity':
            base64.b64encode(json.dumps(header).encode('UTF-8'))
        }

        post_payload_to_ingest_service(insights_upload, temp_file.name)
        self.assertEqual(mock_post.call_args[1].get('headers'), headers)
        self.assertNotIn('auth', mock_post.call_args[1])
コード例 #3
0
 def test_write_csv(self):
     """Test the writing of the CSV data."""
     temp_file = NamedTemporaryFile(mode='w', delete=False)
     headers = ['col1', 'col2']
     data = [{
         'col1': 'r1c1',
         'col2': 'r1c2'
     }, {
         'col1': 'r2c1',
         'col2': 'r2c2'
     }]
     _write_csv(temp_file.name, data, headers)
     self.assertTrue(os.path.exists(temp_file.name))
     os.remove(temp_file.name)
コード例 #4
0
    def test_post_payload_to_ingest_service_with_basic_auth(self, mock_post):
        """Test that the identity header path is taken."""
        insights_user = os.environ.get('INSIGHTS_USER')
        insights_password = os.environ.get('INSIGHTS_PASSWORD')

        temp_file = NamedTemporaryFile(mode='w', delete=False)
        headers = ['col1', 'col2']
        data = [{
            'col1': 'r1c1',
            'col2': 'r1c2'
        }, {
            'col1': 'r2c1',
            'col2': 'r2c2'
        }]
        _write_csv(temp_file.name, data, headers)

        insights_upload = {}

        auth = (insights_user, insights_password)

        post_payload_to_ingest_service(insights_upload, temp_file.name)
        self.assertEqual(mock_post.call_args[1].get('auth'), auth)
        self.assertNotIn('headers', mock_post.call_args[1])