mocking myqueue in most tests
This commit is contained in:
@@ -49,6 +49,17 @@ redis_connection = StrictRedis()
|
|||||||
|
|
||||||
from django_mailbox.models import Mailbox,MessageAttachment,Message
|
from django_mailbox.models import Mailbox,MessageAttachment,Message
|
||||||
|
|
||||||
|
def mocked_myqueue(*args, **kwargs):
|
||||||
|
class Job:
|
||||||
|
def __init__(self,*args, **kwargs):
|
||||||
|
self.result = 1
|
||||||
|
self.id = 1
|
||||||
|
|
||||||
|
def revoke(self):
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return Job()
|
||||||
|
|
||||||
def mocked_sqlalchemy(*args, **kwargs):
|
def mocked_sqlalchemy(*args, **kwargs):
|
||||||
# return object with method
|
# return object with method
|
||||||
|
|
||||||
|
|||||||
@@ -193,8 +193,10 @@ class ListWorkoutTest(TestCase):
|
|||||||
|
|
||||||
@patch('rowers.dataprep.create_engine')
|
@patch('rowers.dataprep.create_engine')
|
||||||
@patch('rowers.dataprep.getsmallrowdata_db')
|
@patch('rowers.dataprep.getsmallrowdata_db')
|
||||||
|
@patch('rowers.dataprep.myqueue')
|
||||||
def test_list_workouts(self, mocked_sqlalchemy,
|
def test_list_workouts(self, mocked_sqlalchemy,
|
||||||
mocked_getsmallrowdata_db):
|
mocked_getsmallrowdata_db,
|
||||||
|
mocked_myqueue):
|
||||||
|
|
||||||
login = self.c.login(username=self.u.username, password=self.password)
|
login = self.c.login(username=self.u.username, password=self.password)
|
||||||
self.assertTrue(login)
|
self.assertTrue(login)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from statements import *
|
|||||||
|
|
||||||
nu = datetime.datetime.now()
|
nu = datetime.datetime.now()
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class WorkoutViewTest(TestCase):
|
class WorkoutViewTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.u = UserFactory()
|
self.u = UserFactory()
|
||||||
@@ -68,7 +69,9 @@ class WorkoutViewTest(TestCase):
|
|||||||
|
|
||||||
@patch('rowers.dataprep.create_engine')
|
@patch('rowers.dataprep.create_engine')
|
||||||
@patch('rowers.dataprep.getsmallrowdata_db')
|
@patch('rowers.dataprep.getsmallrowdata_db')
|
||||||
def test_forcecurve(self, mocked_sqlalchemy, mocked_getsmallrowdata_db):
|
@patch('rowers.middleware.myqueue')
|
||||||
|
def test_forcecurve(self, mocked_sqlalchemy, mocked_getsmallrowdata_db,
|
||||||
|
mocked_myqueue):
|
||||||
login = self.c.login(username=self.u.username, password=self.password)
|
login = self.c.login(username=self.u.username, password=self.password)
|
||||||
self.assertTrue(login)
|
self.assertTrue(login)
|
||||||
|
|
||||||
@@ -142,7 +145,9 @@ class WorkoutViewTest(TestCase):
|
|||||||
|
|
||||||
@patch('rowers.dataprep.create_engine')
|
@patch('rowers.dataprep.create_engine')
|
||||||
@patch('rowers.dataprep.getsmallrowdata_db')
|
@patch('rowers.dataprep.getsmallrowdata_db')
|
||||||
def test_compares(self, mocked_sqlalchemy, mocked_getsmallrowdata_db):
|
@patch('rowers.middleware.myqueue')
|
||||||
|
def test_compares(self, mocked_sqlalchemy, mocked_getsmallrowdata_db,
|
||||||
|
mocked_myqueue):
|
||||||
login = self.c.login(username=self.u.username, password=self.password)
|
login = self.c.login(username=self.u.username, password=self.password)
|
||||||
self.assertTrue(login)
|
self.assertTrue(login)
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from rowers.utils import calculate_age
|
|||||||
import rowers.dataprep as dataprep
|
import rowers.dataprep as dataprep
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class OTWCPChartTest(TestCase):
|
class OTWCPChartTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.u = UserFactory()
|
self.u = UserFactory()
|
||||||
@@ -102,6 +102,7 @@ class OTWCPChartTest(TestCase):
|
|||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class CPChartTest(TestCase):
|
class CPChartTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.u = UserFactory()
|
self.u = UserFactory()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#from __future__ import print_function
|
#from __future__ import print_function
|
||||||
from statements import *
|
from statements import *
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class EmailUpload(TestCase):
|
class EmailUpload(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
redis_connection.publish('tasks','KILL')
|
redis_connection.publish('tasks','KILL')
|
||||||
@@ -64,6 +65,7 @@ workout run
|
|||||||
|
|
||||||
|
|
||||||
#@pytest.mark.django_db
|
#@pytest.mark.django_db
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class EmailTests(TestCase):
|
class EmailTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
redis_connection.publish('tasks','KILL')
|
redis_connection.publish('tasks','KILL')
|
||||||
@@ -146,6 +148,7 @@ race 1
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class EmailAdminUpload(TestCase):
|
class EmailAdminUpload(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
redis_connection.publish('tasks','KILL')
|
redis_connection.publish('tasks','KILL')
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ nu = datetime.datetime.now()
|
|||||||
import rowers
|
import rowers
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class C2Objects(DjangoTestCase):
|
class C2Objects(DjangoTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.c = Client()
|
self.c = Client()
|
||||||
@@ -139,6 +140,7 @@ class C2Objects(DjangoTestCase):
|
|||||||
|
|
||||||
res = add_workout_from_strokedata(self.u,1,data,strokedata,source='c2')
|
res = add_workout_from_strokedata(self.u,1,data,strokedata,source='c2')
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class C2ObjectsTokenExpired(DjangoTestCase):
|
class C2ObjectsTokenExpired(DjangoTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.c = Client()
|
self.c = Client()
|
||||||
@@ -217,6 +219,7 @@ class C2ObjectsTokenExpired(DjangoTestCase):
|
|||||||
|
|
||||||
|
|
||||||
#@pytest.mark.django_db
|
#@pytest.mark.django_db
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class StravaObjects(DjangoTestCase):
|
class StravaObjects(DjangoTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.c = Client()
|
self.c = Client()
|
||||||
@@ -322,6 +325,7 @@ class StravaObjects(DjangoTestCase):
|
|||||||
|
|
||||||
|
|
||||||
#@pytest.mark.django_db
|
#@pytest.mark.django_db
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class STObjects(DjangoTestCase):
|
class STObjects(DjangoTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.c = Client()
|
self.c = Client()
|
||||||
@@ -453,6 +457,7 @@ class STObjects(DjangoTestCase):
|
|||||||
res = add_workout_from_data(self.u,1,data,data)
|
res = add_workout_from_data(self.u,1,data,data)
|
||||||
|
|
||||||
#@pytest.mark.django_db
|
#@pytest.mark.django_db
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class RunKeeperObjects(DjangoTestCase):
|
class RunKeeperObjects(DjangoTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.c = Client()
|
self.c = Client()
|
||||||
@@ -545,6 +550,7 @@ class RunKeeperObjects(DjangoTestCase):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class UAObjects(DjangoTestCase):
|
class UAObjects(DjangoTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.c = Client()
|
self.c = Client()
|
||||||
@@ -647,6 +653,7 @@ class UAObjects(DjangoTestCase):
|
|||||||
|
|
||||||
|
|
||||||
#@pytest.mark.django_db
|
#@pytest.mark.django_db
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class TPObjects(DjangoTestCase):
|
class TPObjects(DjangoTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.c = Client()
|
self.c = Client()
|
||||||
@@ -731,6 +738,7 @@ class TPObjects(DjangoTestCase):
|
|||||||
|
|
||||||
|
|
||||||
#@pytest.mark.django_db
|
#@pytest.mark.django_db
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class AutoExportTests(TestCase):
|
class AutoExportTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
redis_connection.publish('tasks','KILL')
|
redis_connection.publish('tasks','KILL')
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from statements import *
|
|||||||
nu = datetime.datetime.now()
|
nu = datetime.datetime.now()
|
||||||
|
|
||||||
#@pytest.mark.django_db
|
#@pytest.mark.django_db
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class NewUserRegistrationTest(TestCase):
|
class NewUserRegistrationTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.c = Client()
|
self.c = Client()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from rowers.utils import allmonths,allsundays
|
|||||||
|
|
||||||
import rowers.plannedsessions as plannedsessions
|
import rowers.plannedsessions as plannedsessions
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class TrainingPlanTest(TestCase):
|
class TrainingPlanTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.u = UserFactory()
|
self.u = UserFactory()
|
||||||
@@ -162,6 +163,7 @@ class TrainingPlanTest(TestCase):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class SessionLinkTest(TestCase):
|
class SessionLinkTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.u = UserFactory()
|
self.u = UserFactory()
|
||||||
@@ -327,6 +329,7 @@ class SessionLinkTest(TestCase):
|
|||||||
|
|
||||||
# 2019-01-12, HM
|
# 2019-01-12, HM
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class SessionCompleteTest(TestCase):
|
class SessionCompleteTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.u = UserFactory()
|
self.u = UserFactory()
|
||||||
@@ -562,6 +565,7 @@ class SessionCompleteTest(TestCase):
|
|||||||
self.assertEqual(response.status_code,200)
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class ChallengeCompleteTest(TestCase):
|
class ChallengeCompleteTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.u = UserFactory()
|
self.u = UserFactory()
|
||||||
@@ -785,6 +789,7 @@ class ChallengeCompleteTest(TestCase):
|
|||||||
response = self.c.get(url)
|
response = self.c.get(url)
|
||||||
self.assertEqual(response.status_code,200)
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class MandatoryTestCompleteTest(TestCase):
|
class MandatoryTestCompleteTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.u = UserFactory()
|
self.u = UserFactory()
|
||||||
@@ -996,6 +1001,7 @@ class MandatoryTestCompleteTest(TestCase):
|
|||||||
response = self.c.get(url,follow=True)
|
response = self.c.get(url,follow=True)
|
||||||
self.assertEqual(response.status_code,200)
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class PlannedSessionsView(TestCase):
|
class PlannedSessionsView(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# user
|
# user
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ class TeamFactory(factory.DjangoModelFactory):
|
|||||||
private = 'open'
|
private = 'open'
|
||||||
viewing = 'allmembers'
|
viewing = 'allmembers'
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class TeamTest(TestCase):
|
class TeamTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
redis_connection.publish('tasks','KILL')
|
redis_connection.publish('tasks','KILL')
|
||||||
@@ -235,7 +237,7 @@ class TeamTest(TestCase):
|
|||||||
response = self.c.post(url, form_data)
|
response = self.c.post(url, form_data)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class TeamTestLowLevel(TestCase):
|
class TeamTestLowLevel(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
redis_connection.publish('tasks','KILL')
|
redis_connection.publish('tasks','KILL')
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ nu = datetime.datetime.now()
|
|||||||
from rowers.views import add_defaultfavorites
|
from rowers.views import add_defaultfavorites
|
||||||
|
|
||||||
#@pytest.mark.django_db
|
#@pytest.mark.django_db
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class ViewTest(TestCase):
|
class ViewTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
redis_connection.publish('tasks','KILL')
|
redis_connection.publish('tasks','KILL')
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ tested = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
#@pytest.mark.django_db
|
#@pytest.mark.django_db
|
||||||
|
@override_settings(TESTING=True)
|
||||||
class URLTests(TestCase):
|
class URLTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
redis_connection.publish('tasks','KILL')
|
redis_connection.publish('tasks','KILL')
|
||||||
@@ -98,8 +99,8 @@ class URLTests(TestCase):
|
|||||||
'/rowers/histo/user/1/',
|
'/rowers/histo/user/1/',
|
||||||
'/rowers/histo/user/1/2016-01-01/2016-12-31/',
|
'/rowers/histo/user/1/2016-01-01/2016-12-31/',
|
||||||
'/rowers/histodata/',
|
'/rowers/histodata/',
|
||||||
'/rowers/job-kill/1/',
|
# '/rowers/job-kill/1/',
|
||||||
'/rowers/jobs-status/',
|
# '/rowers/jobs-status/',
|
||||||
'/rowers/laboratory/',
|
'/rowers/laboratory/',
|
||||||
'/rowers/laboratory/user/1/',
|
'/rowers/laboratory/user/1/',
|
||||||
'/rowers/legal/',
|
'/rowers/legal/',
|
||||||
@@ -167,8 +168,8 @@ class URLTests(TestCase):
|
|||||||
'/rowers/team-compare-select/',
|
'/rowers/team-compare-select/',
|
||||||
'/rowers/team-compare-select/workout/1/',
|
'/rowers/team-compare-select/workout/1/',
|
||||||
'/rowers/team-compare-select/2016-01-01/2016-12-31/',
|
'/rowers/team-compare-select/2016-01-01/2016-12-31/',
|
||||||
'/rowers/test-job/2/',
|
# '/rowers/test-job/2/',
|
||||||
'/rowers/test-job2/2/',
|
# '/rowers/test-job2/2/',
|
||||||
# '/rowers/test_callback/',
|
# '/rowers/test_callback/',
|
||||||
# '/rowers/updatefitness/',
|
# '/rowers/updatefitness/',
|
||||||
# '/rowers/updatefitness/rower/',
|
# '/rowers/updatefitness/rower/',
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
Binary file not shown.
@@ -287,6 +287,17 @@ def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio):
|
|||||||
|
|
||||||
|
|
||||||
def myqueue(queue,function,*args,**kwargs):
|
def myqueue(queue,function,*args,**kwargs):
|
||||||
|
class MockJob:
|
||||||
|
def __init__(self,*args, **kwargs):
|
||||||
|
self.result = 1
|
||||||
|
self.id = 1
|
||||||
|
|
||||||
|
def revoke(self):
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if settings.TESTING:
|
||||||
|
return MockJob()
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
kwargs['debug'] = True
|
kwargs['debug'] = True
|
||||||
|
|
||||||
|
|||||||
@@ -437,7 +437,9 @@ def remove_asynctask(request,id):
|
|||||||
request.session['async_tasks'] = newtasks
|
request.session['async_tasks'] = newtasks
|
||||||
|
|
||||||
def get_job_result(jobid):
|
def get_job_result(jobid):
|
||||||
if settings.DEBUG:
|
if settings.TESTING:
|
||||||
|
return None
|
||||||
|
elif settings.DEBUG:
|
||||||
result = celery_result.AsyncResult(jobid).result
|
result = celery_result.AsyncResult(jobid).result
|
||||||
else:
|
else:
|
||||||
running_job_ids = rq_registry.get_job_ids()
|
running_job_ids = rq_registry.get_job_ids()
|
||||||
@@ -467,7 +469,16 @@ verbose_job_status = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def get_job_status(jobid):
|
def get_job_status(jobid):
|
||||||
if settings.DEBUG:
|
if settings.TESTING:
|
||||||
|
summary = {
|
||||||
|
'status': 'failed',
|
||||||
|
'result': 0,
|
||||||
|
'finished': True,
|
||||||
|
'failed': True,
|
||||||
|
'started_at':None,
|
||||||
|
}
|
||||||
|
return summary
|
||||||
|
elif settings.DEBUG:
|
||||||
job = celery_result.AsyncResult(jobid)
|
job = celery_result.AsyncResult(jobid)
|
||||||
jobresult = job.result
|
jobresult = job.result
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ SECRET_KEY = CFG['secret_key']
|
|||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
TESTING = False
|
||||||
|
|
||||||
ALLOWED_HOSTS = CFG['allowed_hosts']
|
ALLOWED_HOSTS = CFG['allowed_hosts']
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user