Commit Graph

23 Commits

Author SHA1 Message Date
usamasadiq
96f0915b0f Fixed new pylint warnings.
use generator in any/all()
disable not-callable warnings
disable no-member warnings
Suppressed smaller pylint warnings
Pin edx-proctoring==3.5.0
2021-02-22 16:36:53 +05:00
edX requirements bot
f33f12bbea BOM-2358 : Pyupgrade in dashboard, debug, discussion apps (#26529)
* Python code cleanup by the cleanup-python-code Jenkins job.

This pull request was generated by the cleanup-python-code Jenkins job, which ran
```
cd lms/djangoapps/dashboard; find . -type f -name '*.py' | while read fname; do sed -i 's/  # lint-amnesty, pylint: disable=super-with-arguments//; s/  # lint-amnesty, pylint: disable=import-error, wrong-import-order//; s/  # lint-amnesty, pylint: disable=wrong-import-order//' "$fname"; done; find . -type f -name '*.py' | while read fname; do pyupgrade --exit-zero-even-if-changed --py3-plus --py36-plus --py38-plus "$fname"; done; isort --recursive .
```

The following packages were installed:
`pyupgrade,isort`

* feedback done

Co-authored-by: Zulqarnain <muhammad.zulqarnain@arbisoft.com>
2021-02-22 15:42:21 +05:00
Sarina Canelake
ac999ec1fc Merge pull request #25984 from naeem91/patch-1
Fix PY3 incompatible division
2021-02-18 14:57:38 -05:00
SaadYousaf
50e71479ee [TNL-7729] - Add check to discussion rest API to prevent users in blackout period. 2021-02-16 14:08:56 +05:00
M. Zulqarnain
65cf0db337 BOM-2278 : Pylint amnesty in discussion, dashboard (#26275)
* pylint amnesty in discussion, dashboard
2021-02-03 18:15:14 +05:00
Naeem Ilyas
62ce0ed7fc Fix incompatible division
While deleting a post, the number of comments are retrieved where API reports wrong number of total pages due to PY3 incompatible division:

response.data["pagination"]
{'previous': None, 'count': 3, 'num_pages': 1.02, 'next': 'http://apros.devstack.lms?ajax=1&page=2'}

Which results in PageNotFoundError:

is_thread)):
  File "/edx/src/discussion-edx-platform-extensions/social_engagement/engagement.py", line 382, in _get_paginated_results
    has_next = response.data["pagination"]["next"]
  File "/edx/app/edxapp/edx-platform/lms/djangoapps/discussion/rest_api/views.py", line 526, in retrieve
    form.cleaned_data["requested_fields"],
  File "/edx/app/edxapp/edx-platform/lms/djangoapps/discussion/rest_api/api.py", line 1074, in get_response_comments
    raise PageNotFoundError("Page not found (No results on this page).")
openedx.core.lib.exceptions.PageNotFoundError: Page not found (No results on this page).
2021-01-05 20:13:09 +05:00
David Ormsbee
a333a71411 Format blackout dates to match rest of Discussions API.
Technically, both "2020-10-20T23:59:00Z" and "2020-10-20T23:59:00+00:00"
are ISO-8601 compliant, though the latter is preferred. The Discussions
API uses the "Z" notation for almost all its dates, except for the
course blackout dates (those times when students aren't allowed to post
anything because it would threaten exam integrity). That's because the
blackout dates are manually formatted using datetime.isoformat().

As best as I can tell, we've always passed back the "+00:00" for the
blackout dates. But at some point, this broke the expectations of the
mobile apps, which expect the "+Z" format, like the rest of the API.
This commit changes the blackout dates to be returned in +Z format when
the blackout datetimes are specified by the user in UTC (which is almost
always the case–I suspect the mobile clients would break if the dates
were specified in other timezones anyhow).
2020-11-23 10:30:12 -05:00
Aarif
98af9ce418 remove useless-supression warnings 2020-05-01 19:42:15 +05:00
Feanil Patel
9cf2f9f298 Run 2to3 -f future . -w
This will remove imports from __future__ that are no longer needed.

