Skip to content

Commit

Permalink
Automatically determine forbidden word prefix to use
Browse files Browse the repository at this point in the history
  • Loading branch information
theotherp committed Nov 12, 2024
1 parent 711d0e8 commit bbfb010
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 16 additions & 2 deletions core/src/test/java/org/nzbhydra/indexers/NewznabTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,16 @@ public class NewznabTest {
SearchingConfig searchingConfigMock;
@Mock
private QueryGenerator queryGeneratorMock;
@Mock
private BaseConfigHandler configHandler;
Category animeCategory = new Category("anime");
Category naCategory = new Category("n/a");
Category otherCategory = new Category("other");
@Mock
private ConfigProvider configProviderMock;

@InjectMocks
private Newznab testee = new Newznab(configProviderMock, indexerRepositoryMock, searchResultRepositoryMock, indexerApiAccessRepositoryMock, shortRepositoryMock, null, indexerWebAccessMock, resultAcceptorMock,
categoryProviderMock, infoProviderMock, null, queryGeneratorMock, null, unmarshallerMock, null);
private Newznab testee;


@BeforeEach
Expand All @@ -145,6 +146,7 @@ public void setUp() throws Exception {
testee.config = new IndexerConfig();
testee.config.setSupportedSearchIds(Lists.newArrayList(MediaIdType.TMDB, MediaIdType.TVRAGE));
testee.config.setHost("http://127.0.0.1:1234");
testee.config.setForbiddenWordPrefix(IndexerConfig.ForbiddenWordPrefix.EXCLAMATION_MARK);
testee.indexer = indexerEntityMock;

baseConfig = new BaseConfig();
Expand Down Expand Up @@ -175,6 +177,7 @@ public String answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArgument(1);
}
});

}

@Test
Expand Down Expand Up @@ -411,6 +414,7 @@ void shouldNotConvertIdIfNotNecessary() throws Exception {

@Test
void shouldAddExcludedAndRequiredWordsToQuery() throws Exception {
testee.config.setForbiddenWordPrefix(IndexerConfig.ForbiddenWordPrefix.DOUBLE_DASH);
SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
searchRequest.setQuery("q");
searchRequest.getInternalData().setForbiddenWords(Lists.newArrayList("a", "b", "c"));
Expand All @@ -436,12 +440,22 @@ void shouldAddExcludedAndRequiredWordsToQuery() throws Exception {

@Test
void shoulNotdAddExcludedAndRequiredWordsWithSomeCharacters() throws Exception {
testee.config.setForbiddenWordPrefix(IndexerConfig.ForbiddenWordPrefix.DOUBLE_DASH);
SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
searchRequest.setQuery("q");
searchRequest.getInternalData().setForbiddenWords(Lists.newArrayList("a", "b b", "-c", "d.d"));
assertEquals(UriComponentsBuilder.fromHttpUrl("http://127.0.0.1:1234/api?t=search&extended=1&q=q --a&limit=1000").build(), buildCleanedSearchUrl(searchRequest, null, null).build());
}

@Test
void shoulNotdAddExcludedWordsWithExclamationMark() throws Exception {
testee.config.setForbiddenWordPrefix(IndexerConfig.ForbiddenWordPrefix.EXCLAMATION_MARK);
SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
searchRequest.setQuery("q");
searchRequest.getInternalData().setForbiddenWords(Lists.newArrayList("a", "b b", "-c", "d.d"));
assertEquals(UriComponentsBuilder.fromHttpUrl("http://127.0.0.1:1234/api?t=search&extended=1&q=q !a&limit=1000").build(), buildCleanedSearchUrl(searchRequest, null, null).build());
}

@Test
void shouldUseDifferentExclusionFormatForNzedbAndOmgWtf() throws Exception {
testee.config.setBackend(BackendType.NZEDB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.net.URI;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -117,6 +118,8 @@ void shouldCheckCaps() throws Exception {
.thenReturn(builder.getTestResult(1, 100, "Avengers", 0, 100));
when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=movie&imdbid=0848228"), indexerConfig))
.thenReturn(builder.getTestResult(1, 100, "Avengers", 0, 100));
when(indexerWebAccess.get(new URI("http://127.0.0.1:1234/api?apikey=apikey&t=search&q=Avengers%20--1080p"), indexerConfig, NewznabXmlRoot.class))
.thenReturn(builder.getTestResult(1, 100, "Avengers", 0, 100));

capsRoot.getSearching().setAudioSearch(new CapsXmlSearch("yes", "q"));

Expand All @@ -138,6 +141,7 @@ void shouldCheckCaps() throws Exception {
assertThat(checkCapsRespone.getIndexerConfig().getBackend()).isEqualTo(BackendType.NZEDB);

assertTrue(checkCapsRespone.isAllCapsChecked());
assertEquals(IndexerConfig.ForbiddenWordPrefix.DOUBLE_DASH, checkCapsRespone.getIndexerConfig().getForbiddenWordPrefix());

verify(indexerWebAccess, times(8)).get(any(), eq(indexerConfig));
}
Expand Down

0 comments on commit bbfb010

Please sign in to comment.