Bottom Page

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
buran wrote Feb-14-2019, 10:56 AM:
Please, use python tag when post block of code. icode tag is for inline code
Quote

Top Page

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

Forum Jump:


Users browsing this thread: 1 Guest(s)