示例#1
0
    def test_gen_datetime_11(self):
        """
        @Test: Create a datetime with non-Date arguments
        @Feature: DateTime Generator
        @Assert: Datetime is not created due to value error
        """

        with self.assertRaises(ValueError):
            gen_datetime(min_date=(1, ), max_date=(2, 3, 4))
示例#2
0
def test_gen_datetime_13():
    """Create a datetime with min_date > max_date."""
    # Today is...
    today = datetime.datetime.now()
    # Five minutes into the future
    min_date = today + datetime.timedelta(seconds=5 * 60)

    with pytest.raises(AssertionError):
        gen_datetime(min_date=min_date, max_date=today)
示例#3
0
    def test_gen_datetime_12(self):
        """
        @Test: Create a datetime with non-Date arguments
        @Feature: DateTime Generator
        @Assert: Datetime is not created due to value error
        """

        with self.assertRaises(ValueError):
            gen_datetime(min_date=['a', 'b'], max_date=['c', 'd', 'e'])
    def test_gen_datetime_12(self):
        """
        @Test: Create a datetime with non-Date arguments
        @Feature: DateTime Generator
        @Assert: Datetime is not created due to value error
        """

        with self.assertRaises(ValueError):
            gen_datetime(
                min_date=['a', 'b'],
                max_date=['c', 'd', 'e']
            )
    def test_gen_datetime_11(self):
        """
        @Test: Create a datetime with non-Date arguments
        @Feature: DateTime Generator
        @Assert: Datetime is not created due to value error
        """

        with self.assertRaises(ValueError):
            gen_datetime(
                min_date=(1,),
                max_date=(2, 3, 4)
            )
示例#6
0
    def test_gen_datetime_13(self):
        """
        @Test: Create a datetime with min_date > max_date
        @Feature: DateTime Generator
        @Assert: Datetime should not be created due to assertion error
        """

        # Today is...
        today = datetime.datetime.now()
        # Five minutes into the future
        min_date = today + datetime.timedelta(seconds=5 * 60)

        with self.assertRaises(AssertionError):
            gen_datetime(min_date=min_date, max_date=today)
    def test_gen_datetime_13(self):
        """
        @Test: Create a datetime with min_date > max_date
        @Feature: DateTime Generator
        @Assert: Datetime should not be created due to assertion error
        """

        # Today is...
        today = datetime.datetime.now()
        # Five minutes into the future
        min_date = today + datetime.timedelta(seconds=5*60)

        with self.assertRaises(AssertionError):
            gen_datetime(
                min_date=min_date,
                max_date=today
            )
示例#8
0
def test_gen_datetime_3():
    """Create a datetime with only max_date."""
    # Today is...
    today = datetime.datetime.now()
    # Five minutes into the future
    max_date = today + datetime.timedelta(seconds=5 * 60)

    for _ in range(10):
        assert gen_datetime(max_date=max_date) <= max_date
示例#9
0
def test_gen_datetime_2():
    """Create a datetime with only min_date."""
    # Today is...
    today = datetime.datetime.now()
    # Five minutes ago
    min_date = today - datetime.timedelta(seconds=5 * 60)

    for _ in range(10):
        assert gen_datetime(min_date=min_date) >= min_date
示例#10
0
 def test_with_end(self, controler, controler_with_logging, tmpdir, mocker):
     """Make sure that passing a end date is passed to the fact gathering method."""
     controler.facts.get_all = mocker.MagicMock()
     path = os.path.join(tmpdir.mkdir('report').strpath, 'report.csv')
     hamsterlib.reports.TSVWriter = mocker.MagicMock(
         return_value=hamsterlib.reports.TSVWriter(path))
     end = fauxfactory.gen_datetime()
     hamster_cli._export(controler, 'csv', None, end)
     args, kwargs = controler.facts.get_all.call_args
     assert kwargs['end'] == end
