Skip to content

Commit

Permalink
Fix breaking UT cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
CXuesong committed Oct 10, 2024
1 parent c4d525a commit 710ff72
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
6 changes: 3 additions & 3 deletions UnitTestProject1/Tests/GeneratorTests1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public async Task AllCategoriesGeneratorTest1(string siteName, int batches)
}

[Theory]
[InlineData(nameof(WpTest2SiteAsync), "Category:Template documentation pages‏")]
[InlineData(nameof(WikiaTestSiteAsync), "BlogListingPage‏‎‏")]
[InlineData(nameof(TFWikiSiteAsync), "Category:Autobot subgroups‏")]
[InlineData(nameof(WpTest2SiteAsync), "Category:Template documentation pages‏")]
[InlineData(nameof(WikiaTestSiteAsync), "Free wiki software")]
[InlineData(nameof(TFWikiSiteAsync), "Category:Autobot subgroups‏")]
public async Task CategoryMembersGeneratorTest(string siteName, string categoryName)
{
var site = await WikiSiteFromNameAsync(siteName);
Expand Down
2 changes: 1 addition & 1 deletion UnitTestProject1/Tests/PageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task WpEnPageReadTest1()

[Theory]
[InlineData(nameof(WpTest2SiteAsync), "Project:sandbox", "Wikipedia:Sandbox", BuiltInNamespaces.Project, 2076)]
[InlineData(nameof(WikiaTestSiteAsync), "Project:sandbox", "Discussion Manual Wiki:Sandbox", BuiltInNamespaces.Project, 637)]
[InlineData(nameof(WikiaTestSiteAsync), "Project:sandbox", "DMan Ⅱ Wiki:Sandbox", BuiltInNamespaces.Project, 149)]
[InlineData(nameof(TFWikiSiteAsync), "Help:coming soon", "Help:Coming soon", BuiltInNamespaces.Help, 10122)]
public async Task WikiPageReadTest2(string siteName, string fetchTitle, string expectedTitle, int expectedNs, int expectedId)
{
Expand Down
12 changes: 6 additions & 6 deletions UnitTestProject1/Tests/SiteTokenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public SiteTokenTests(ITestOutputHelper output, WikiSiteProvider wikiSiteProvide
SiteNeedsLogin(Endpoints.TFWiki);
}

[SkippableTheory]
[InlineData(nameof(WpTest2SiteAsync))]
[InlineData(nameof(WikiaTestSiteAsync))]
[InlineData(nameof(TFWikiSiteAsync))]
public async Task TokenTest(string testSiteName)
[Theory]
[InlineData(nameof(WpTest2SiteAsync), new[] { "edit", "move", "patrol" })]
[InlineData(nameof(WikiaTestSiteAsync), new[] { "edit", "move", "patrol" })]
[InlineData(nameof(TFWikiSiteAsync), new[] { "edit", "patrol" })]
public async Task TokenTest(string testSiteName, string[] tokenTypes)
{
var site = await WikiSiteFromNameAsync(testSiteName);
foreach (var tokenType in new[] { "edit", "move", "patrol" })
foreach (var tokenType in tokenTypes)
{
// Fetch twice at a time...
var tokenValueTask1 = site.GetTokenAsync(tokenType);
Expand Down
8 changes: 4 additions & 4 deletions UnitTestProject1/Tests/WikiLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public async Task WikiLinkTest1()
[Fact]
public async Task TestMethod2()
{
var WikiaTestSite = await WikiaTestSiteAsync;
var link1 = WikiLink.Parse(WikiaTestSite, "__ _project_ _talk_:___sandbox_", BuiltInNamespaces.Category);
var link2 = WikiLink.Parse(WikiaTestSite, "part1:part2:part3", BuiltInNamespaces.Category);
Assert.Equal("Discussion Manual Wiki talk:Sandbox", link1.ToString());
var wikiaTestSite = await WikiaTestSiteAsync;
var link1 = WikiLink.Parse(wikiaTestSite, "__ _project_ _talk_:___sandbox_", BuiltInNamespaces.Category);
var link2 = WikiLink.Parse(wikiaTestSite, "part1:part2:part3", BuiltInNamespaces.Category);
Assert.Equal("DMan Ⅱ Wiki talk:Sandbox", link1.ToString());
Assert.Equal("Category:Part1:part2:part3", link2.ToString());
}

Expand Down
6 changes: 4 additions & 2 deletions WikiClientLibrary/Infrastructures/TokensManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task<string> GetTokenAsync(string tokenType, bool forceRefetch, Can
{
if (string.IsNullOrEmpty(tokenType))
throw new ArgumentException(Prompts.ExceptionArgumentNullOrEmpty, nameof(tokenType));
if (tokenType.Contains("|"))
if (tokenType.Contains('|'))
throw new ArgumentException(Prompts.ExceptionArgumentContainsPipe, nameof(tokenType));
cancellationToken.ThrowIfCancellationRequested();
tokenType = tokenType.Trim();
Expand All @@ -95,6 +95,8 @@ public async Task<string> GetTokenAsync(string tokenType, bool forceRefetch, Can
if (site.SiteInfo.Version < v117 && tokenType == "patrol")
realTokenType = "edit";
// Use csrf token if possible.
// https://www.mediawiki.org/wiki/MediaWiki_1.37/Deprecation_of_legacy_API_token_parameters
// https://github.com/wikimedia/mediawiki/blob/1.19.10/includes/api/ApiQueryInfo.php
if (site.SiteInfo.Version >= v124 && CsrfTokens.Contains(tokenType))
realTokenType = "csrf";
// Collect tokens from cache
Expand Down Expand Up @@ -156,7 +158,7 @@ string ExtractToken(IDictionary<string, JsonNode?> jTokens, string tokenType1)
}
var token = (string?)jtoken;
if (token == null)
throw new ArgumentException($"Invalid token type: {tokenType1}.", nameof(tokenType));
throw new ArgumentException($"Failed to extract {tokenType1} token from the API response.", nameof(tokenType));
return token;
}

Expand Down

0 comments on commit 710ff72

Please sign in to comment.