def test_yearly_working_days_is_calculated_correctly():
    """testing if the yearly_working_days is calculated correctly
    """

    wh = WorkingHours()
    wh['mon'] = [[1, 2]]
    wh['tue'] = [[3, 4]]
    wh['wed'] = [[5, 6]]
    wh['thu'] = [[7, 8]]
    wh['fri'] = [[9, 10]]
    wh['sat'] = []
    wh['sun'] = []
    assert wh.yearly_working_days == pytest.approx(261)

    wh = WorkingHours()
    wh['mon'] = [[1, 2]]
    wh['tue'] = [[3, 4]]
    wh['wed'] = [[5, 6]]
    wh['thu'] = [[7, 8]]
    wh['fri'] = [[9, 10]]
    wh['sat'] = [[11, 12]]
    wh['sun'] = []
    assert wh.yearly_working_days == pytest.approx(313)

    wh = WorkingHours()
    wh['mon'] = [[1, 2]]
    wh['tue'] = [[3, 4]]
    wh['wed'] = [[5, 6]]
    wh['thu'] = [[7, 8]]
    wh['fri'] = [[9, 10]]
    wh['sat'] = [[11, 12]]
    wh['sun'] = [[13, 14]]
    assert wh.yearly_working_days == pytest.approx(365)
Beispiel #2
0
    def test_yearly_working_days_is_calculated_correctly(self):
        """testing if the yearly_working_days is calculated correctly
        """

        wh = WorkingHours()
        wh['mon'] = [[1, 2]]
        wh['tue'] = [[3, 4]]
        wh['wed'] = [[5, 6]]
        wh['thu'] = [[7, 8]]
        wh['fri'] = [[9, 10]]
        wh['sat'] = []
        wh['sun'] = []
        self.assertAlmostEqual(wh.yearly_working_days, 261, 3)

        wh = WorkingHours()
        wh['mon'] = [[1, 2]]
        wh['tue'] = [[3, 4]]
        wh['wed'] = [[5, 6]]
        wh['thu'] = [[7, 8]]
        wh['fri'] = [[9, 10]]
        wh['sat'] = [[11, 12]]
        wh['sun'] = []
        self.assertAlmostEqual(wh.yearly_working_days, 313, 4)

        wh = WorkingHours()
        wh['mon'] = [[1, 2]]
        wh['tue'] = [[3, 4]]
        wh['wed'] = [[5, 6]]
        wh['thu'] = [[7, 8]]
        wh['fri'] = [[9, 10]]
        wh['sat'] = [[11, 12]]
        wh['sun'] = [[13, 14]]
        self.assertAlmostEqual(wh.yearly_working_days, 365, 0)
Beispiel #3
0
    def test_weekly_working_days_is_calculated_correctly(self):
        """testing if the weekly working days are calculated correctly
        """
        wh = WorkingHours()
        wh['mon'] = [[1, 2]]
        wh['tue'] = [[3, 4]]
        wh['wed'] = [[5, 6]]
        wh['thu'] = [[7, 8]]
        wh['fri'] = [[9, 10]]
        wh['sat'] = []
        wh['sun'] = []
        self.assertEqual(wh.weekly_working_days, 5)

        wh = WorkingHours()
        wh['mon'] = [[1, 2]]
        wh['tue'] = [[3, 4]]
        wh['wed'] = [[5, 6]]
        wh['thu'] = [[7, 8]]
        wh['fri'] = [[9, 10]]
        wh['sat'] = [[11, 12]]
        wh['sun'] = []
        self.assertEqual(wh.weekly_working_days, 6)

        wh = WorkingHours()
        wh['mon'] = [[1, 2]]
        wh['tue'] = [[3, 4]]
        wh['wed'] = [[5, 6]]
        wh['thu'] = [[7, 8]]
        wh['fri'] = [[9, 10]]
        wh['sat'] = [[11, 12]]
        wh['sun'] = [[13, 14]]
        self.assertEqual(wh.weekly_working_days, 7)