示例#11
0
 def test_with_end(self, controler, controler_with_logging, tmpdir, mocker):
     """Make sure that passing a end date is passed to the fact gathering method."""
     controler.facts.get_all = mocker.MagicMock()
     path = os.path.join(tmpdir.mkdir('report').strpath, 'report.csv')
     hamsterlib.reports.TSVWriter = mocker.MagicMock(return_value=hamsterlib.reports.TSVWriter(
         path))
     end = fauxfactory.gen_datetime()
     hamster_cli._export(controler, 'csv', None, end)
     args, kwargs = controler.facts.get_all.call_args
     assert kwargs['end'] == end
示例#12
0
    def test_gen_datetime_1(self):
        """
        @Test: Create a datetime with no arguments
        @Feature: DateTime Generator
        @Assert: Datetime is created with random values
        """

        result = gen_datetime()
        self.assertTrue(isinstance(result, datetime.datetime),
                        "Data is not instance of datetime.date.")
示例#13
0
    def test_gen_datetime_1(self):
        """
        @Test: Create a datetime with no arguments
        @Feature: DateTime Generator
        @Assert: Datetime is created with random values
        """

        result = gen_datetime()
        self.assertTrue(
            isinstance(result, datetime.datetime),
            "Data is not instance of datetime.date.")
示例#14
0
def test_gen_datetime_7():
    """Create a datetime with specified datetime ranges."""
    # min_date for the platform
    min_date = (datetime.datetime.now() - datetime.timedelta(365 * MIN_YEARS))
    # max_date for the platform
    max_date = (datetime.datetime.now() + datetime.timedelta(365 * MAX_YEARS))

    for _ in range(20):
        result = gen_datetime(min_date=min_date, max_date=max_date)
        assert result.year <= max_date.year
        assert result.year >= min_date.year
示例#15
0
def test_gen_datetime_6():
    """Create a datetime with max_date == None."""
    # max_date for the platform
    max_date = (datetime.datetime.now() + datetime.timedelta(365 * MAX_YEARS))
    # min_date  = max_date - 1 year
    min_date = max_date - datetime.timedelta(365 * 1)

    for _ in range(20):
        result = gen_datetime(min_date=min_date, max_date=None)
        assert result.year <= max_date.year
        assert result.year >= min_date.year
示例#16
0
def test_gen_datetime_4():
    """Create a datetime with a 5-days datetime range."""
    # Today is...
    today = datetime.datetime.now()
    # Five minutes ago
    min_date = today - datetime.timedelta(seconds=5 * 60)
    # Five minutes into the future
    max_date = today + datetime.timedelta(seconds=5 * 60)

    for _ in range(10):
        result = gen_datetime(min_date=min_date, max_date=max_date)
        assert result >= min_date
        assert result <= max_date
示例#17
0
    def test_gen_datetime_3(self):
        """
        @Test: Create a datetime with only max_date
        @Feature: DateTime Generator
        @Assert: Datetime is created and falls before minumum datetime
        """

        # Today is...
        today = datetime.datetime.now()
        # Five minutes into the future
        max_date = today + datetime.timedelta(seconds=5 * 60)

        for turn in range(10):
            result = gen_datetime(max_date=max_date)
            self.assertTrue(result <= max_date)
示例#18
0
    def test_gen_datetime_2(self):
        """
        @Test: Create a datetime with only min_date
        @Feature: DateTime Generator
        @Assert: Datetime is created and falls after minimum datetime
        """

        # Today is...
        today = datetime.datetime.now()
        # Five minutes ago
        min_date = today - datetime.timedelta(seconds=5 * 60)

        for turn in range(10):
            result = gen_datetime(min_date=min_date)
            self.assertTrue(result >= min_date)
示例#19
0
    def test_gen_datetime_2(self):
        """
        @Test: Create a datetime with only min_date
        @Feature: DateTime Generator
        @Assert: Datetime is created and falls after minimum datetime
        """

        # Today is...
        today = datetime.datetime.now()
        # Five minutes ago
        min_date = today - datetime.timedelta(seconds=5*60)

        for turn in range(10):
            result = gen_datetime(min_date=min_date)
            self.assertTrue(result >= min_date)
示例#20
0
    def test_gen_datetime_3(self):
        """
        @Test: Create a datetime with only max_date
        @Feature: DateTime Generator
        @Assert: Datetime is created and falls before minumum datetime
        """

        # Today is...
        today = datetime.datetime.now()
        # Five minutes into the future
        max_date = today + datetime.timedelta(seconds=5*60)

        for turn in range(10):
            result = gen_datetime(max_date=max_date)
            self.assertTrue(result <= max_date)
