Python Forum
Python Unittest - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Python Unittest (/thread-16099.html)



Python Unittest - roadrage - Feb-14-2019

Hello,
I'm new to writing unittests for python scripts

below is a function I have written, so that scheduled start time for a Jira ticket can be autoassigned. We only work on deploy tickets from Monday through thursday and push any new deploy tickets that are requested on thursday through sunday to monday.
here is my script sst.py
sligtht modifications to my scripts, seems to be working for thursday
import arrow

def set_scheduled_start_time():
        utcnow = arrow.utcnow()
        weekday = utcnow.format("dddd")
        if weekday in ["Thursday"]:
            datetime = utcnow.replace(days=+4).format("YYYY-MM-DDTHH:mm:ss")
            ddatetime = utcnow.replace(days=+4).format("dddd")
        elif weekday in ["Friday"]:
            datetime = utcnow.replace(days=+3).format("YYYY-MM-DDTHH:mm:ss")
            ddatetime = utcnow.replace(days=+3).format("dddd")
        elif weekday in ["Saturday"]:
            datetime = utcnow.replace(days=+2).format("YYYY-MM-DDTHH:mm:ss")
            ddatetime = utcnow.replace(days=+2).format("dddd")
        else:
            datetime = utcnow.replace(days=+1).format("YYYY-MM-DDTHH:mm:ss")
            ddatetime = utcnow.replace(days=+1).format("dddd")
        return datetime
        return datetime
set_scheduled_start_time()
here is the unittest I'm trying to write
test_sst.py
import unittest
import sst
import arrow 

class TestSst(unittest.TestCase):

    def test_set_scheduled_start_time(self):
        result = sst.set_scheduled_start_time()
        self.assertEquals(result,Monday)
say if utcnow.format("dddd") is thursday, then my ddatetime.format("dddd") should be monday; I do not call the function with any parameters.
now i need to able to test if for the rest of the days of the week