Пример #1
0
    def test_compare_datetimes(self):
        self.assertEqual(original_datetime(*self.more_recent), datetime(*self.more_recent))
        self.assertEqual(original_datetime(*self.really_old), datetime(*self.really_old))
        self.assertEqual(original_date(*self.more_recent), date(*self.more_recent))
        self.assertEqual(original_date(*self.really_old), date(*self.really_old))

        self.assertEqual(original_date(*self.just_safe).strftime('%Y-%m-%d'), date(*self.just_safe).strftime('%Y-%m-%d'))
        self.assertEqual(original_datetime(*self.just_safe).strftime('%Y-%m-%d'), datetime(*self.just_safe).strftime('%Y-%m-%d'))
Пример #2
0
    def test_compare_datetimes(self):
        self.assertEqual(original_datetime(*self.more_recent), datetime(*self.more_recent))
        self.assertEqual(original_datetime(*self.really_old), datetime(*self.really_old))
        self.assertEqual(original_date(*self.more_recent), date(*self.more_recent))
        self.assertEqual(original_date(*self.really_old), date(*self.really_old))

        self.assertEqual(original_date(*self.just_safe).strftime('%Y-%m-%d'), date(*self.just_safe).strftime('%Y-%m-%d'))
        self.assertEqual(original_datetime(*self.just_safe).strftime('%Y-%m-%d'), datetime(*self.just_safe).strftime('%Y-%m-%d'))
Пример #3
0
def test_datetime(*args):
    """Generating a datetime aware or naive
    depending of USE_TZ"""
    d = original_datetime(*args)
    if settings.USE_TZ:
        d = timezone.make_aware(d, timezone.utc)
    return d
Пример #4
0
def test_datetime(*args):
    """Generating a datetime aware or naive
    depending of USE_TZ"""
    d = original_datetime(*args)
    if settings.USE_TZ:
        d = timezone.make_aware(d, timezone.utc)
    return d
Пример #5
0
def test_prepare_ssh_key_consume_missing_private_key(get_build_from_instructions,
                                                     set_build_status,
                                                     check_output,
                                                     datetime):
    ('PrepareSSHKey#write_file should log to the build output and exit if the private key is missing')
    datetime.utcnow.return_value = original_datetime(2015, 6, 27)

    build = get_build_from_instructions.return_value

    # Given a PrepareSSHKey Step instance
    step = prepare_step_instance(PrepareSSHKey)
    step.parent.get_name.return_value = 'foo'
    # And some instructions with ssh info
    instructions = {
        'builder': {'id': 'my-happy-builder'},
        'slug': 'foobar',
        'id_rsa_public': 'the public key',
        'id_rsa_private_key_path': 'id_rsa_chucknorris',
        'id_rsa_public_key_path': 'id_rsa_chucknorris.pub',
    }

    # When I call consume with those instructions
    step.consume.when.called_with(
        instructions).should.have.raised(RuntimeError)

    # Then get_build_from_instructions should have been called with
    # the instructions
    get_build_from_instructions.assert_called_once_with(
        instructions)

    # And set_build_status sets the build to "running" and provides a
    # description with the start time
    set_build_status.assert_called_once_with(
        build,
        instructions,
        'running',
        'carpentry build started at 2015/06/27 00:00:00 UTC',
    )

    # And the build output should have gotten date
    build.append_to_stdout.assert_has_calls([
        call(u'preparing ssh key...\n'),
        call(u'the builder my-happy-builder does not have a private_key set')
    ])
Пример #6
0
def test_prepare_ssh_key_consume_ssh_add_failed(
        get_build_from_instructions,
        set_build_status,
        check_output,
        datetime):
    ('PrepareSSHKey#write_file should save the '
     'output of error details when ssh-add failed')
    build = get_build_from_instructions.return_value
    datetime.utcnow.return_value = original_datetime(2015, 6, 27)

    check_output.side_effect = CalledProcessError(
        1, 'ssh-add /path/to/key', 'boom')

    # Given a PrepareSSHKey Step instance
    step = prepare_step_instance(PrepareSSHKey)

    # And some instructions with ssh info
    instructions = {
        'slug': 'foobar',
        'id_rsa_private': 'the private key',
        'id_rsa_public': 'the public key',
        'id_rsa_private_key_path': 'id_rsa_chucknorris',
        'id_rsa_public_key_path': 'id_rsa_chucknorris.pub',
    }

    # When I call consume with those instructions
    step.consume(instructions)

    # Then get_build_from_instructions should have been called with
    # the instructions
    get_build_from_instructions.assert_called_once_with(
        instructions)

    # And set_build_status sets the build to "running" and provides a
    # description with the start time
    set_build_status.assert_called_once_with(
        build,
        instructions,
        'running',
        'carpentry build started at 2015/06/27 00:00:00 UTC',
    )
Пример #7
0
def test_prepare_ssh_key_consume(get_build_from_instructions,
                                 set_build_status,
                                 check_output,
                                 datetime):
    ('PrepareSSHKey#write_file should create the destination '
     'folder if it does not exist')
    build = get_build_from_instructions.return_value
    datetime.utcnow.return_value = original_datetime(2015, 6, 27)

    # Given a PrepareSSHKey Step instance
    step = prepare_step_instance(PrepareSSHKey)

    # And some instructions with ssh info
    instructions = {
        'slug': 'foobar',
        'id_rsa_private': 'the private key',
        'id_rsa_public': 'the public key',
        'id_rsa_private_key_path': 'id_rsa_chucknorris',
        'id_rsa_public_key_path': 'id_rsa_chucknorris.pub',
    }

    # When I call consume with those instructions
    step.consume(instructions)

    # Then get_build_from_instructions should have been called with
    # the instructions
    get_build_from_instructions.assert_called_once_with(
        instructions)

    # And set_build_status sets the build to "running" and provides a
    # description with the start time
    set_build_status.assert_called_once_with(
        build,
        instructions,
        'running',
        'carpentry build started at 2015/06/27 00:00:00 UTC',
    )