示例#21
0
    def test_gen_datetime_6(self):
        """
        @Test: Create a datetime with max_date == None
        @Feature: DateTime Generator
        @Assert: Datetime is after minimum and before system max
        """

        # max_date for the platform
        max_date = (datetime.datetime.now() +
                    datetime.timedelta(365 * MAX_YEARS))
        # min_date  = max_date - 1 year
        min_date = max_date - datetime.timedelta(365 * 1)

        for turn in range(20):
            result = gen_datetime(min_date=min_date, max_date=None)
            self.assertTrue(result.year <= max_date.year, result)
            self.assertTrue(result.year >= min_date.year, result)
示例#22
0
    def test_gen_datetime_5(self):
        """
        @Test: Create a datetime with min_date = None
        @Feature: DateTime Generator
        @Assert: Datetime is created and falls within the datetime range
        """

        # min_date for the platform
        min_date = (datetime.datetime.now() -
                    datetime.timedelta(365 * MIN_YEARS))
        # max_date = min_date + 1 year
        max_date = min_date + datetime.timedelta(365 * 1)

        for turn in range(20):
            result = gen_datetime(min_date=None, max_date=max_date)
            self.assertTrue(result.year <= max_date.year)
            self.assertTrue(result.year >= min_date.year)
示例#23
0
    def test_gen_datetime_7(self):
        """
        @Test: Create a datetime with specified datetime ranges
        @Feature: DateTime Generator
        @Assert: Datetime is created and falls in the specified datetime range
        """

        # min_date for the platform
        min_date = (datetime.datetime.now() -
                    datetime.timedelta(365 * MIN_YEARS))
        # max_date for the platform
        max_date = (datetime.datetime.now() +
                    datetime.timedelta(365 * MAX_YEARS))

        for turn in range(20):
            result = gen_datetime(min_date=min_date, max_date=max_date)
            self.assertTrue(result.year <= max_date.year, result)
            self.assertTrue(result.year >= min_date.year, result)
示例#24
0
    def test_gen_datetime_4(self):
        """
        @Test: Create a datetime with a 5-days datetime range
        @Feature: DateTime Generator
        @Assert: Datetime is created and falls within the datetime range
        """

        # Today is...
        today = datetime.datetime.now()
        # Five minutes ago
        min_date = today - datetime.timedelta(seconds=5 * 60)
        # Five minutes into the future
        max_date = today + datetime.timedelta(seconds=5 * 60)

        for turn in range(10):
            result = gen_datetime(min_date=min_date, max_date=max_date)
            self.assertTrue(result >= min_date)
            self.assertTrue(result <= max_date)
示例#25
0
    def test_gen_datetime_5(self):
        """
        @Test: Create a datetime with min_date = None
        @Feature: DateTime Generator
        @Assert: Datetime is created and falls within the datetime range
        """

        # min_date for the platform
        min_date = (datetime.datetime.now() -
                    datetime.timedelta(365 * MIN_YEARS))
        # max_date = min_date + 1 year
        max_date = min_date + datetime.timedelta(365 * 1)

        for turn in range(20):
            result = gen_datetime(
                min_date=None,
                max_date=max_date
            )
            self.assertTrue(result.year <= max_date.year)
            self.assertTrue(result.year >= min_date.year)
示例#26
0
    def test_gen_datetime_6(self):
        """
        @Test: Create a datetime with max_date == None
        @Feature: DateTime Generator
        @Assert: Datetime is after minimum and before system max
        """

        # max_date for the platform
        max_date = (datetime.datetime.now() +
                    datetime.timedelta(365 * MAX_YEARS))
        # min_date  = max_date - 1 year
        min_date = max_date - datetime.timedelta(365 * 1)

        for turn in range(20):
            result = gen_datetime(
                min_date=min_date,
                max_date=None
            )
            self.assertTrue(result.year <= max_date.year, result)
            self.assertTrue(result.year >= min_date.year, result)
