Merge remote-tracking branch 'Gluejar/master' into dj111

# Conflicts:
#	core/tests.py
#	payment/tests.py
pull/95/head
eric 2018-04-25 16:23:00 -04:00
commit 3337de9a2e
24 changed files with 41 additions and 211 deletions

View File

@ -10,6 +10,7 @@ django imports
from django.contrib.auth.models import User
from django.test import TestCase
from django.test.client import Client
from django.utils.timezone import now
"""
regluit imports
@ -17,7 +18,6 @@ regluit imports
import regluit.core.isbn
from regluit.core import models
from regluit.utils.localdatetime import now
from regluit.api import models as apimodels
class ApiTests(TestCase):

View File

@ -23,6 +23,7 @@ from django_comments.models import Comment
from github3 import (login, GitHub)
from github3.repos.release import Release
from django.utils.timezone import now
from gitenberg.metadata.pandata import Pandata
# regluit imports
@ -31,7 +32,6 @@ import regluit
import regluit.core.isbn
from regluit.core.validation import test_file
from regluit.marc.models import inverse_marc_rels
from regluit.utils.localdatetime import now
from . import cc
from . import models

View File

@ -229,9 +229,9 @@ def load_doab_edition(title, doab_id, url, format, rights,
break
if edition is not None:
# if this is a new edition, then add related editions asynchronously
# if this is a new edition, then add related editions SYNCHRONOUSLY
if getattr(edition, 'new', False):
tasks.populate_edition.delay(edition.isbn_13)
tasks.populate_edition(edition.isbn_13)
doab_identifer = models.Identifier.get_or_add(type='doab', value=doab_id,
work=edition.work)
@ -421,6 +421,9 @@ def load_doab_oai(from_year=None, limit=100000):
for record in doab_client.listRecords(metadataPrefix='oai_dc', from_=from_):
if not record[1]:
continue
item_type = unlist(record[1].getMap().get('type', None))
if item_type != 'book':
continue
idents = record[1].getMap()['identifier']
if idents:
for ident in idents:

View File

@ -4,9 +4,9 @@ from random import randint, randrange
from django.conf import settings
from django.core.management.base import BaseCommand
from django.utils.timezone import now
from regluit.core.models import Work, Campaign
from regluit.utils.localdatetime import now
class Command(BaseCommand):
help = "creates random campaigns for any works that lack one for testing"

View File

@ -26,6 +26,7 @@ from django.core.files.base import ContentFile
from django.db import models
from django.db.models import F, Q
from django.db.models.signals import post_save
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
#regluit imports
@ -46,7 +47,7 @@ from regluit.payment.parameters import (
TRANSACTION_STATUS_INCOMPLETE
)
from regluit.utils import crypto
from regluit.utils.localdatetime import now, date_today
from regluit.utils.localdatetime import date_today
from regluit.core.parameters import (
REWARDS,

View File

@ -20,10 +20,10 @@ from django.core.urlresolvers import reverse
from django.db import models
from django.db.models import F
from django.db.models.signals import post_save, pre_delete
from django.utils.timezone import now
import regluit
from regluit.marc.models import MARCRecord as NewMARC
from regluit.utils.localdatetime import now
from questionnaire.models import Landing
from regluit.core import mobi

View File

@ -22,6 +22,7 @@ from django.db.utils import DatabaseError
from django.dispatch import Signal
from django.utils.translation import ugettext_noop as _
from django.template.loader import render_to_string
from django.utils.timezone import now
from notification import models as notification
@ -29,9 +30,9 @@ from notification import models as notification
regluit imports
"""
from regluit.payment.signals import transaction_charged, transaction_failed, pledge_modified, pledge_created
from regluit.utils.localdatetime import now, date_today
from regluit.core.parameters import REWARDS, BUY2UNGLUE, THANKS, LIBRARY, RESERVE, THANKED
from regluit.libraryauth.models import Library, LibraryUser
from regluit.utils.localdatetime import date_today
logger = logging.getLogger(__name__)

View File

