Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Unittest
#1
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
Reply


Messages In This Thread
Python Unittest - by roadrage - Feb-14-2019, 06:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  unittest mepyyeti 3 3,301 Dec-21-2017, 04:57 PM
Last Post: mepyyeti

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020