Beispiel #4
0
 def test_daily_working_hours_attribute_is_None(self):
     """testing if the daily_working_hours attribute will be equal to the
     default settings value when it is set to None
     """
     wh = WorkingHours()
     wh.daily_working_hours = None
     self.assertEqual(wh.daily_working_hours, defaults.daily_working_hours)
 def test_daily_working_hours_attribute_is_None(self):
     """testing if the daily_working_hours attribute will be equal to the
     default settings value when it is set to None
     """
     wh = WorkingHours()
     wh.daily_working_hours = None
     self.assertEqual(wh.daily_working_hours, defaults.daily_working_hours)
def test_weekly_working_days_is_calculated_correctly():
    """testing if the weekly working days are calculated correctly
    """
    wh = WorkingHours()
    wh['mon'] = [[1, 2]]
    wh['tue'] = [[3, 4]]
    wh['wed'] = [[5, 6]]
    wh['thu'] = [[7, 8]]
    wh['fri'] = [[9, 10]]
    wh['sat'] = []
    wh['sun'] = []
    assert wh.weekly_working_days == 5

    wh = WorkingHours()
    wh['mon'] = [[1, 2]]
    wh['tue'] = [[3, 4]]
    wh['wed'] = [[5, 6]]
    wh['thu'] = [[7, 8]]
    wh['fri'] = [[9, 10]]
    wh['sat'] = [[11, 12]]
    wh['sun'] = []
    assert wh.weekly_working_days == 6

    wh = WorkingHours()
    wh['mon'] = [[1, 2]]
    wh['tue'] = [[3, 4]]
    wh['wed'] = [[5, 6]]
    wh['thu'] = [[7, 8]]
    wh['fri'] = [[9, 10]]
    wh['sat'] = [[11, 12]]
    wh['sun'] = [[13, 14]]
    assert wh.weekly_working_days == 7
Beispiel #7
0
    def test_weekly_working_days_is_a_read_only_attribute(self):
        """testing if the weekly working days is a read-only attribute
        """
        wh = WorkingHours()
        with self.assertRaises(AttributeError) as cm:
            wh.weekly_working_days = 6

        self.assertEqual(str(cm.exception), "can't set attribute")
def test_daily_working_hours_attribute_is_None():
    """testing if the daily_working_hours attribute will be equal to the
    default settings value when it is set to None
    """
    wh = WorkingHours()
    wh.daily_working_hours = None
    from stalker import defaults
    assert wh.daily_working_hours == defaults.daily_working_hours
Beispiel #9
0
    def test_to_tjp_attribute_is_read_only(self):
        """testing if the to_tjp attribute is read only
        """
        wh = WorkingHours()
        with self.assertRaises(AttributeError) as cm:
            wh.to_tjp = 'some value'

        self.assertEqual(str(cm.exception), "can't set attribute")
def test_to_tjp_attribute_is_read_only():
    """testing if the to_tjp attribute is read only
    """
    wh = WorkingHours()
    with pytest.raises(AttributeError) as cm:
        wh.to_tjp = 'some value'

    assert str(cm.value) == "can't set attribute"
def test_weekly_working_days_is_a_read_only_attribute():
    """testing if the weekly working days is a read-only attribute
    """
    wh = WorkingHours()
    with pytest.raises(AttributeError) as cm:
        wh.weekly_working_days = 6

    assert str(cm.value) == "can't set attribute"
def test_yearly_working_days_is_a_read_only_attribute():
    """testing if the yearly_working_days attribute is a read only
    attribute
    """
    wh = WorkingHours()
    with pytest.raises(AttributeError) as cm:
        wh.yearly_working_days = 260.1

    assert str(cm.value) == "can't set attribute"
Beispiel #13
0
    def test_yearly_working_days_is_a_read_only_attribute(self):
        """testing if the yearly_working_days attribute is a read only
        attribute
        """
        wh = WorkingHours()
        with self.assertRaises(AttributeError) as cm:
            wh.yearly_working_days = 260.1

        self.assertEqual(str(cm.exception), "can't set attribute")
 def test_split_in_to_working_hours_is_not_implemented_yet(self):
     """testing if a NotimplementedError will be raised when the
     split_in_to_working_hours() method is called
     """
     with self.assertRaises(NotImplementedError):
         wh = WorkingHours()
         start = datetime.datetime.now()
         end = start + datetime.timedelta(days=10)
         wh.split_in_to_working_hours(start, end)
