'Test that uploading with registry correctly uses trusts'

@mock.patch('glance.common.trust_auth.TokenRefresher')
def test_upload_with_trusts(self, mock_refresher):

    self.config(data_api='glance.db.registry.api')
    refresher = mock.MagicMock()
    mock_refresher.return_value = refresher
    refresher.refresh_token.return_value = 'fake_token'
    request = unit_test_utils.get_fake_request()
    request.environ['keystone.token_auth'] = mock.MagicMock()
    request.environ['keystone.token_info'] = {'token': {'roles': [{'name': 'FakeRole', 'id': 'FakeID'}]}}
    image = FakeImage('abcd')
    self.image_repo.result = image
    mock_fake_save = mock.Mock()
    mock_fake_save.side_effect = [None, exception.NotAuthenticated, None]
    temp_save = FakeImageRepo.save
    FakeImageRepo.save = mock_fake_save
    self.controller.upload(request, unit_test_utils.UUID2, 'YYYY', 4)
    self.assertEqual('YYYY', image.data)
    self.assertEqual(4, image.size)
    FakeImageRepo.save = temp_save
    mock_refresher.assert_called_once_with(request.environ['keystone.token_auth'], request.context.tenant, ['FakeRole'])
    refresher.refresh_token.assert_called_once_with()
    refresher.release_resources.assert_called_once_with()
    self.assertEqual('fake_token', request.context.auth_token)
