Ejemplo n.º 1
0
    def test_can_get_list(self):
        tset = base.TogglSet(can_get_list=False)
        assert tset.can_get_list is False

        RandomEntity._can_get_list = False
        tset = base.TogglSet(RandomEntity)
        assert tset.can_get_list is False
        RandomEntity._can_get_list = True
        assert tset.can_get_list is True

        tset = base.TogglSet()
        assert tset.can_get_list is True
Ejemplo n.º 2
0
    def test_all_sort(self, mocker):
        mocker.patch.object(utils, 'toggl')
        utils.toggl.return_value = [
            {
                'id': 4,
                'some_field': 'asdf'
            },
            {
                'id': 1,
                'some_field': 'asdf-aa'
            },
            {
                'id': 2,
                'some_field': 'asdf-bb'
            },
            {
                'id': 3,
                'some_field': 'mmm'
            },
        ]

        tset = base.TogglSet(RandomEntity)
        objs = tset.filter(order='desc')
        assert len(objs) == 4
        assert objs[0].some_field == 'mmm'
Ejemplo n.º 3
0
    def test_rebind_class(self):
        tset = base.TogglSet()

        tset.bind_to_class(RandomEntity)

        with pytest.raises(exceptions.TogglException):
            tset.bind_to_class(RandomEntity)
Ejemplo n.º 4
0
    def test_get_detail_none_exception(self, mocker):
        mocker.patch.object(utils, 'toggl')
        utils.toggl.side_effect = exceptions.TogglNotFoundException(404, 'Not found')

        tset = base.TogglSet(RandomEntity)
        obj = tset.get(id=123)

        assert obj is None
Ejemplo n.º 5
0
    def test_get_detail_none(self, mocker):
        mocker.patch.object(utils, 'toggl')
        utils.toggl.return_value = {
            'data': None
        }

        tset = base.TogglSet(RandomEntity)
        obj = tset.get(id=123)

        assert obj is None
Ejemplo n.º 6
0
    def test_get_detail_filter_fallback_no_entries(self, mocker):
        mocker.patch.object(utils, 'toggl')
        utils.toggl.return_value = [{
            'id': 321,
            'some_field': 'asdf'
        }, {
            'id': 321,
            'some_field': 'asdf'
        }]

        tset = base.TogglSet(RandomEntity, can_get_detail=False)
        assert tset.get(id=123) is None
Ejemplo n.º 7
0
    def test_get_detail_filter_fallback(self, mocker):
        mocker.patch.object(utils, 'toggl')
        utils.toggl.return_value = [{
            'id': 123,
            'some_field': 'asdf'
        }]

        tset = base.TogglSet(RandomEntity, can_get_detail=False)
        obj = tset.get(id=123)

        assert obj is not None
        assert obj.some_field == 'asdf'
Ejemplo n.º 8
0
    def test_get_detail_filter_fallback_multiple_entries(self, mocker):
        mocker.patch.object(utils, 'toggl')
        utils.toggl.return_value = [{
            'id': 123,
            'some_field': 'asdf'
        }, {
            'id': 123,
            'some_field': 'asdf'
        }]

        tset = base.TogglSet(RandomEntity, can_get_detail=False)
        with pytest.raises(exceptions.TogglMultipleResultsException):
            tset.get(id=123)
Ejemplo n.º 9
0
    def test_get_detail_basic(self, mocker):
        mocker.patch.object(utils, 'toggl')
        utils.toggl.return_value = {
            'data': {
                'some_field': 'asdf'
            }
        }

        tset = base.TogglSet(RandomEntity)
        obj = tset.get(id=123)

        assert obj is not None
        assert obj.some_field == 'asdf'
Ejemplo n.º 10
0
    def test_unbound_set(self):
        tset = base.TogglSet()

        with pytest.raises(exceptions.TogglException):
            tset.get()

        with pytest.raises(exceptions.TogglException):
            tset.all()

        with pytest.raises(exceptions.TogglException):
            tset.filter()

        with pytest.raises(exceptions.TogglException):
            tset.base_url
