forked from wikimedia/pywikibot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoreferences_tests.py
executable file
·45 lines (36 loc) · 1.33 KB
/
noreferences_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
"""Test noreferences bot module."""
#
# (C) Pywikibot team, 2018-2022
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations
import pywikibot
from scripts.noreferences import NoReferencesBot
from tests.aspects import TestCase, unittest
class TestAddingReferences(TestCase):
"""Test adding references to section."""
family = 'wikipedia'
code = 'cs'
def test_add(self):
"""Test adding references section."""
page = pywikibot.Page(self.site, 'foo')
bot = NoReferencesBot()
bot.site = self.site
page.text = '\n== Reference ==\n* [http://www.baz.org Baz]'
new_text = bot.addReferences(page.text)
expected = ('\n== Reference ==\n<references />'
'\n\n* [http://www.baz.org Baz]')
self.assertEqual(new_text, expected)
def test_add_under_templates(self):
"""Test adding references section under templates in section."""
page = pywikibot.Page(self.site, 'foo')
bot = NoReferencesBot()
bot.site = self.site
page.text = '\n== Reference ==\n{{Překlad|en|Baz|123456}}'
new_text = bot.addReferences(page.text)
expected = page.text + '\n<references />\n'
self.assertEqual(new_text, expected)
if __name__ == '__main__':
unittest.main()