コード例 #1
0
    def test_not_found(self, ctx, mock_switch_repository: SwitchRepository,
                       switch_manager: SwitchManager):
        mock_switch_repository.delete_switch = MagicMock(
            side_effect=SwitchNotFoundError)

        with raises(SwitchNotFoundError):
            switch_manager.delete(ctx, TEST_SWITCH_ID)
コード例 #2
0
    def test_switch_not_found(self, ctx,
                              mock_switch_repository: SwitchRepository,
                              switch_manager: SwitchManager):
        mock_switch_repository.search_switches_by = MagicMock(return_value=([],
                                                                            0))

        with raises(SwitchNotFoundError):
            switch_manager.get_by_id(ctx, TEST_SWITCH_ID)
コード例 #3
0
    def test_happy_path(self, ctx, mock_switch_repository: SwitchRepository,
                        switch_manager: SwitchManager):
        mock_switch_repository.delete_switch = MagicMock()

        switch_manager.delete(ctx, TEST_SWITCH_ID)

        mock_switch_repository.delete_switch.assert_called_once_with(
            ctx, TEST_SWITCH_ID)
コード例 #4
0
    def test_happy_path(self, ctx, mock_switch_repository: SwitchRepository,
                        sample_switch: Switch, switch_manager: SwitchManager):
        mock_switch_repository.search_switches_by = MagicMock(
            return_value=([sample_switch], 1))
        result = switch_manager.get_by_id(ctx, TEST_SWITCH_ID)

        assert sample_switch == result
        mock_switch_repository.search_switches_by.assert_called_once()
コード例 #5
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)
コード例 #6
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))
コード例 #7
0
    def test_happy_path(self, ctx, mock_switch_repository: SwitchRepository,
                        sample_switch: Switch, switch_manager: SwitchManager):
        mock_switch_repository.search_switches_by = MagicMock(
            return_value=([sample_switch], 1))
        result, count = switch_manager.search(ctx,
                                              limit=42,
                                              offset=2,
                                              terms='abc')

        assert [sample_switch] == result
        assert 1 == count
        mock_switch_repository.search_switches_by.assert_called_once_with(
            ctx, limit=42, offset=2, terms='abc')
コード例 #8
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)
コード例 #9
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()
コード例 #10
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.create_switch = MagicMock()

        switch_manager.create(ctx, req)

        mock_switch_repository.create_switch.assert_called_once_with(
            ctx,
            description=req.description,
            ip_v4=req.ip_v4,
            community=req.community)