Ejemplo n.º 11
0
    def test_filter_multiple_conditions(self, mocker):
        mocker.patch.object(utils, 'toggl')
        utils.toggl.return_value = [
            {
                'id': 3,
                'some_field': 'asdf'
            },
            {
                'id': 2,
                'some_field': 'asdf'
            },
            {
                'id': 3,
                'some_field': 'mmm'
            },
        ]

        tset = base.TogglSet(RandomEntity, can_get_detail=False)
        objs = tset.filter(some_field='asdf', id=2)
        assert len(objs) == 1
Ejemplo n.º 12
0
    def test_filter_contain(self, mocker):
        mocker.patch.object(utils, 'toggl')
        utils.toggl.return_value = [
            {
                'id': 1,
                'some_field': 'asdf'
            },
            {
                'id': 1,
                'some_field': 'asdf-aa'
            },
            {
                'id': 2,
                'some_field': 'asdf-bb'
            },
            {
                'id': 3,
                'some_field': 'mmm'
            },
        ]

        tset = base.TogglSet(RandomEntity, can_get_detail=False)
        objs = tset.filter(some_field='asdf', contain=True)
        assert len(objs) == 3
Ejemplo n.º 13
0
class Workspace(base.TogglEntity):
    _can_create = False
    _can_delete = False

    name = fields.StringField(required=True)
    """
    Name of the workspace
    """

    premium = fields.BooleanField()
    """
    If it's a pro workspace or not. Shows if someone is paying for the workspace or not
    """

    admin = fields.BooleanField()
    """
    Shows whether currently requesting user has admin access to the workspace
    """

    only_admins_may_create_projects = fields.BooleanField()
    """
    Whether only the admins can create projects or everybody
    """

    only_admins_see_billable_rates = fields.BooleanField()
    """
    Whether only the admins can see billable rates or everybody
    """

    rounding = fields.IntegerField()
    """
    Type of rounding:

    * round down: -1
    * nearest: 0
    * round up: 1
    """

    rounding_minutes = fields.IntegerField()
    """
    Round up to nearest minute
    """

    default_hourly_rate = fields.FloatField()
    """
    Default hourly rate for workspace, won't be shown to non-admins
    if the only_admins_see_billable_rates flag is set to true
    """

    default_currency = fields.StringField()
    """
    Default currency for workspace
    """

    # As TogglEntityMeta is by default adding WorkspaceTogglSet to TogglEntity,
    # but we want vanilla TogglSet so defining it here explicitly.
    objects = base.TogglSet()

    def invite(self, *emails):  # type: (str) -> None
        """
        Invites users defined by email addresses. The users does not have to have account in Toggl, in that case after
        accepting the invitation, they will go through process of creating the account in the Toggl web.

        :param emails: List of emails to invite.
        :return: None
        """
        for email in emails:
            if not validate_email(email):
                raise exceptions.TogglValidationException(
                    'Supplied email \'{}\' is not valid email!'.format(email))

        emails_json = json.dumps({'emails': emails})
        data = utils.toggl("/workspaces/{}/invite".format(self.id),
                           "post",
                           emails_json,
                           config=self._config)

        if 'notifications' in data and data['notifications']:
            raise exceptions.TogglException(data['notifications'])
Ejemplo n.º 14
0
    def test_all_can_get_list_false(self):
        tset = base.TogglSet(RandomEntity, can_get_list=False)

        with pytest.raises(exceptions.TogglException):
            tset.all()
Ejemplo n.º 15
0
    def test_url(self):
        tset = base.TogglSet(url='http://some-url.com')
        assert tset.base_url == 'http://some-url.com'

        tset = base.TogglSet(RandomEntity)
        assert tset.base_url == 'random_entitys'