https://docs.python.org/3.5/library/2to3.html#2to3fixer-future
2019-12-30 10:35:30 -05:00
arbisoft
641ba0215a BOM-296
Fixing python3
2019-08-29 16:58:25 +05:00
Ned Batchelder
b3a731550c Fix problems that drf-yasg uncovered.
These were originally fixed individually, but had to be reverted, and
are now combined in one commit.  The originals were:

7b9040f6b0 This enum was backwards
8774ff1f9b Use ref_name to disambiguate serializers that drf-yasg would otherwise assume are the same.
8a44397139 Is this field missing because it is None?
4a1154a7ca Give a safer buffer for clearing the rate limiting
64c47856dd DRF 3.7.4 changed how you delegate to another view, so don't
7359ca4fb2 Is this right? It fixes two tests
fdd66e5390 Adjust the expected error message for DRF 3.7.7
9257f68fd8 The default TIME_ZONE should be UTC
2019-06-21 18:04:15 -04:00
Ned Batchelder
39c7a2db7c Revert "Use drf-yasg for Open API documentation" 2019-06-11 16:05:00 -04:00
Ned Batchelder
64c47856dd DRF 3.7.4 changed how you delegate to another view, so don't
The error in the test was:
```
AssertionError: The `request` argument must be an instance of `django.http.HttpRequest`, not `rest_framework.request.Request`.
```
The (controversial) incompatible change was in 3.7.4: https://github.com/encode/django-rest-framework/pull/5618

I'll look into whether there's another way to address it.

<details>
  <summary>Full error report</summary>

