def test_add_to_objects_timeline(): with patch("taiga.timeline.service._add_to_object_timeline") as mock: users = [User(), User(), User()] project = Project() service._add_to_objects_timeline(users, project, "test") assert mock.call_count == 3 assert mock.mock_calls == [ call(users[0], project, "test", "default", {}), call(users[1], project, "test", "default", {}), call(users[2], project, "test", "default", {}), ] with pytest.raises(Exception): service.push_to_timeline(None, project, "test")
def _import_comments(self, project, repo, options): users_bindings = options.get('users_bindings', {}) page = 1 while True: comments = self._client.get("/repos/{}/issues/comments".format(repo['full_name']), { "page": page, "per_page": 100 }) page += 1 for comment in comments: issue_id = comment['issue_url'].split("/")[-1] if options.get('type', None) == "user_stories": obj = UserStory.objects.get(project=project, ref=issue_id) elif options.get('type', None) == "issues": obj = Issue.objects.get(project=project, ref=issue_id) snapshot = take_snapshot( obj, comment=comment['body'], user=users_bindings.get(comment['user']['id'], User(full_name=comment['user'].get('name', None) or comment['user']['login'])), delete=False ) HistoryEntry.objects.filter(id=snapshot.id).update(created_at=comment['created_at']) if len(comments) < 100: break
def _import_comments(self, project_data, obj, story, options): users_bindings = options.get("users_bindings", {}) for comment in story["comments"]: if "text" in comment: snapshot = take_snapshot( obj, comment=comment["text"], user=users_bindings.get( comment["person"]["id"], User(full_name=comment["person"]["name"]), ), delete=False, ) HistoryEntry.objects.filter(id=snapshot.id).update( created_at=comment["created_at"]) for attachment in comment["file_attachments"]: self._import_attachment( obj, attachment["id"], attachment["filename"], comment["created_at"], comment["person"]["id"], options, )
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
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
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
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'] = []
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'])
def _import_comments(self, project_data, obj, story, options): users_bindings = options.get('users_bindings', {}) for comment in story['comments']: if 'text' in comment: snapshot = take_snapshot( obj, comment=comment['text'], user=users_bindings.get( comment['person']['id'], User(full_name=comment['person']['name'])), delete=False) HistoryEntry.objects.filter(id=snapshot.id).update( created_at=comment['created_at']) for attachment in comment['file_attachments']: self._import_attachment(obj, attachment['id'], attachment['filename'], comment['created_at'], comment['person']['id'], options)
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
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
def _import_comments(self, project, repo, options): users_bindings = options.get("users_bindings", {}) page = 1 while True: comments = self._client.get( "/repos/{}/issues/comments".format(repo["full_name"]), { "page": page, "per_page": 100 }, ) page += 1 for comment in comments: issue_id = comment["issue_url"].split("/")[-1] if options.get("type", None) == "user_stories": obj = UserStory.objects.get(project=project, ref=issue_id) elif options.get("type", None) == "issues": obj = Issue.objects.get(project=project, ref=issue_id) snapshot = take_snapshot( obj, comment=comment["body"], user=users_bindings.get( comment["user"]["id"], User(full_name=comment["user"].get("name", None) or comment["user"]["login"]), ), delete=False, ) HistoryEntry.objects.filter(id=snapshot.id).update( created_at=comment["created_at"]) if len(comments) < 100: break
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