示例#27
0
    def test_gen_datetime_7(self):
        """
        @Test: Create a datetime with specified datetime ranges
        @Feature: DateTime Generator
        @Assert: Datetime is created and falls in the specified datetime range
        """

        # min_date for the platform
        min_date = (datetime.datetime.now() -
                    datetime.timedelta(365 * MIN_YEARS))
        # max_date for the platform
        max_date = (datetime.datetime.now() +
                    datetime.timedelta(365 * MAX_YEARS))

        for turn in range(20):
            result = gen_datetime(
                min_date=min_date,
                max_date=max_date
            )
            self.assertTrue(result.year <= max_date.year, result)
            self.assertTrue(result.year >= min_date.year, result)
示例#28
0
    def test_gen_datetime_4(self):
        """
        @Test: Create a datetime with a 5-days datetime range
        @Feature: DateTime Generator
        @Assert: Datetime is created and falls within the datetime range
        """

        # Today is...
        today = datetime.datetime.now()
        # Five minutes ago
        min_date = today - datetime.timedelta(seconds=5*60)
        # Five minutes into the future
        max_date = today + datetime.timedelta(seconds=5*60)

        for turn in range(10):
            result = gen_datetime(
                min_date=min_date,
                max_date=max_date
            )
            self.assertTrue(result >= min_date)
            self.assertTrue(result <= max_date)
示例#29
0
 def gen_value(self):
     """Return a value suitable for a :class:`DateTimeField`."""
     return gen_datetime(self.min_date, self.max_date)
示例#30
0
    fauxfactory.gen_alpha(),
    "_{0}".format(fauxfactory.gen_alpha()),
    "{0}.{1}".format(fauxfactory.gen_alpha(), fauxfactory.gen_alpha()),
    "_{0}.{1}".format(fauxfactory.gen_alpha(), fauxfactory.gen_alpha()),
    ("'{0}'".format(fauxfactory.gen_alpha()), ParseException),
    ('"{0}"'.format(fauxfactory.gen_alpha()), ParseException),
    (fauxfactory.gen_numeric_string(), ParseException),
]

value_tests = [
    "'{0}'".format(fauxfactory.gen_alpha()),
    '"{0}"'.format(fauxfactory.gen_alpha()),
    fauxfactory.gen_numeric_string(),
    fauxfactory.gen_date().isoformat(),
    fauxfactory.gen_time().isoformat(),
    fauxfactory.gen_datetime().isoformat(),
    (fauxfactory.gen_alpha(), ParseException),
    ("_{0}".format(fauxfactory.gen_alpha()), ParseException),
    ("{0}.{1}".format(fauxfactory.gen_alpha(), fauxfactory.gen_alpha()), ParseException),
    ("_{0}.{1}".format(fauxfactory.gen_alpha(), fauxfactory.gen_alpha()), ParseException),
]

regex_tests = [
    "/regex/",
    "/regex/i",
    "/regex/im",
    ("/not[a-valid/", ParseException),
    ("/not(a-valid/", ParseException),
    ("/not-a-valid)", ParseException),
    ("'regex'", ParseException),
]
示例#31
0
 def gen_value(self):
     """Return a value suitable for a :class:`DateTimeField`."""
     return gen_datetime(self.min_date, self.max_date)
示例#32
0
def test_gen_datetime_9():
    """Create a datetime with non-Date arguments."""
    with pytest.raises(ValueError):
        gen_datetime(min_date='abc', max_date='def')
示例#33
0
def test_gen_datetime_1():
    """Create a datetime with no arguments."""
    assert isinstance(gen_datetime(), datetime.datetime)
示例#34
0
def test_gen_datetime_11():
    """Create a datetime with non-Date arguments."""
    with pytest.raises(ValueError):
        gen_datetime(min_date=(1, ), max_date=(2, 3, 4))
示例#35
0
def test_gen_date_14():
    """max-date must be a Datetime type."""
    with pytest.raises(ValueError):
        gen_datetime(min_date=datetime.datetime.now(), max_date='foo')
示例#36
0
def test_gen_datetime_12():
    """Create a datetime with non-Date arguments."""
    with pytest.raises(ValueError):
        gen_datetime(min_date=['a', 'b'], max_date=['c', 'd', 'e'])