Пример #1
0
def test_parse_date_string():
    # test unconverted data remains: Z
    assert parse_date_string('2019-09-17T06:16:39Z') == datetime(
        2019, 9, 17, 6, 16, 39)

    # test unconverted data remains: .22Z
    assert parse_date_string('2019-09-17T06:16:39.22Z') == datetime(
        2019, 9, 17, 6, 16, 39, 220000)

    # test time data without ms does not match format with ms
    assert parse_date_string('2019-09-17T06:16:39Z',
                             '%Y-%m-%dT%H:%M:%S.%f') == datetime(
                                 2019, 9, 17, 6, 16, 39)

    # test time data with timezone Z does not match format with timezone +05:00
    assert parse_date_string('2019-09-17T06:16:39Z',
                             '%Y-%m-%dT%H:%M:%S+05:00') == datetime(
                                 2019, 9, 17, 6, 16, 39)

    # test time data with timezone +05:00 does not match format with timezone Z
    assert parse_date_string('2019-09-17T06:16:39+05:00',
                             '%Y-%m-%dT%H:%M:%SZ') == datetime(
                                 2019, 9, 17, 6, 16, 39)

    # test time data with timezone -05:00 and with ms does not match format with timezone +02:00 without ms
    assert parse_date_string('2019-09-17T06:16:39.4040+05:00',
                             '%Y-%m-%dT%H:%M:%S+02:00') == datetime(
                                 2019, 9, 17, 6, 16, 39, 404000)
Пример #2
0
     - Argument name to extract from Demisto arguments as number.

    When:
    - Case a: Argument exists, and is lower than default 'lower_bound' value.
    - Case b: Argument exists, and is above given 'maximum_bound' value.

    Then:
     - Ensure that DemistoException is thrown with error message indicating that value is not positive.
     - Ensure that DemistoException is thrown with error message indicating that value is higher than maximum expected.
    """
    with pytest.raises(DemistoException, match=f'limit should be equal or higher than {MINIMUM_POSITIVE_VALUE}'):
        get_and_validate_positive_int_argument({'limit': -3}, 'limit')


@pytest.mark.parametrize('arg, expected',
                         [('2020-11-22T16:31:14-02:00', datetime(2020, 11, 22, 18, 31, 14, tzinfo=pytz.utc)),
                          (None, None),
                          ('2020-11-22T22:31:14-02:00', datetime(2020, 11, 23, 0, 31, 14, tzinfo=pytz.utc)),
                          ('2020-11-22T01:31:14+02:00', datetime(2020, 11, 21, 23, 31, 14, tzinfo=pytz.utc))])
def test_get_optional_time_parameter_valid_time_argument(arg, expected):
    """
    Given:
     - Demisto arguments.
     - Argument of type time to extract from Demisto arguments as epoch time.

    When:
     - Case a: Argument exists, has expected date format.
     - Case b: Argument does not exist.
     - Case c: Argument exists, timezone is not UTC.
     - Case d: Argument exists, timezone is not UTC.