```
AssertionError: The `request` argument must be an instance of `django.http.HttpRequest`, not `rest_framework.request.Request`.

Stacktrace

self = <lms.djangoapps.discussion_api.tests.test_views.CommentViewSetListTest testMethod=test_profile_image_request_for_null_endorsed_by>

    def test_profile_image_request_for_null_endorsed_by(self):
        """
        Tests if 'endorsed' is True but 'endorsed_by' is null, the api does not crash.
        This is the case for some old/stale data in prod/stage environments.
        """
        self.register_get_user_response(self.user)
        thread = self.make_minimal_cs_thread({
            "thread_type": "question",
            "endorsed_responses": [make_minimal_cs_comment({
                "id": "endorsed_comment",
                "user_id": self.user.id,
                "username": self.user.username,
                "endorsed": True,
            })],
            "non_endorsed_resp_total": 0,
        })
        self.register_get_thread_response(thread)
        self.create_profile_image(self.user, get_profile_image_storage())

        response = self.client.get(self.url, {
            "thread_id": thread["id"],
            "endorsed": True,
>           "requested_fields": "profile_image",
        })

lms/djangoapps/discussion_api/tests/test_views.py:1446:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/test.py:291: in get
    response = super(APIClient, self).get(path, data=data, **extra)
../venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/test.py:208: in get
    return self.generic('GET', path, **r)
../venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/test.py:237: in generic
    method, path, data, content_type, secure, **extra)
../venvs/edxapp/local/lib/python2.7/site-packages/django/test/client.py:416: in generic
    return self.request(**r)
../venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/test.py:288: in request
    return super(APIClient, self).request(**kwargs)
../venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/test.py:240: in request
    request = super(APIRequestFactory, self).request(**kwargs)
../venvs/edxapp/local/lib/python2.7/site-packages/django/test/client.py:501: in request
    six.reraise(*exc_info)
../venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/exception.py:41: in inner
    response = get_response(request)
../venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py:249: in _legacy_get_response
    response = self._get_response(request)
../venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py:187: in _get_response
    response = self.process_exception_by_middleware(e, request)
../venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py:185: in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
../venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py:185: in inner
    return func(*args, **kwargs)
../venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/csrf.py:58: in wrapped_view
    return view_func(*args, **kwargs)
../venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/viewsets.py:95: in view
    return self.dispatch(request, *args, **kwargs)
../venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py:494: in dispatch
    response = self.handle_exception(exc)
../venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py:491: in dispatch
    response = handler(request, *args, **kwargs)
lms/djangoapps/discussion_api/views.py:505: in list
    form.cleaned_data["requested_fields"],
lms/djangoapps/discussion_api/api.py:659: in get_comment_list
    results = _serialize_discussion_entities(request, context, responses, requested_fields, DiscussionEntity.comment)
lms/djangoapps/discussion_api/api.py:468: in _serialize_discussion_entities
    request, results, usernames, discussion_entity_type, include_profile_image
lms/djangoapps/discussion_api/api.py:413: in _add_additional_response_fields
    username_profile_dict = _get_user_profile_dict(request, usernames=','.join(usernames))
lms/djangoapps/discussion_api/api.py:350: in _get_user_profile_dict
    user_profile_details = AccountViewSet.as_view({'get': 'list'})(request).data
../venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/csrf.py:58: in wrapped_view
    return view_func(*args, **kwargs)
../venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/viewsets.py:95: in view
    return self.dispatch(request, *args, **kwargs)
../venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py:477: in dispatch
    request = self.initialize_request(request, *args, **kwargs)
../venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/viewsets.py:118: in initialize_request
    request = super(ViewSetMixin, self).initialize_request(request, *args, **kwargs)
../venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py:381: in initialize_request
    parser_context=parser_context
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <rest_framework.request.Request object at 0x7f597c773890>
request = <rest_framework.request.Request object at 0x7f597fa20f90>
parsers = [<openedx.core.lib.api.parsers.MergePatchParser object at 0x7f59810c32d0>]
authenticators = [<edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication object at 0x7f597c713690>, <openedx.core.lib...rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser object at 0x7f597c773390>]
negotiator = <rest_framework.negotiation.DefaultContentNegotiation object at 0x7f597fa20410>
parser_context = {'args': (), 'kwargs': {}, 'view': <openedx.core.djangoapps.user_api.accounts.views.AccountViewSet object at 0x7f597c7846d0>}

    def __init__(self, request, parsers=None, authenticators=None,
                 negotiator=None, parser_context=None):
        assert isinstance(request, HttpRequest), (
            'The `request` argument must be an instance of '
            '`django.http.HttpRequest`, not `{}.{}`.'
>           .format(request.__class__.__module__, request.__class__.__name__)
        )
E       AssertionError: The `request` argument must be an instance of `django.http.HttpRequest`, not `rest_framework.request.Request`.

../venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/request.py:159: AssertionError
```
</details>
2019-06-10 15:27:39 -04:00
Stu Young
13e624a50b INCR-307 Run python-modernize on lms/djangoapps/discussion/rest_api (#20618)
* run python modernize

* run isort

* Fix quality
2019-05-28 12:51:49 -04:00
Nimisha Asthagiri
dfa3728edf Move django_comment_common from common to openedx 2019-05-03 12:10:18 -04:00
Nimisha Asthagiri
c606aaeb57 Discussion consolidation: quality 2019-05-03 12:09:47 -04:00
Nimisha Asthagiri
e160b23903 Move django_comment_client to discussion/ 2019-05-03 12:09:46 -04:00
Nimisha Asthagiri
b949452eb2 Move discussion_api to discussion/rest_api 2019-05-03 12:07:21 -04:00
Nimisha Asthagiri
ef0e06cc0a Revert "Discussions consolidation" 2019-05-02 14:59:56 -04:00
Nimisha Asthagiri
df962a31b7 Move django_comment_common to openedx/core/djangoapps/discussion_common 2019-05-01 19:15:02 -04:00
Nimisha Asthagiri
c2e232a3d4 Discussion consolidation: quality 2019-05-01 19:13:10 -04:00
Nimisha Asthagiri
db89a64d06 Move django_comment_client to discussion/ 2019-05-01 19:13:10 -04:00
Nimisha Asthagiri
3d1bb23809 Move discussion_api to discussion/rest_api 2019-05-01 19:13:10 -04:00