Beispiel #15
0
 def test_split_in_to_working_hours_is_not_implemented_yet(self):
     """testing if a NotimplementedError will be raised when the
     split_in_to_working_hours() method is called
     """
     with self.assertRaises(NotImplementedError):
         wh = WorkingHours()
         start = datetime.datetime.now()
         end = start + datetime.timedelta(days=10)
         wh.split_in_to_working_hours(start, end)
def test_daily_working_hours_attribute_is_not_an_integer():
    """testing if a TypeError will be raised when the daily_working hours
    attribute is set to a value other than an integer
    """
    wh = WorkingHours()
    with pytest.raises(TypeError) as cm:
        wh.daily_working_hours = 'not an integer'

    assert str(cm.value) == \
        'WorkingHours.daily_working_hours should be an integer, not str'
def test_working_hours_attribute_is_not_a_dictionary():
    """testing if a TypeError will be raised when the working_hours
    attribute is set to a value which is not a dictionary
    """
    wh = WorkingHours()
    with pytest.raises(TypeError) as cm:
        wh.working_hours = 'not a dictionary of proper values'

    assert str(cm.value) == \
        'WorkingHours.working_hours should be a dictionary, not str'
Beispiel #18
0
    def test_working_hours_attribute_is_not_a_dictionary(self):
        """testing if a TypeError will be raised when the working_hours
        attribute is set to a value which is not a dictionary
        """
        wh = WorkingHours()
        with self.assertRaises(TypeError) as cm:
            wh.working_hours = 'not a dictionary of proper values'

        self.assertEqual(
            str(cm.exception),
            'WorkingHours.working_hours should be a dictionary, not str')
def test_daily_working_hours_attribute_is_set_to_a_number_bigger_than_24():
    """testing if a ValueError will be raised when the daily working hours
    attribute value is bigger than 24
    """
    wh = WorkingHours()
    with pytest.raises(ValueError) as cm:
        wh.daily_working_hours = 25

    assert str(cm.value) == \
        'WorkingHours.daily_working_hours should be a positive integer ' \
        'value greater than 0 and smaller than or equal to 24'
def test_split_in_to_working_hours_is_not_implemented_yet():
    """testing if a NotimplementedError will be raised when the
    split_in_to_working_hours() method is called
    """
    with pytest.raises(NotImplementedError):
        wh = WorkingHours()
        import datetime
        import pytz
        start = datetime.datetime.now(pytz.utc)
        end = start + datetime.timedelta(days=10)
        wh.split_in_to_working_hours(start, end)
Beispiel #21
0
 def test_working_hours_attribute_is_working_properly(self):
     """testing if the working_hours attribute is working properly
     """
     working_hours = copy.copy(defaults.working_hours)
     working_hours['sun'] = [[540, 1000]]
     working_hours['sat'] = [[500, 800], [900, 1440]]
     wh = WorkingHours()
     wh.working_hours = working_hours
     self.assertEqual(wh.working_hours, working_hours)
     self.assertEqual(wh.working_hours['sun'], working_hours['sun'])
     self.assertEqual(wh.working_hours['sat'], working_hours['sat'])
 def test_working_hours_attribute_is_working_properly(self):
     """testing if the working_hours attribute is working properly
     """
     working_hours = copy.copy(defaults.working_hours)
     working_hours["sun"] = [[540, 1000]]
     working_hours["sat"] = [[500, 800], [900, 1440]]
     wh = WorkingHours()
     wh.working_hours = working_hours
     self.assertEqual(wh.working_hours, working_hours)
     self.assertEqual(wh.working_hours["sun"], working_hours["sun"])
     self.assertEqual(wh.working_hours["sat"], working_hours["sat"])
Beispiel #23
0
    def test_daily_working_hours_attribute_is_not_an_integer(self):
        """testing if a TypeError will be raised when the daily_working hours
        attribute is set to a value other than an integer
        """
        wh = WorkingHours()
        with self.assertRaises(TypeError) as cm:
            wh.daily_working_hours = 'not an integer'

        self.assertEqual(
            str(cm.exception),
            'WorkingHours.daily_working_hours should be an integer, not str')
