Moves common test utilities from devhub to amo

This commit is contained in:
Kumar McMillan 2011-04-29 16:39:14 -05:00
Родитель 76de7c47fe
Коммит 0c7901dbd6
2 изменённых файлов: 36 добавлений и 33 удалений

Просмотреть файл

@ -1,3 +1,6 @@
from datetime import datetime, timedelta
import time
from django import forms
from redisutils import mock_redis, reset_redis
@ -48,3 +51,34 @@ class RedisTest(object):
def tearDown(self):
super(RedisTest, self).tearDown()
reset_redis(self._redis)
def close_to_now(dt):
"""
Make sure the datetime is within a minute from `now`.
"""
dt_ts = time.mktime(dt.timetuple())
dt_minute_ts = time.mktime((dt + timedelta(minutes=1)).timetuple())
now_ts = time.mktime(datetime.now().timetuple())
return now_ts >= dt_ts and now_ts < dt_minute_ts
def assert_no_validation_errors(validation):
"""Assert that the validation (JSON) does not contain a traceback.
Note that this does not test whether the addon passed
validation or not.
"""
if hasattr(validation, 'task_error'):
# FileUpload object:
error = validation.task_error
else:
# Upload detail - JSON output
error = validation['error']
if error:
print '-' * 70
print error
print '-' * 70
raise AssertionError("Unexpected task error: %s" %
error.rstrip().split("\n")[-1])

Просмотреть файл

@ -5,7 +5,6 @@ import re
import shutil
import socket
import tempfile
import time
from datetime import datetime, timedelta
from decimal import Decimal
from collections import namedtuple
@ -25,7 +24,8 @@ import amo
import amo.tests
import paypal
from amo.urlresolvers import reverse
from amo.tests import formset, initial
from amo.tests import (formset, initial, close_to_now,
assert_no_validation_errors)
from amo.tests.test_helpers import get_image_path
from addons import cron
from addons.forms import AddonFormBasic
@ -43,37 +43,6 @@ from users.models import UserProfile
from versions.models import ApplicationsVersions, License, Version
def assert_no_validation_errors(validation):
"""Assert that the validation (JSON) does not contain a traceback.
Note that this does not test whether the addon passed
validation or not.
"""
if hasattr(validation, 'task_error'):
# FileUpload object:
error = validation.task_error
else:
# Upload detail - JSON output
error = validation['error']
if error:
print '-' * 70
print error
print '-' * 70
raise AssertionError("Unexpected task error: %s" %
error.rstrip().split("\n")[-1])
def close_to_now(dt):
"""
Make sure the datetime is within a minute from `now`.
"""
dt_ts = time.mktime(dt.timetuple())
dt_minute_ts = time.mktime((dt + timedelta(minutes=1)).timetuple())
now_ts = time.mktime(datetime.now().timetuple())
return now_ts >= dt_ts and now_ts < dt_minute_ts
class MetaTests(test_utils.TestCase):
def test_assert_close_to_now(dt):