Skip to content

Commit

Permalink
[Halpy-123a] Add more docstrings
Browse files Browse the repository at this point in the history
& remove a useless function
  • Loading branch information
Rixxan committed Mar 24, 2022
1 parent 0e58ba9 commit d6d633d
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 70 deletions.
2 changes: 1 addition & 1 deletion CLI/BackupFactUpdater/__main__.py
Expand Up @@ -37,7 +37,7 @@

# noinspection PyBroadException
def run():

"""Run the Backup Fact Updater"""
dbconfig = {
"user": config.get("Database", "user"),
"password": config.get("Database", "password"),
Expand Down
2 changes: 1 addition & 1 deletion CLI/DSSAUpdater/__main__.py
Expand Up @@ -36,7 +36,7 @@


def run():

"""Run the DSSA Updater"""
print(
"=" * 20
+ "\nCopyright (c) 2022 The Hull Seals\nDSSA file updater for HalpyBOT\n"
Expand Down
3 changes: 0 additions & 3 deletions halpybot/packages/announcer/announcer.py
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions 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
"""
9 changes: 6 additions & 3 deletions tests/test_checks.py
Expand Up @@ -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),
Expand All @@ -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"),
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/test_config.py
Expand Up @@ -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']",
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions tests/test_database.py
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_delayed.py
Expand Up @@ -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(
Expand All @@ -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"
)
Expand All @@ -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

0 comments on commit d6d633d

Please sign in to comment.