mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
run tests on commit
This commit is contained in:
parent
445ca84834
commit
76df656128
8 changed files with 18 additions and 17 deletions
0
tests/data/__init__.py
Normal file
0
tests/data/__init__.py
Normal file
32
tests/data/test_regexes.py
Normal file
32
tests/data/test_regexes.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from data import regexes
|
||||
import re
|
||||
import unittest
|
||||
|
||||
|
||||
class TestRegexes(unittest.TestCase):
|
||||
def test_contains(self):
|
||||
pattern = {"pattern": "ABC123"}
|
||||
|
||||
self.assertTrue(regexes.contains("ABC123TESTSTRING", pattern)) # Beginning
|
||||
self.assertTrue(regexes.contains("TESTABC123STRING", pattern)) # Middle
|
||||
self.assertTrue(regexes.contains("TESTSTRINGABC123", pattern)) # End
|
||||
self.assertTrue(regexes.contains("ABC123", pattern)) # Entire string
|
||||
|
||||
self.assertFalse(regexes.contains("aBC123TESTSTRING", pattern)) # Wrong casing
|
||||
self.assertFalse(regexes.contains("SOMETHING ELSE", pattern)) # No match
|
||||
|
||||
# Add case insensitive flag
|
||||
pattern["flags"] = re.IGNORECASE
|
||||
self.assertTrue(regexes.contains("aBC123TESTSTRING", pattern)) # Incorrect casing should now pass
|
||||
|
||||
def test_steam_codes(self):
|
||||
self.assertTrue(regexes.contains("AAAAA-BBBBB-CCCCC", regexes.STEAM_CODE)) # Only letters
|
||||
self.assertTrue(regexes.contains("11111-22222-33333", regexes.STEAM_CODE)) # Only numbers
|
||||
self.assertTrue(regexes.contains("ABC12-34DEF-GHI56", regexes.STEAM_CODE)) # Both
|
||||
self.assertTrue(regexes.contains("abcde-fghij-lmnop", regexes.STEAM_CODE)) # Case insensitive flag
|
||||
self.assertTrue(regexes.contains("AAAAAA-BBBBB-CCCCC", regexes.STEAM_CODE)) # Extra characters can be in front
|
||||
|
||||
self.assertFalse(regexes.contains("A-BBBBB-CCCCC", regexes.STEAM_CODE)) # First group is too small
|
||||
self.assertFalse(regexes.contains("AAAAA-BBBBBB-CCCCC", regexes.STEAM_CODE)) # Second group is too big
|
||||
self.assertFalse(regexes.contains("AA??A-#ù$B6-!ÈCMa", regexes.STEAM_CODE)) # Invalid characters
|
||||
self.assertFalse(regexes.contains("Something something communism", regexes.STEAM_CODE)) # Random string
|
||||
18
tests/data/test_schedule.py
Normal file
18
tests/data/test_schedule.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from data import schedule
|
||||
from datetime import datetime
|
||||
import pytz
|
||||
import unittest
|
||||
|
||||
|
||||
class TestSchedule(unittest.TestCase):
|
||||
def test_holiday_has_passed(self):
|
||||
tz = pytz.timezone("Europe/Brussels")
|
||||
before = datetime(2020, 8, 8, tzinfo=tz)
|
||||
during = datetime(2021, 6, 2, tzinfo=tz)
|
||||
after = datetime(2021, 8, 8, tzinfo=tz)
|
||||
|
||||
holiday = schedule.Holiday([1, 6, 2021], [2, 7, 2021])
|
||||
|
||||
self.assertFalse(holiday.has_passed(before))
|
||||
self.assertFalse(holiday.has_passed(during))
|
||||
self.assertTrue(holiday.has_passed(after))
|
||||
27
tests/data/test_snipe.py
Normal file
27
tests/data/test_snipe.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from data.snipe import should_snipe
|
||||
import unittest
|
||||
from unittest.mock import Mock
|
||||
|
||||
|
||||
class TestSnipe(unittest.TestCase):
|
||||
def test_should_snipe(self):
|
||||
mock_message = Mock()
|
||||
mock_guild = Mock()
|
||||
mock_author = Mock()
|
||||
|
||||
# Guild is None
|
||||
mock_message.guild = None
|
||||
self.assertFalse(should_snipe(mock_message))
|
||||
mock_message.guild = mock_guild
|
||||
|
||||
# Author is a bot
|
||||
mock_message.author = mock_author
|
||||
mock_author.bot = True
|
||||
self.assertFalse(should_snipe(mock_message))
|
||||
mock_author.bot = False
|
||||
|
||||
mock_message.content = "Some string that contains A123B-CE68S-Z6B34 a Steam code"
|
||||
self.assertFalse(should_snipe(mock_message))
|
||||
|
||||
mock_message.content = "Some string that does NOT contain a Steam code"
|
||||
self.assertTrue(should_snipe(mock_message))
|
||||
Loading…
Add table
Add a link
Reference in a new issue