Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add disabled task type unit test
Signed-off-by: Jana Peper <[email protected]>
  • Loading branch information
janepie committed Dec 18, 2024
commit 129af480acf167cc02d806445d5b871ee590f9e1
31 changes: 24 additions & 7 deletions tests/lib/TaskProcessing/TaskProcessingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public function getOptionalOutputShapeEnumValues(): array {
}
}



class FailingSyncProvider implements IProvider, ISynchronousProvider {
public const ERROR_MESSAGE = 'Failure';
public function getId(): string {
Expand Down Expand Up @@ -387,6 +389,7 @@ public function getExpectedRuntime(): int {
*/
class TaskProcessingTest extends \Test\TestCase {
private IManager $manager;
private IManager $disabledTypeManager;
private Coordinator $coordinator;
private array $providers;
private IServerContainer $serverContainer;
Expand All @@ -396,6 +399,7 @@ class TaskProcessingTest extends \Test\TestCase {
private IJobList $jobList;
private IUserMountCache $userMountCache;
private IRootFolder $rootFolder;
private IConfig $config;

public const TEST_USER = 'testuser';

Expand Down Expand Up @@ -442,11 +446,6 @@ protected function setUp(): void {
$this->jobList->expects($this->any())->method('add')->willReturnCallback(function () {
});

$config = $this->createMock(IConfig::class);
$config->method('getAppValue')
->with('core', 'ai.textprocessing_provider_preferences', '')
->willReturn('');

$this->eventDispatcher = $this->createMock(IEventDispatcher::class);

$text2imageManager = new \OC\TextToImage\Manager(
Expand All @@ -460,9 +459,9 @@ protected function setUp(): void {
);

$this->userMountCache = $this->createMock(IUserMountCache::class);

$this->config = \OC::$server->get(IConfig::class);
$this->manager = new Manager(
\OC::$server->get(IConfig::class),
$this->config,
$this->coordinator,
$this->serverContainer,
\OC::$server->get(LoggerInterface::class),
Expand Down Expand Up @@ -492,7 +491,25 @@ public function testShouldNotHaveAnyProviders(): void {
$this->manager->scheduleTask(new Task(TextToText::ID, ['input' => 'Hello'], 'test', null));
}

public function testProviderShouldBeRegisteredAndTaskTypeDisabled(): void {
$this->registrationContext->expects($this->any())->method('getTaskProcessingProviders')->willReturn([
new ServiceRegistration('test', SuccessfulSyncProvider::class)
]);
$taskProcessingTypeSettings = [
TextToText::ID => false,
];
$this->config->setAppValue('core', 'ai.taskprocessing_type_preferences', json_encode($taskProcessingTypeSettings));
$context = $this->coordinator->getRegistrationContext();
self::assertCount(0, $this->manager->getAvailableTaskTypes());
self::assertCount(1, $this->manager->getAvailableTaskTypes(true));
self::assertTrue($this->manager->hasProviders());
self::expectException(\OCP\TaskProcessing\Exception\PreConditionNotMetException::class);
$this->manager->scheduleTask(new Task(TextToText::ID, ['input' => 'Hello'], 'test', null));
}


public function testProviderShouldBeRegisteredAndTaskFailValidation(): void {
$this->config->setAppValue('core', 'ai.taskprocessing_type_preferences', '');
$this->registrationContext->expects($this->any())->method('getTaskProcessingProviders')->willReturn([
new ServiceRegistration('test', BrokenSyncProvider::class)
]);
Expand Down