Exemplo n.º 1
0
def test_user_no_read_throttling(settings, rf):
    settings.REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['user-read'] = None
    request = rf.get("/test")
    request.user = User(id=1)
    throttling = CommonThrottle()
    for x in range(100):
        assert throttling.allow_request(request, None)
    cache.clear()
    settings.REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['user-read'] = None
Exemplo n.º 2
0
def test_user_multi_read_first_small_throttling(settings, rf):
    settings.REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['user-read'] = ["1/min", "10/min"]
    request = rf.get("/test")
    request.user = User(id=1)
    throttling = CommonThrottle()
    assert throttling.allow_request(request, None)
    assert throttling.allow_request(request, None) is False
    for x in range(100):
        assert throttling.allow_request(request, None) is False
    cache.clear()
    settings.REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['user-read'] = None
Exemplo n.º 3
0
def test_user_simple_write_throttling(settings, rf):
    settings.REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['user-write'] = "1/min"
    request = rf.post("/test")
    request.user = User(id=1)
    throttling = CommonThrottle()
    assert throttling.allow_request(request, None)
    assert throttling.allow_request(request, None) is False
    for x in range(100):
        assert throttling.allow_request(request, None) is False
    cache.clear()
    settings.REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['user-write'] = None
Exemplo n.º 4
0
def test_whitelisted_user_throttling(settings, rf):
    settings.REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['user-read'] = "1/min"
    settings.REST_FRAMEWORK['DEFAULT_THROTTLE_WHITELIST'] = [1]
    request = rf.get("/test")
    request.user = User(id=1)
    throttling = CommonThrottle()
    assert throttling.allow_request(request, None)
    assert throttling.allow_request(request, None)
    cache.clear()
    settings.REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['user-read'] = None
    settings.REST_FRAMEWORK['DEFAULT_THROTTLE_WHITELIST'] = []
Exemplo n.º 5
0
 def _import_history(self, obj, task, options):
     users_bindings = options.get('users_bindings', {})
     stories = self._client.stories.find_by_task(task['id'])
     for story in stories:
         if story['type'] == "comment":
             snapshot = take_snapshot(
                 obj,
                 comment=story['text'],
                 user=users_bindings.get(story['created_by']['id'], User(full_name=story['created_by']['name'])),
                 delete=False
             )
             HistoryEntry.objects.filter(id=snapshot.id).update(created_at=story['created_at'])
Exemplo n.º 6
0
    def _import_comments(self, obj, issue, options):
        users_bindings = options.get('users_bindings', {})
        offset = 0
        while True:
            comments = self._client.get("/issue/{}/comment".format(issue['key']), {"startAt": offset})
            for comment in comments['comments']:
                snapshot = take_snapshot(
                    obj,
                    comment=comment['body'],
                    user=users_bindings.get(
                        comment['author']['name'],
                        User(full_name=comment['author']['displayName'])
                    ),
                    delete=False
                )
                HistoryEntry.objects.filter(id=snapshot.id).update(created_at=comment['created'])

            offset += len(comments['comments'])
            if len(comments['comments']) <= comments['maxResults']:
                break
Exemplo n.º 7
0
 def get_assigned_to_extra_info(self, obj):
     assigned_to = None
     if obj.assigned_to_extra_info is not None:
         assigned_to = User(**obj.assigned_to_extra_info)
     return UserBasicInfoSerializer(assigned_to).data