<commit_before><?php
namespace Keboola\Test\Common;

use Keboola\Csv\CsvFile;
use Keboola\StorageApi\Client;
use Keboola\StorageApi\Options\FileUploadOptions;
use Keboola\Test\StorageApiTestCase;

class QueueJobsTest extends StorageApiTestCase
{
    public function setUp()
    {
        parent::setUp();
        $this->_client->createBucket('test', Client::STAGE_IN);
        $this->_client->createTableAsync('in.c-test', 'table1', new CsvFile(__DIR__ . '/../_data/languages-headers.csv'));
    }

    public function tearDown()
    {
        parent::tearDown();
        $this->_client->dropBucket('in.c-test', ['force' => true]);
    }

    public function testQueueTableImportFromFile()
    {
        $fileId = $this->_client->uploadFile(__DIR__ . '/../_data/languages.csv', new FileUploadOptions());
        $jobId = $this->_client->queueTableImport('in.c-test.table1', ['dataFileId' => $fileId]);
        $job = $this->_client->getJob($jobId);
        $this->assertEquals('in.c-test.table1', $job['tableId']);
        $this->assertEquals('tableImport', $job['operationName']);
        $this->assertEquals($fileId, $job['operationParams']['source']['fileId']);
        $this->assertEquals('file', $job['operationParams']['source']['type']);
    }
}
<commit_msg>feat: test queue table import from workspace<commit_after><?php
namespace Keboola\Test\Common;

use Keboola\Csv\CsvFile;
use Keboola\StorageApi\Client;
use Keboola\StorageApi\Options\FileUploadOptions;
use Keboola\Test\StorageApiTestCase;

class QueueJobsTest extends StorageApiTestCase
{
    public function setUp()
    {
        parent::setUp();
        $this->_client->createBucket('test', Client::STAGE_IN);
        $this->_client->createTableAsync('in.c-test', 'table1', new CsvFile(__DIR__ . '/../_data/languages-headers.csv'));
    }

    public function tearDown()
    {
        parent::tearDown();
        $this->_client->dropBucket('in.c-test', ['force' => true]);
    }

    public function testQueueTableImportFromFile()
    {
        $fileId = $this->_client->uploadFile(__DIR__ . '/../_data/languages.csv', new FileUploadOptions());
        $jobId = $this->_client->queueTableImport('in.c-test.table1', ['dataFileId' => $fileId]);
        $job = $this->_client->getJob($jobId);
        $this->assertEquals('in.c-test.table1', $job['tableId']);
        $this->assertEquals('tableImport', $job['operationName']);
        $this->assertEquals($fileId, $job['operationParams']['source']['fileId']);
        $this->assertEquals('file', $job['operationParams']['source']['type']);
    }

    public function testQueueTableImportFromWorkspace()
    {
        $jobId = $this->_client->queueTableImport(
            'in.c-test.table1',
            [
                'dataWorkspaceId' => 'myWorkspace',
                'dataTableName' => 'myTable',
            ]
        );
        $job = $this->_client->getJob($jobId);
        $this->assertEquals('in.c-test.table1', $job['tableId']);
        $this->assertEquals('tableImport', $job['operationName']);
        $this->assertEquals('myWorkspace', $job['operationParams']['source']['workspaceId']);
        $this->assertEquals('myTable', $job['operationParams']['source']['tableName']);
        $this->assertEquals('workspace', $job['operationParams']['source']['type']);
    }
}

{'fraction_non_alphanumeric': 0.18653321201091902, 'fraction_numerical': 0.002426448286320898, 'mean_word_length': 3.619047619047619, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2338647', 'n_tokens_mistral': 995, 'n_tokens_neox': 993, 'n_words': 138}