pyupgrade on rss_proxy and shoppingcart (#26628)

This commit is contained in:
M. Zulqarnain
2021-02-22 12:58:09 +05:00
committed by GitHub
parent 95d6397f41
commit b6a2b91dd5
9 changed files with 24 additions and 43 deletions

View File

@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import migrations, models
import django.utils.timezone
import model_utils.fields

View File

@@ -1,9 +1,6 @@
"""
Models for the rss_proxy djangoapp.
"""
import six
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from model_utils.models import TimeStampedModel
@@ -19,9 +16,9 @@ class WhitelistedRssUrl(TimeStampedModel):
"""
url = models.CharField(max_length=255, unique=True, db_index=True)
class Meta(object):
class Meta:
""" Meta class for this Django model """
app_label = "rss_proxy"
def __str__(self):
return six.text_type(self.url)
return str(self.url)

View File

@@ -1,9 +1,6 @@
"""
Tests for the rss_proxy models
"""
import six
from django.test import TestCase
from lms.djangoapps.rss_proxy.models import WhitelistedRssUrl
@@ -13,11 +10,11 @@ class WhitelistedRssUrlTests(TestCase):
""" Tests for the rss_proxy.WhitelistedRssUrl model """
def setUp(self):
super(WhitelistedRssUrlTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
super().setUp()
self.whitelisted_rss_url = WhitelistedRssUrl.objects.create(url='http://www.example.com')
def test_unicode(self):
"""
Test the unicode function returns the url
"""
assert six.text_type(self.whitelisted_rss_url) == self.whitelisted_rss_url.url
assert str(self.whitelisted_rss_url) == self.whitelisted_rss_url.url

View File

@@ -3,9 +3,10 @@ Tests for the rss_proxy views
"""
from unittest.mock import Mock, patch
from django.test import TestCase
from django.urls import reverse
from mock import Mock, patch
from lms.djangoapps.rss_proxy.models import WhitelistedRssUrl
@@ -14,7 +15,7 @@ class RssProxyViewTests(TestCase):
""" Tests for the rss_proxy views """
def setUp(self):
super(RssProxyViewTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
super().setUp()
self.whitelisted_url1 = 'http://www.example.com'
self.whitelisted_url2 = 'http://www.example.org'
@@ -45,7 +46,7 @@ class RssProxyViewTests(TestCase):
Test the proxy view with a whitelisted URL
"""
mock_requests_get.return_value = Mock(status_code=200, content=self.rss)
resp = self.client.get('%s?url=%s' % (reverse('rss_proxy:proxy'), self.whitelisted_url1))
resp = self.client.get('{}?url={}'.format(reverse('rss_proxy:proxy'), self.whitelisted_url1))
assert resp.status_code == 200
assert resp['Content-Type'] == 'application/xml'
assert resp.content.decode('utf-8') == self.rss
@@ -56,7 +57,7 @@ class RssProxyViewTests(TestCase):
Test the proxy view with a whitelisted URL that is not found
"""
mock_requests_get.return_value = Mock(status_code=404)
resp = self.client.get('%s?url=%s' % (reverse('rss_proxy:proxy'), self.whitelisted_url2))
resp = self.client.get('{}?url={}'.format(reverse('rss_proxy:proxy'), self.whitelisted_url2))
print(resp.status_code)
print(resp.content)
print(resp['Content-Type'])
@@ -68,5 +69,5 @@ class RssProxyViewTests(TestCase):
"""
Test the proxy view with a non-whitelisted URL
"""
resp = self.client.get('%s?url=%s' % (reverse('rss_proxy:proxy'), self.non_whitelisted_url))
resp = self.client.get('{}?url={}'.format(reverse('rss_proxy:proxy'), self.non_whitelisted_url))
assert resp.status_code == 404

View File

@@ -25,7 +25,7 @@ def proxy(request):
status_code = 200
rss = cache.get(cache_key, '')
print(cache_key)
print(u'Cached rss: %s' % rss)
print('Cached rss: %s' % rss)
if not rss:
# Go get the RSS from the URL if it was not cached
resp = requests.get(url)

View File

@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
import django.db.models.deletion
import django.utils.timezone
import model_utils.fields
@@ -116,7 +113,7 @@ class Migration(migrations.Migration):
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
('qty', models.IntegerField(default=1, help_text='The number of items sold.')),
('unit_price', models.DecimalField(default=0.0, help_text='The price per item sold, including discounts.', max_digits=30, decimal_places=2)),
('currency', models.CharField(default=u'usd', help_text='Lower-case ISO currency codes', max_length=8)),
('currency', models.CharField(default='usd', help_text='Lower-case ISO currency codes', max_length=8)),
],
),
migrations.CreateModel(
@@ -126,9 +123,9 @@ class Migration(migrations.Migration):
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
('amount', models.DecimalField(default=0.0, help_text='The amount of the transaction. Use positive amounts for payments and negative amounts for refunds.', max_digits=30, decimal_places=2)),
('currency', models.CharField(default=u'usd', help_text='Lower-case ISO currency codes', max_length=8)),
('currency', models.CharField(default='usd', help_text='Lower-case ISO currency codes', max_length=8)),
('comments', models.TextField(help_text='Optional: provide additional information for this transaction', null=True, blank=True)),
('status', models.CharField(default=u'started', help_text="The status of the payment or refund. 'started' means that payment is expected, but money has not yet been transferred. 'completed' means that the payment or refund was received. 'cancelled' means that payment or refund was expected, but was cancelled before money was transferred. ", max_length=32, choices=[(u'started', u'started'), (u'completed', u'completed'), (u'cancelled', u'cancelled')])),
('status', models.CharField(default='started', help_text="The status of the payment or refund. 'started' means that payment is expected, but money has not yet been transferred. 'completed' means that the payment or refund was received. 'cancelled' means that payment or refund was expected, but was cancelled before money was transferred. ", max_length=32, choices=[('started', 'started'), ('completed', 'completed'), ('cancelled', 'cancelled')])),
('created_by', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
('invoice', models.ForeignKey(to='shoppingcart.Invoice', on_delete=models.CASCADE)),
('last_modified_by', models.ForeignKey(related_name='last_modified_by_user', to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
@@ -138,8 +135,8 @@ class Migration(migrations.Migration):
name='Order',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('currency', models.CharField(default=u'usd', max_length=8)),
('status', models.CharField(default=u'cart', max_length=32, choices=[(u'cart', u'cart'), (u'paying', u'paying'), (u'purchased', u'purchased'), (u'refunded', u'refunded'), (u'defunct-cart', u'defunct-cart'), (u'defunct-paying', u'defunct-paying')])),
('currency', models.CharField(default='usd', max_length=8)),
('status', models.CharField(default='cart', max_length=32, choices=[('cart', 'cart'), ('paying', 'paying'), ('purchased', 'purchased'), ('refunded', 'refunded'), ('defunct-cart', 'defunct-cart'), ('defunct-paying', 'defunct-paying')])),
('purchase_time', models.DateTimeField(null=True, blank=True)),
('refunded_time', models.DateTimeField(null=True, blank=True)),
('bill_to_first', models.CharField(max_length=64, blank=True)),
@@ -159,7 +156,7 @@ class Migration(migrations.Migration):
('recipient_name', models.CharField(max_length=255, null=True, blank=True)),
('recipient_email', models.CharField(max_length=255, null=True, blank=True)),
('customer_reference_number', models.CharField(max_length=63, null=True, blank=True)),
('order_type', models.CharField(default=u'personal', max_length=32, choices=[(u'personal', u'personal'), (u'business', u'business')])),
('order_type', models.CharField(default='personal', max_length=32, choices=[('personal', 'personal'), ('business', 'business')])),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
],
),
@@ -169,16 +166,16 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
('status', models.CharField(default=u'cart', max_length=32, db_index=True, choices=[(u'cart', u'cart'), (u'paying', u'paying'), (u'purchased', u'purchased'), (u'refunded', u'refunded'), (u'defunct-cart', u'defunct-cart'), (u'defunct-paying', u'defunct-paying')])),
('status', models.CharField(default='cart', max_length=32, db_index=True, choices=[('cart', 'cart'), ('paying', 'paying'), ('purchased', 'purchased'), ('refunded', 'refunded'), ('defunct-cart', 'defunct-cart'), ('defunct-paying', 'defunct-paying')])),
('qty', models.IntegerField(default=1)),
('unit_cost', models.DecimalField(default=0.0, max_digits=30, decimal_places=2)),
('list_price', models.DecimalField(null=True, max_digits=30, decimal_places=2)),
('line_desc', models.CharField(default=u'Misc. Item', max_length=1024)),
('currency', models.CharField(default=u'usd', max_length=8)),
('line_desc', models.CharField(default='Misc. Item', max_length=1024)),
('currency', models.CharField(default='usd', max_length=8)),
('fulfilled_time', models.DateTimeField(null=True, db_index=True)),
('refund_requested_time', models.DateTimeField(null=True, db_index=True)),
('service_fee', models.DecimalField(default=0.0, max_digits=30, decimal_places=2)),
('report_comments', models.TextField(default=u'')),
('report_comments', models.TextField(default='')),
],
),
migrations.CreateModel(
@@ -231,7 +228,7 @@ class Migration(migrations.Migration):
name='Donation',
fields=[
('orderitem_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='shoppingcart.OrderItem', on_delete=models.CASCADE)),
('donation_type', models.CharField(default=u'general', max_length=32, choices=[(u'general', u'A general donation'), (u'course', u'A donation to a particular course')])),
('donation_type', models.CharField(default='general', max_length=32, choices=[('general', 'A general donation'), ('course', 'A donation to a particular course')])),
('course_id', CourseKeyField(max_length=255, db_index=True)),
],
bases=('shoppingcart.orderitem',),

View File

@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import migrations, models

View File

@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import migrations, models
@@ -14,11 +11,11 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='courseregcodeitem',
name='mode',
field=models.SlugField(default=u'honor'),
field=models.SlugField(default='honor'),
),
migrations.AlterField(
model_name='paidcourseregistration',
name='mode',
field=models.SlugField(default=u'honor'),
field=models.SlugField(default='honor'),
),
]

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.13 on 2018-05-14 20:37