def test_daily_working_hours_attribute_is_a_negative_number():
    """testing if a ValueError will be raised when the daily_working_hours
    attribute is set to a negative value
    """
    wh = WorkingHours()
    with pytest.raises(ValueError) as cm:
        wh.daily_working_hours = -10

    assert str(cm.value) == \
        'WorkingHours.daily_working_hours should be a positive integer ' \
        'value greater than 0 and smaller than or equal to 24'
 def test_working_hours_attribute_value_is_not_complete(self):
     """testing if the default values are going to be used for missing days
     in the given working_hours attribute
     """
     working_hours = {"sat": [[900, 1080]], "sun": [[900, 1080]]}
     wh = WorkingHours()
     wh.working_hours = working_hours
     self.assertEqual(wh["mon"], defaults.working_hours["mon"])
     self.assertEqual(wh["tue"], defaults.working_hours["tue"])
     self.assertEqual(wh["wed"], defaults.working_hours["wed"])
     self.assertEqual(wh["thu"], defaults.working_hours["thu"])
     self.assertEqual(wh["fri"], defaults.working_hours["fri"])
Beispiel #26
0
    def test_daily_working_hours_attribute_is_a_negative_number(self):
        """testing if a ValueError will be raised when the daily_working_hours
        attribute is set to a negative value
        """
        wh = WorkingHours()
        with self.assertRaises(ValueError) as cm:
            wh.daily_working_hours = -10

        self.assertEqual(
            str(cm.exception),
            'WorkingHours.daily_working_hours should be a positive integer '
            'value greater than 0 and smaller than or equal to 24')
Beispiel #27
0
 def test_working_hours_attribute_value_is_not_complete(self):
     """testing if the default values are going to be used for missing days
     in the given working_hours attribute
     """
     working_hours = {'sat': [[900, 1080]], 'sun': [[900, 1080]]}
     wh = WorkingHours()
     wh.working_hours = working_hours
     self.assertEqual(wh['mon'], defaults.working_hours['mon'])
     self.assertEqual(wh['tue'], defaults.working_hours['tue'])
     self.assertEqual(wh['wed'], defaults.working_hours['wed'])
     self.assertEqual(wh['thu'], defaults.working_hours['thu'])
     self.assertEqual(wh['fri'], defaults.working_hours['fri'])
def test_working_hours_attribute_value_is_not_complete():
    """testing if the default values are going to be used for missing days
    in the given working_hours attribute
    """
    working_hours = {'sat': [[900, 1080]], 'sun': [[900, 1080]]}
    wh = WorkingHours()
    wh.working_hours = working_hours
    from stalker import defaults
    assert wh['mon'] == defaults.working_hours['mon']
    assert wh['tue'] == defaults.working_hours['tue']
    assert wh['wed'] == defaults.working_hours['wed']
    assert wh['thu'] == defaults.working_hours['thu']
    assert wh['fri'] == defaults.working_hours['fri']
Beispiel #29
0
    def test_daily_working_hours_attribute_is_set_to_a_number_bigger_than_24(
            self):
        """testing if a ValueError will be raised when the daily working hours
        attribute value is bigger than 24
        """
        wh = WorkingHours()
        with self.assertRaises(ValueError) as cm:
            wh.daily_working_hours = 25

        self.assertEqual(
            str(cm.exception),
            'WorkingHours.daily_working_hours should be a positive integer '
            'value greater than 0 and smaller than or equal to 24')
def test_working_hours_attribute_is_working_properly():
    """testing if the working_hours attribute is working properly
    """
    import copy
    from stalker import defaults
    working_hours = copy.copy(defaults.working_hours)
    working_hours['sun'] = [[540, 1000]]
    working_hours['sat'] = [[500, 800], [900, 1440]]
    wh = WorkingHours()
    wh.working_hours = working_hours
    assert wh.working_hours == working_hours
    assert wh.working_hours['sun'] == working_hours['sun']
    assert wh.working_hours['sat'] == working_hours['sat']
