Пример #1
0
    def test_happy_path(self, ctx, mock_switch_repository: SwitchRepository,
                        switch_manager: SwitchManager):
        req = MutationRequest(
            description='desc',
            ip_v4='157.159.123.123',
            community='ip',
        )
        mock_switch_repository.update_switch = MagicMock()

        switch_manager.update(ctx, '2', req)

        mock_switch_repository.update_switch.assert_called_once_with(
            ctx, switch_id='2', **asdict(req))
Пример #2
0
    def test_switch_not_found(self, ctx,
                              mock_switch_repository: SwitchRepository,
                              switch_manager: SwitchManager):
        req = MutationRequest(
            description='desc',
            ip_v4='157.159.123.123',
            community='ip',
        )
        mock_switch_repository.update_switch = MagicMock(
            side_effect=SwitchNotFoundError)

        with raises(SwitchNotFoundError):
            switch_manager.update(ctx, '2', req)
Пример #3
0
    def test_invalid_mutation_request(self, ctx,
                                      mock_switch_repository: SwitchRepository,
                                      field: str, value,
                                      switch_manager: SwitchManager):
        req = MutationRequest(
            description='desc',
            ip_v4='157.159.123.123',
            community='ip',
        )
        req = MutationRequest(**{**asdict(req), **{field: value}})
        mock_switch_repository.update_switch = MagicMock()

        with raises(ValueError):
            switch_manager.update(ctx, '2', req)
Пример #4
0
    def test_missing_required_field(self, ctx,
                                    mock_switch_repository: SwitchRepository,
                                    switch_manager: SwitchManager):
        req = MutationRequest(
            description='desc',
            ip_v4='157.159.123.123',
            community='ip',
        )
        req.community = None
        mock_switch_repository.update_switch = MagicMock()

        with raises(MissingRequiredField):
            switch_manager.update(ctx, '2', req)

        mock_switch_repository.update_switch.assert_not_called()