diff --git a/CLI/BackupFactUpdater/__main__.py b/CLI/BackupFactUpdater/__main__.py index a3d5c377..6a7120e7 100644 --- a/CLI/BackupFactUpdater/__main__.py +++ b/CLI/BackupFactUpdater/__main__.py @@ -37,7 +37,7 @@ # noinspection PyBroadException def run(): - + """Run the Backup Fact Updater""" dbconfig = { "user": config.get("Database", "user"), "password": config.get("Database", "password"), diff --git a/CLI/DSSAUpdater/__main__.py b/CLI/DSSAUpdater/__main__.py index ab122832..2379f5ee 100644 --- a/CLI/DSSAUpdater/__main__.py +++ b/CLI/DSSAUpdater/__main__.py @@ -36,7 +36,7 @@ def run(): - + """Run the DSSA Updater""" print( "=" * 20 + "\nCopyright (c) 2022 The Hull Seals\nDSSA file updater for HalpyBOT\n" diff --git a/halpybot/packages/announcer/announcer.py b/halpybot/packages/announcer/announcer.py index 955c7c99..45cb2cd4 100644 --- a/halpybot/packages/announcer/announcer.py +++ b/halpybot/packages/announcer/announcer.py @@ -75,9 +75,6 @@ def __init__(self, bot: Optional[pydle.Client] = None): content=anntype["Content"], ) - def rehash(self): - pass - async def announce(self, announcement: str, args: Dict): """Announce a new case diff --git a/tests/__init__.py b/tests/__init__.py index e69de29b..6aad20f5 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,11 @@ +""" +HalpyBOT v1.6 + +__init__.py - Initilization for HalpyBOT Tests + +Copyright (c) 2022 The Hull Seals, +All rights reserved. + +Licensed under the GNU General Public License +See license.md +""" diff --git a/tests/test_checks.py b/tests/test_checks.py index 429e9838..eedcef69 100644 --- a/tests/test_checks.py +++ b/tests/test_checks.py @@ -24,9 +24,9 @@ from halpybot.packages.models import User -# Do the levels line up with expected permissions? @pytest.mark.asyncio -async def test_config_write(): +async def test_permission_configs(): + """Test if levels match their expected returns""" levels = { (Pup, 1), (Drilled, 2), @@ -42,15 +42,16 @@ async def test_config_write(): @pytest.mark.asyncio async def test_permission_level_none(): + """Test if incorrectedly formatted VHOSTS return expected values""" vhost_tests = ["notaseal@abcdefg.hijklmnop", "this is garbage", "dQw4w9WgXcQ", None] for given_host in vhost_tests: vhost = User.process_vhost(given_host) assert vhost is None -# Check returned VHOST of user @pytest.mark.asyncio async def test_permission_level(): + """Test if VHOSTS return their expected values""" vhost_tests = { ("rixxan@rixxan.admin.hullseals.space", "rixxan.admin.hullseals.space"), ("seal@seal.cybersealmgr.hullseals.space", "cybersealmgr.hullseals.space"), @@ -67,12 +68,14 @@ async def test_permission_level(): @pytest.mark.asyncio async def test_permission_level_rix(): + """Test if special users VHOSTS are returned as expected""" vhost = User.process_vhost("rixxan.admin.hullseals.space") assert vhost == "rixxan.admin.hullseals.space" @pytest.mark.asyncio async def test_permission_level_comparisons(): + """Test that Permission Levels are sorted correctly""" assert ( Pup.level < Drilled.level diff --git a/tests/test_config.py b/tests/test_config.py index 5ed04862..c2fb452a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -16,15 +16,15 @@ from halpybot.packages.configmanager import config, config_write -# Does the Config file exist? def test_config_exists(): + """Test that the config file exists. Without it, you aren't getting far.""" config_file = os.path.exists("config/config.ini") assert config_file is True -# Check critical aspects for value @pytest.mark.asyncio async def test_config_value(): + """Test that critical values are in the config file.""" config_values = { # Essential if you are using NickServ/SASL "config['SASL']['username']", "config['SASL']['password']", @@ -60,9 +60,9 @@ async def test_config_value(): assert value is not None -# Can we write to the Config file? @pytest.mark.asyncio async def test_config_write(): + """Test that the config file is writable""" prev_value = config["IRC"]["usessl"] config_write("IRC", "usessl", "True") assert config["IRC"]["usessl"] == "True" diff --git a/tests/test_database.py b/tests/test_database.py index bb1a9225..e9d01e2a 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -16,10 +16,11 @@ from halpybot.packages.database import latency -# Test Database Latency -# If the latency is any greater than 15, the connection is unusable. @pytest.mark.asyncio async def test_latency(): + """Test the Database Latency. + + If it's above 15, the connection is unusable.""" start = time.time() connection = await latency() final = round(connection - start, 2) diff --git a/tests/test_delayed.py b/tests/test_delayed.py index 2db4513c..5a3a3c24 100644 --- a/tests/test_delayed.py +++ b/tests/test_delayed.py @@ -35,6 +35,7 @@ @pytest.mark.asyncio async def test_open(): + """Test that a delayed case can be opened""" global testID, curr_delayed curr_delayed = await DelayedCase.check() opened = await DelayedCase.open( @@ -46,24 +47,28 @@ async def test_open(): @pytest.mark.asyncio async def test_check(): + """Test that the number of delayed cases can be tested for""" checked_number = await DelayedCase.check() assert int(checked_number) > int(curr_delayed) @pytest.mark.asyncio async def test_close(): + """Test that a delayed case be closed""" closed = await DelayedCase.status(int(testID), 3, "HalpyBOT Test Library") assert closed[1] == 0 @pytest.mark.asyncio async def test_reopen(): + """Test that a delayed case can be reopened""" reopen = await DelayedCase.reopen(int(testID), "2", "HalpyBOT Test Library") assert reopen[1] == 0 @pytest.mark.asyncio async def test_notes(): + """Test that case notes can be modified""" notes = await DelayedCase.notes( int(testID), "Modified Case Notes", "HalpyBOT Test Library" ) @@ -72,5 +77,6 @@ async def test_notes(): @pytest.mark.asyncio async def test_close2(): + """Repeat the closure of the precvious test. Leave the system clean!""" closed = await DelayedCase.status(int(testID), 3, "HalpyBOT Test Library") assert closed[1] == 0 diff --git a/tests/test_edsm.py b/tests/test_edsm.py index 6525d281..872d4fa7 100644 --- a/tests/test_edsm.py +++ b/tests/test_edsm.py @@ -45,6 +45,7 @@ def pytest_sessionfinish(session, exitstatus): # 1: Existing sys @pytest.mark.asyncio async def test_sys(): + """Test that EDSM returns a valid response for a given system""" sys = await GalaxySystem.get_info("Sol", cache_override=True) assert sys.name == "Sol" @@ -52,6 +53,7 @@ async def test_sys(): # 2: Non-Existent Sys @pytest.mark.asyncio async def test_non_sys(): + """Test that an invalid system does not return a good value.""" sys = await GalaxySystem.get_info( "Praisehalpydamnwhyisthisnotasysnam", cache_override=True ) @@ -61,6 +63,7 @@ async def test_non_sys(): # 3: GetInfo error @pytest.mark.asyncio async def test_request_error(): + """Test that the module will error correctly if EDSM doesn't respond""" with patch( "halpybot.packages.edsm.GalaxySystem.get_info", side_effect=aiohttp.ClientError("Err"), @@ -71,43 +74,25 @@ async def test_request_error(): ) -# Test Sys Exists -# 1: Existing sys -@pytest.mark.asyncio -async def test_sys_exists(): - sysexists = await GalaxySystem.exists("Sol", cache_override=True) - assert sysexists is True - - -# 2: Non-Existent Sys -@pytest.mark.asyncio -async def test_non_sys_exists(): - sysexists = await GalaxySystem.exists( - "Praisehalpydamnwhyisthisnotasysnam", cache_override=True - ) - assert sysexists is False - - -# Test Nearby Systems -# 1: Existing Nearby @pytest.mark.asyncio async def test_sys_nearby(): + """Test that we can get a nearby system name from a given set of coordinates""" nearby_sys = await GalaxySystem.get_nearby("1", "2", "3") assert nearby_sys == ("Hixkar", 98.25) -# 2: Non-Existent Nearby @pytest.mark.asyncio async def test_sys_not_nearby(): + """Test that impossible coordinates will return None systems nearby""" nearby_sys = await GalaxySystem.get_nearby( "1000000000", "20000000000", "30000000000" ) assert nearby_sys == (None, None) -# 3: GetNearby error @pytest.mark.asyncio async def test_request_nearby_error(): + """Test that the module will error correctly if EDSM doesn't respond""" with patch( "halpybot.packages.edsm.GalaxySystem.get_nearby", side_effect=aiohttp.ClientError("Err"), @@ -116,100 +101,103 @@ async def test_request_nearby_error(): await GalaxySystem.get_nearby("1", "2", "3") -# Test CMDR -# 1: Existing CMDR @pytest.mark.asyncio async def test_cmdr(): + """Test that EDSM returns a valid response for a given CMDR""" cmdr = await Commander.get_cmdr("Rixxan", cache_override=True) assert cmdr.name == "Rixxan" -# 2: Non-Existent CMDR @pytest.mark.asyncio async def test_noncmdr(): + """Test that EDSM will return a None value for a bad CMDR Name""" cmdr = await Commander.get_cmdr( "Praisehalpydamnwhyisthisnotacmdrnam", cache_override=True ) assert cmdr is None -# 2: Cached CMDR @pytest.mark.asyncio async def test_noncmdr2(): + """Test that the caching system responds correctly on a repeated value""" cmdr = await Commander.get_cmdr("Rixxan") assert cmdr.name == "Rixxan" cmdr = await Commander.get_cmdr("Rixxan") assert cmdr.name == "Rixxan" -# CMDR Location - As this can be dynamic, we will simply assume any response is valid. @pytest.mark.asyncio async def test_location(): + """Test that the Commander system responds with a value""" location = await Commander.location("Rixxan") assert location is not None -# Landmarks @pytest.mark.asyncio async def test_landmark(): + """Test that the Landmark system operates correctly""" landmark = await checklandmarks("Delkar", cache_override=True) assert landmark == ("Sol", "83.11", "SW") @pytest.mark.asyncio async def test_distance_bad_landmark(): + """Test that the Landmark system will return the proper exception to a bad system""" with pytest.raises(NoResultsEDSM): await checklandmarks("Sagittarius B*") -# DSSA @pytest.mark.asyncio async def test_dssa(): + """Test that the DSSA system operates correctly""" dssa = await checkdssa("Col 285 Sector AA-A a30-2", cache_override=True) assert dssa == ("Synuefuae CM-J d10-42 (DSSA Artemis Rest)", "6,129.55", "East") @pytest.mark.asyncio async def test_distance_bad_dssa(): + """Test that the DSSA system will return the proper exception to a bad system""" with pytest.raises(NoResultsEDSM): await checkdssa("Sagittarius B*") -# Calculate Distance def test_coords(): + """Test that the distance calculator responds the proper distance""" coords = calc_distance(-1, 2, 3, 400, 500, 600) assert coords == 409.41 -# Calculate Direction @pytest.mark.asyncio async def test_direction(): + """Test that the direction calculator responds with the proper direction""" direction = await calc_direction(-1, 2, 500, 600) assert direction == "North" -# Calculate Direction @pytest.mark.asyncio async def test_nearby(): + """Test that a system will respond properly if fed itself""" nearby = await get_nearby_system("Sagittarius A*") assert nearby == (True, "Sagittarius A*") @pytest.mark.asyncio async def test_nearby_extra(): + """Test that the system cleaner will properly if fed extra details (to a point)""" nearby = await get_nearby_system("Delkar 3 a") assert nearby == (True, "Delkar") -# Calculate Direction @pytest.mark.asyncio async def test_distance(): + """Test that the distance system will calculate properly""" dist = await checkdistance("Sagittarius A*", "Delkar") assert dist == ("25,864.81", "North") @pytest.mark.asyncio async def test_distance_no_a(): + """Test that null arguments will error properly""" with pytest.raises(EDSMConnectionError): await checkdistance("", "Delkar") await checkdistance("Delkar", "") @@ -217,18 +205,21 @@ async def test_distance_no_a(): @pytest.mark.asyncio async def test_distance_bad_sys(): + """Test that distances between non-existing points will error properly""" with pytest.raises(NoResultsEDSM): await checkdistance("Sagittarius B*", "ThisCMDRDoesntExist") @pytest.mark.asyncio async def test_distance_bad_sys_2(): + """Test that distances between only one incorrect point will error properly""" with pytest.raises(NoResultsEDSM): await checkdistance("Sagittarius A*", "ThisCMDRStillDoesntExist") @pytest.mark.asyncio async def test_distance_with_cmdr(): + """Test that Distances will respond properly both ways""" dist = await checkdistance("Rixxan", "Delkar") dist2 = await checkdistance("Delkar", "Rixxan") assert dist[0] == dist2[0] @@ -236,23 +227,27 @@ async def test_distance_with_cmdr(): @pytest.mark.asyncio async def test_distance_cmdr_coords(): + """Check that the independent get_coordinates system works""" cmdr = await halpybot.packages.edsm.edsm.get_coordinates("Rixxan") assert cmdr is not None @pytest.mark.asyncio -async def test_distance_bad_cleaner(): +async def test_sys_cleaner(): + """Test that the system cleaner works properly with nonprocgen""" not_procgen = await sys_cleaner("lp 732-94") assert not_procgen == "LP 732-94" @pytest.mark.asyncio -async def test_distance_bad_cleaner_2(): +async def test_cleaner_2(): + """ "Test the system cleaner works with procGen""" not_procgen = await sys_cleaner("Col 285 Sector HN-I c1O-19") assert not_procgen == "COL 285 SECTOR HN-I C10-19" @pytest.mark.asyncio async def test_distance_check_landmarks_far(): + """Test a distant system doesn't have a landmark within range""" with pytest.raises(NoResultsEDSM): await checklandmarks("Skaudoae UF-Q b47-1") diff --git a/tests/test_logging.py b/tests/test_logging.py index c6ecb1e4..afe9122a 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -19,22 +19,22 @@ logFolder = os.path.dirname(logFile) -# Test for Logging Directory Existence. @pytest.mark.asyncio async def test_log_path(): + """Test that the log folder exists""" assert os.path.exists(logFolder) -# Test if we can create a file in the log directory @pytest.mark.asyncio async def test_log_write(): + """Test that the log directory is writable""" with open(os.path.join(logFolder, "testFile.txt"), "w", encoding="UTF-8"): pass assert os.path.exists(f"{logFolder}/testFile.txt") -# Test for log rotation @pytest.mark.asyncio async def test_log_delete(): + """Test that the log directory can be rotated""" os.remove(f"{logFolder}/testFile.txt") assert not os.path.exists(f"{logFolder}/testFile.txt") diff --git a/tests/test_seals.py b/tests/test_seals.py index c9a8f4dd..cd71c1d6 100644 --- a/tests/test_seals.py +++ b/tests/test_seals.py @@ -16,10 +16,9 @@ from halpybot.packages.configmanager import config, config_write -# Test Time -# 1: Test a good user with a valid WHOIS @pytest.mark.asyncio async def test_good_whois(): + """Test the WHOIS reply for the fun name""" user = await whois("HalpyBOT") user = user[: len(user) // 2] assert ( @@ -30,12 +29,17 @@ async def test_good_whois(): @pytest.mark.asyncio async def test_bad_whois(): + """Test that the WHOIS system responds properly in ONLINE mode""" + prev_value = config["Offline Mode"]["enabled"] + config_write("Offline Mode", "enabled", "False") user = await whois("ThisCMDRDoesntExist") assert user == "No registered user found by that name!" + config_write("Offline Mode", "enabled", prev_value) @pytest.mark.asyncio async def test_no_db(): + """Test that the WHOIS responds properly in offline mode""" prev_value = config["Offline Mode"]["enabled"] config_write("Offline Mode", "enabled", "True") no_database = await whois("ThisCMDRDoesntExist") diff --git a/tests/test_server.py b/tests/test_server.py index 04876b4a..a9579fd9 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -17,5 +17,6 @@ @pytest.mark.asyncio async def test_root(): + """Test the server responds properly to a GET / query""" mac = await server_root("bacon") assert mac.status == 200 diff --git a/tests/test_utils.py b/tests/test_utils.py index ee2279ae..fc8407f1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -17,81 +17,75 @@ from halpybot.packages.command import get_help_text -# Test Time @pytest.mark.asyncio async def test_seconds(): + """Test the time system responds properly""" time = await get_time_seconds("12:34:56") assert time == "45296" -# Test Bad Time @pytest.mark.asyncio async def test_seconds_bad(): + """Test the time system responds properly if an error occurs""" with pytest.raises(ValueError): await get_time_seconds("BACON") -# Test Lang Codes -# 1: If the file exists, we will assume it is correct. def test_lang(): + """Test the lang files exist""" assert os.path.exists("data/languages/iso639-1.json") is True -# 2: Check if the file returns a dict def test_lang_content(): + """Test the lang file is formatted properly""" langs = language_codes() assert isinstance(langs, dict) -# Test Strip ASCII -# 1: Strip non-ascii def test_strip(): + """Test ascii code can be stripped from a string""" string = strip_non_ascii("This has Non-Ascii รถ to Strip") assert string == ("This has Non-Ascii to Strip", True) -# 2: Nothing to Strip def test_non_strip(): + """Test ascii-compliant strings will be left alone""" string = strip_non_ascii("This has Non-Ascii to Strip") assert string == ("This has Non-Ascii to Strip", False) -# Test Help Commands -# 1: If the file exists, we will assume it is correct. async def test_commands(): + """Test the help file exists""" assert os.path.exists("data/help/commands.json") is True -# 2: Check a help command response. If it returns a not none value, we will assume it is true. async def test_commands_content(): + """Test the help file is formatted properly""" assert get_help_text("ping") is not None -# Test backup_facts Commands -# If the file exists, we will assume it is correct. @pytest.mark.asyncio async def test_backup_facts_file(): + """Test the backup fact file exists""" assert os.path.exists("data/facts/backup_facts.json") is True # TODO: Test Backup Fact with Fact test module -# Test EDSM files -# 1: If the file exists, we will assume it is correct. @pytest.mark.asyncio async def test_dssa_file(): + """Test the DSSA file exists""" assert os.path.exists("data/edsm/dssa.json") is True -# 1: If the file exists, we will assume it is correct. @pytest.mark.asyncio async def test_landmark_file(): + """Test the landmark file exists""" assert os.path.exists("data/edsm/landmarks.json") is True -# Test announcer file -# 1: If the file exists, we will assume it is correct. @pytest.mark.asyncio async def test_announcer_file(): + """Test the announcer file exists""" assert os.path.exists("data/announcer/announcer.json") is True