@ -13,6 +13,7 @@ django imports
from django.conf import settings
from django.contrib.auth.models import User
from django.core.mail import send_mail
from django.utils.timezone import now
from notification.engine import send_all
from notification import models as notification
@ -29,8 +30,7 @@ from regluit.core import (
from regluit.core.models import Campaign, Acq, Gift
from regluit.core.signals import deadline_impending
from regluit.core.parameters import RESERVE, REWARDS, THANKS
from regluit.utils.localdatetime import now, date_today
from regluit.utils.localdatetime import date_today
logger = logging.getLogger(__name__)

View File

@ -26,6 +26,7 @@ from django.http import Http404
from django.test import TestCase
from django.test.client import Client
from django.test.utils import override_settings
from django.utils.timezone import now
from django_comments.models import Comment
@ -65,8 +66,8 @@ from regluit.core.validation import valid_subject
from regluit.frontend.views import safe_get_work
from regluit.payment.models import Transaction
from regluit.payment.parameters import PAYMENT_TYPE_AUTHORIZATION
from regluit.utils.localdatetime import now, date_today
from regluit.pyepub import EPUB
from regluit.utils.localdatetime import date_today
from .epub import test_epub
from .pdf import test_pdf
@ -999,58 +1000,6 @@ class DownloadPageTest(TestCase):
eb2.delete()
self.assertFalse(eb2.edition.work.is_free)
class LocaldatetimeTest(TestCase):
@override_settings(LOCALDATETIME_NOW=None)
def test_LOCALDATETIME_NOW_none(self):
try:
localdatetime.now
except NameError:
from regluit.utils import localdatetime
else:
reload(localdatetime)
self.assertAlmostEqual(
mktime(datetime.now().timetuple()),
mktime(localdatetime.now().timetuple()),
1.0
)
@override_settings(LOCALDATETIME_NOW=lambda: datetime.now() + timedelta(365))
def test_LOCALDATETIME_NOW_year_ahead(self):
try:
localdatetime.now
except NameError:
from regluit.utils import localdatetime
else:
reload(localdatetime)
self.assertAlmostEqual(
mktime((datetime.now() + timedelta(365)).timetuple()),
mktime(localdatetime.now().timetuple()),
1.0
)
def test_no_time_override(self):
from regluit.utils import localdatetime
self.assertAlmostEqual(
mktime(datetime.now().timetuple()),
mktime(localdatetime.now().timetuple()),
1.0
)
def tearDown(self):
# restore localdatetime.now() to what's in the settings file
try:
localdatetime.now
except NameError:
from regluit.utils import localdatetime
else:
reload(localdatetime)
class MailingListTests(TestCase):
#mostly to check that MailChimp account is setp correctly

View File

@ -13,11 +13,11 @@ from django.conf import settings
from django.forms.extras.widgets import SelectDateWidget
from django.forms.widgets import RadioSelect
from django.utils.translation import ugettext_lazy as _
from django.utils.timezone import now
from regluit.core.lookups import OwnerLookup
from regluit.core.models import Campaign, Edition, Claim, RightsHolder, WasWork
from regluit.core.parameters import *
from regluit.utils.localdatetime import now
class RightsHolderForm(forms.ModelForm):
email = forms.EmailField(

View File

@ -163,7 +163,7 @@
<div class="column">
<span>Contact</span>
<ul>
<li> <a href="mailto:info@ebookfoundation.org"><i class="fa fa-envelope fa-2x"></i></a> <a href="https://twitter.com/unglueit"><i class="fa fa-twitter fa-2x"></i></a> <a href="https://facebook/com/unglueit"><i class="fa fa-facebook fa-2x"></i></a></li>
<li> <a href="mailto:info@ebookfoundation.org"><i class="fa fa-envelope fa-2x"></i></a> <a href="https://twitter.com/unglueit"><i class="fa fa-twitter fa-2x"></i></a> <a href="https://facebook.com/unglueit"><i class="fa fa-facebook fa-2x"></i></a></li>
</ul>
</div>
</div>

View File

@ -1,5 +1,6 @@
from django import template
from regluit.utils.localdatetime import now
from django.utils.timezone import now
from regluit.core.parameters import REWARDS, BUY2UNGLUE
register = template.Library()

View File

@ -1,4 +1,4 @@
from regluit.utils.localdatetime import now
from django.utils.timezone import now
from django import template
register = template.Library()

View File

@ -1,5 +1,6 @@
from regluit.utils.localdatetime import now
from django import template
from django.utils.timezone import now
from regluit.core.models import Acq
register = template.Library()

View File

@ -13,6 +13,7 @@ from django.core import mail
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
from django.utils.timezone import now
from notification.models import Notice
@ -21,7 +22,6 @@ from regluit.core.models import Work, Campaign, RightsHolder, Claim, Subject
from regluit.payment.models import Transaction
from regluit.payment.manager import PaymentManager
from regluit.payment.stripelib import StripeClient, TEST_CARDS, ERROR_TESTING, card
from regluit.utils.localdatetime import now
class WishlistTests(TestCase):
fixtures = ['initial_data.json', 'neuromancer.json']

View File

@ -45,6 +45,7 @@ from django.template import TemplateDoesNotExist
from django.template.loader import render_to_string
from django.utils.http import urlencode
from django.utils.translation import ugettext_lazy as _
from django.utils.timezone import now
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from django.views.generic.edit import FormView
@ -123,11 +124,11 @@ from regluit.payment.parameters import (
COMPANY_TITLE
)
from regluit.utils.localdatetime import now, date_today
from regluit.libraryauth.forms import UserNamePass
from regluit.libraryauth.views import Authenticator, superlogin, login_user
from regluit.libraryauth.models import Library
from regluit.marc.views import qs_marc_records
from regluit.utils.localdatetime import date_today
from questionnaire.models import Landing, Questionnaire
from questionnaire.views import export_summary as answer_summary, export_csv as export_answers

View File

@ -10,12 +10,12 @@ from datetime import timedelta
django imports
"""
from django.http import HttpResponseForbidden
from django.utils.timezone import now
"""
regluit imports
"""
from regluit.payment.models import PaymentResponse
from regluit.utils.localdatetime import now, zuluformat
class ProcessorError(Exception):
"""An abstraction around payment processor exceptions"""

View File

@ -18,6 +18,7 @@ django imports
from django.conf import settings
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.utils.timezone import now
"""
regluit imports
@ -26,7 +27,6 @@ from regluit.payment import credit
from regluit.payment.models import Transaction, Receiver, PaymentResponse, Account
from regluit.payment.parameters import *
from regluit.payment.signals import transaction_charged, pledge_modified, pledge_created
from regluit.utils.localdatetime import now
logger = logging.getLogger(__name__)

View File

@ -18,6 +18,7 @@ from django.db.models import Q
from django.contrib.sites.models import Site
from django.db.models.signals import post_save, post_delete
from django.utils.http import urlquote
from django.utils.timezone import now
## django module imports
@ -42,7 +43,7 @@ from regluit.payment.parameters import (
)
from regluit.payment.signals import credit_balance_added, pledge_created
from regluit.utils.localdatetime import now, date_today
from regluit.utils.localdatetime import date_today
logger = logging.getLogger(__name__)

View File

@ -22,6 +22,7 @@ django imports
from django.conf import settings
from django.core.mail import send_mail
from django.http import HttpResponse
from django.utils.timezone import now
"""
regluit imports
@ -38,7 +39,6 @@ from regluit.payment.parameters import (
TRANSACTION_STATUS_CANCELED
)
from regluit.payment.signals import transaction_charged, transaction_failed
from regluit.utils.localdatetime import now, zuluformat
# as of 2013.07.15
# ['charge.disputed', 'coupon.updated'] are legacy events -- don't know whether to

View File

@ -20,6 +20,11 @@ from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.core.validators import URLValidator
from django.test import TestCase
<<<<<<< HEAD
=======
from django.utils import unittest
from django.utils.timezone import now
>>>>>>> Gluejar/master
"""
regluit imports
@ -29,7 +34,6 @@ from regluit.core.signals import handle_transaction_charged
from regluit.payment.manager import PaymentManager
from regluit.payment.models import Transaction, Account
from regluit.payment.parameters import *
from regluit.utils.localdatetime import now
def setup_selenium():
# Set the display window for our xvfb

View File

@ -24,6 +24,7 @@ from django.http import (
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.test.utils import setup_test_environment
from django.utils.timezone import now
from django.views.decorators.csrf import csrf_exempt
from django.views.generic.edit import FormView
from django.views.generic.base import TemplateView
@ -38,7 +39,6 @@ from regluit.payment.models import Transaction
from regluit.payment.parameters import *
from regluit.payment.stripelib import STRIPE_PK
from regluit.payment.tests import PledgeTest, AuthorizeTest
from regluit.utils.localdatetime import now
logger = logging.getLogger(__name__)

View File

@ -1 +1 @@
import localdatetime

View File

@ -1,140 +1,8 @@
"""
Utility to return datetime.datetime.utcnow() by default but allows for a custom utcnow() (e.g., for testing)
from django.utils.timezone import now
>>> import regluit
>>> from regluit.utils.localdatetime import now
>>> now()
datetime.datetime(2012, 3, 8, 14, 0, 35, 409270)
>>> now()
datetime.datetime(2012, 3, 8, 14, 0, 36, 985271)
>>> n = now()
>>> n
datetime.datetime(2012, 3, 8, 14, 1, 54, 650679)
>>> regluit.utils.localdatetime._now = lambda: n
>>> now()
datetime.datetime(2012, 3, 8, 14, 1, 54, 650679)
>>> now()
datetime.datetime(2012, 3, 8, 14, 1, 54, 650679)
>>> now()
DST handled:
>>> ptz = pytz.timezone('America/Los_Angeles')
>>> make_naive(datetime.datetime(2012,03,11,10,tzinfo=utc), ptz)
datetime.datetime(2012, 3, 11, 3, 0)
>>> make_naive(datetime.datetime(2012,03,11,9,tzinfo=utc), ptz)
datetime.datetime(2012, 3, 11, 1, 0)
>>> make_aware(datetime.datetime(2012,11,4,1,30), ptz)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/raymondyee/C/src/Gluejar/regluit/utils/localdatetime.py", line 90, in make_aware
return timezone.localize(value, is_dst=None)
File "/Users/raymondyee/.virtualenvs/regluit/lib/python2.7/site-packages/pytz/tzinfo.py", line 349, in localize
raise AmbiguousTimeError(dt)
AmbiguousTimeError: 2012-11-04 01:30:00
"""
import pytz
import datetime
import django
from django.conf import settings
# for Django 1.3.x, return a timestamp naive now()
# for Django 1.4 should switch to django.utils.timezone.now()
# see https://code.djangoproject.com/browser/django/trunk/django/utils/timezone.py?rev=17642#L232
def now():
if hasattr(settings, 'LOCALDATETIME_NOW') and settings.LOCALDATETIME_NOW is not None:
return settings.LOCALDATETIME_NOW()
else:
try:
return django.utils.timezone.now()
except AttributeError, e:
return datetime.datetime.now()
# provide a replacement for datetime.date.today()
# this will be timezone naive -- is that what we really want?
# switch to django.utils.timezone.localdate in django 1.11
def date_today():
return now().date()
# borrow a lot of the routines/code that will be in Django 1.4+ django.utils.timezone
# https://code.djangoproject.com/browser/django/trunk/django/utils/timezone.py
utc = pytz.utc
def get_default_timezone():
return pytz.timezone(settings.TIME_ZONE)
def is_aware(value):
"""
Determines if a given datetime.datetime is aware.
The logic is described in Python's docs:
http://docs.python.org/library/datetime.html#datetime.tzinfo
"""
return value.tzinfo is not None and value.tzinfo.utcoffset(value) is not None
def is_naive(value):
"""
Determines if a given datetime.datetime is naive.
The logic is described in Python's docs:
http://docs.python.org/library/datetime.html#datetime.tzinfo
"""
return value.tzinfo is None or value.tzinfo.utcoffset(value) is None
def make_aware(value, timezone):
"""
Makes a naive datetime.datetime in a given time zone aware.
"""
if hasattr(timezone, 'localize'):
# available for pytz time zones
return timezone.localize(value, is_dst=None)
else:
# may be wrong around DST changes
return value.replace(tzinfo=timezone)
def make_naive(value, timezone):
"""
Makes an aware datetime.datetime naive in a given time zone.
"""
value = value.astimezone(timezone)
if hasattr(timezone, 'normalize'):
# available for pytz time zones
value = timezone.normalize(value)
return value.replace(tzinfo=None)
def isoformat(value):
"""
if value is naive, assume it's in the default_timezone
"""
if is_naive(value):
return make_aware(value, get_default_timezone()).isoformat()
else:
return value.isoformat()
def zuluformat(value):
"""format value in zulu format -- e.g., 2012-03-26T17:47:22.654449Z"""
return "{0}Z".format(as_utc_naive(value).isoformat())
def as_utc_naive(value):
"""
if value is naive, assume it's in the default time zone, then convert to UTC but make naive
"""
if is_naive(value):
return make_naive(make_aware(value, get_default_timezone()), utc)
else:
return make_naive(value, utc)
def as_default_timezone_naive(value):
"""
if value is naive, assume it's in UTC and convert to the default tz and make it naive
"""
if is_naive(value):
return make_naive(make_aware(value, utc), get_default_timezone())
else:
return make_naive(value, get_default_timezone())