Beispiel #31
0
def test_working_hours_attribute_is_set_to_a_dictionary_of_other_formatted_data():
    """testing if a TypeError will be raised when the working hours
    attribute value is a dictionary of some other value
    """
    wh = WorkingHours()
    with pytest.raises(TypeError) as cm:
        wh.working_hours = {'not': 'properly valued'}

    assert str(cm.value) == \
        'WorkingHours.working_hours should be a dictionary with keys ' \
        '"mon, tue, wed, thu, fri, sat, sun" and the values should a ' \
        'list of lists of two integers like [[540, 720], [800, 1080]], ' \
        'not str'
 def test_working_hours_attribute_value_is_not_complete(self):
     """testing if the default values are going to be used for missing days
     in the given working_hours attribute
     """
     working_hours = {
         'sat': [[900, 1080]],
         'sun': [[900, 1080]]
     }
     wh = WorkingHours()
     wh.working_hours = working_hours
     self.assertEqual(wh['mon'], defaults.working_hours['mon'])
     self.assertEqual(wh['tue'], defaults.working_hours['tue'])
     self.assertEqual(wh['wed'], defaults.working_hours['wed'])
     self.assertEqual(wh['thu'], defaults.working_hours['thu'])
     self.assertEqual(wh['fri'], defaults.working_hours['fri'])
Beispiel #33
0
 def test_working_hours_attribute_is_not_a_dictionary(self):
     """testing if a TypeError will be raised when the working_hours
     attribute is set to a value which is not a dictionary
     """
     wh = WorkingHours()
     self.assertRaises(TypeError, setattr, wh, 'working_hours',
                       'not a dictionary of proper values')
Beispiel #34
0
 def test_daily_working_hours_attribute_is_set_to_a_number_bigger_than_24(
         self):
     """testing if a ValueError will be raised when the daily working hours
     attribute value is bigger than 24
     """
     wh = WorkingHours()
     self.assertRaises(ValueError, setattr, wh, 'daily_working_hours', 25)
Beispiel #35
0
 def test_daily_working_hours_attribute_is_not_an_integer(self):
     """testing if a TypeError will be raised when the daily_working hours
     attribute is set to a value other than an integer
     """
     wh = WorkingHours()
     self.assertRaises(TypeError, setattr, wh, 'daily_working_hours',
                       'not an integer')
    def test_is_working_hour_is_working_properly(self):
        """testing if the is_working_hour method is working properly
        """
        wh = WorkingHours()

        wh["mon"] = [[570, 720], [780, 1110]]
        wh["tue"] = [[570, 720], [780, 1110]]
        wh["wed"] = [[570, 720], [780, 1110]]
        wh["thu"] = [[570, 720], [780, 1110]]
        wh["fri"] = [[570, 720], [780, 1110]]
        wh["sat"] = [[570, 720]]
        wh["sun"] = []

        # monday
        check_date = datetime.datetime(2013, 4, 8, 13, 55)
        self.assertTrue(wh.is_working_hour(check_date))

        # sunday
        check_date = datetime.datetime(2013, 4, 14, 13, 55)
        self.assertFalse(wh.is_working_hour(check_date))
    def test_is_working_hour_is_working_properly(self):
        """testing if the is_working_hour method is working properly
        """
        wh = WorkingHours()

        wh['mon'] = [[570, 720], [780, 1110]]
        wh['tue'] = [[570, 720], [780, 1110]]
        wh['wed'] = [[570, 720], [780, 1110]]
        wh['thu'] = [[570, 720], [780, 1110]]
        wh['fri'] = [[570, 720], [780, 1110]]
        wh['sat'] = [[570, 720]]
        wh['sun'] = []

        # monday
        check_date = datetime.datetime(2013, 4, 8, 13, 55)
        self.assertTrue(wh.is_working_hour(check_date))

        # sunday
        check_date = datetime.datetime(2013, 4, 14, 13, 55)
        self.assertFalse(wh.is_working_hour(check_date))
 def test_daily_working_hours_attribute_is_working_properly(self):
     """testing if the daily_working_hours attribute is working properly
     """
     wh = WorkingHours()
     wh.daily_working_hours = 23
     self.assertEqual(wh.daily_working_hours, 23)