def test_client_arguments(): """Checks that client can receive token and timeout values """ client = lokalise.Client("123abc", connect_timeout=5, read_timeout=3) assert client.token == "123abc" assert client.connect_timeout == 5 assert client.read_timeout == 3
def test_invalid_client(): """Check that a BadRequest is raised when the client has invalid token """ invalid_client = lokalise.Client("invalid") with pytest.raises(lokalise.errors.BadRequest) as excinfo: invalid_client.projects() assert excinfo.value.args[1] == 400
def test_reset_client(): """Checks that the client can be reset """ client = lokalise.Client("123abc", connect_timeout=5, read_timeout=3) assert client.connect_timeout == 5 # Run an API request so that an endpoint is lazily-loaded with pytest.raises(lokalise.errors.BadRequest): client.projects() client.reset_client() assert client.token == '' assert client.connect_timeout is None assert client.read_timeout is None # Now make sure that lazily-loaded endpoint was reset as well endpoint_attrs = [a for a in vars(client) if a.endswith('_endpoint')] for attr in endpoint_attrs: assert getattr(client, attr) is None
def __init__(self, project_id, personal_token): self.project_id = project_id self.personal_token = personal_token self.client = lokalise.Client(self.personal_token)
from django.conf import settings from rest_framework import status from rest_framework.mixins import CreateModelMixin, ListModelMixin, UpdateModelMixin from rest_framework.permissions import AllowAny from rest_framework.response import Response from rest_framework.views import APIView from rest_framework.viewsets import GenericViewSet from .exceptions import GitHubApiError from .githubclient import GithubAPI from .models import Tool from .serializers import ToolSerializer # from .tasks import update_task from .utils import get_all_translating_keys, populate_with_translating_value client = lokalise.Client(settings.LOKALISE_API_TOKEN) class ToolViewSet(ListModelMixin, CreateModelMixin, UpdateModelMixin, GenericViewSet): queryset = Tool.objects.all() serializer_class = ToolSerializer permission_classes = [AllowAny] def list(self, request, *args, **kwargs): queryset = Tool.objects.all() return Response({ 'code': 0, 'data': self.serializer_class(queryset, many=True).data })
def client(): """Creates a sample client object using the token from the ENV. """ return lokalise.Client(os.getenv("LOKALISE_API_TOKEN"))