from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

#from __future__ import print_function
from .statements import *

nu = datetime.datetime.now()

from rowers.rower_rules import is_workout_user

#@pytest.mark.django_db
class WorkoutTests(TestCase):
    def setUp(self):
        redis_connection.publish('tasks','KILL')
        self.u = User.objects.create_user('john',
                                     'sander@ds.ds',
                                     'koeinsloot')
        self.r = Rower.objects.create(user=self.u,gdproptin=True,surveydone=True,
                                 gdproptindate=timezone.now()
        )
        nu = datetime.datetime.now()
        self.w = Workout.objects.create(name='testworkout',
                                        workouttype='water',
                                   user=self.r,date=nu.strftime('%Y-%m-%d'),
                                   starttime=nu.strftime('%H:%M:%S'),
                                   duration="0:55:00",distance=8000)

    def test_checkworkoutuser(self):
        self.assertEqual(is_workout_user(self.u,self.w),True)

#@pytest.mark.django_db
class C2Tests(TestCase):
    def setUp(self):
        redis_connection.publish('tasks','KILL')
        self.u = User.objects.create_user('john',
                                     'sander@ds.ds',
                                     'koeinsloot')
        self.r = Rower.objects.create(user=self.u,gdproptin=True,surveydone=True,
                                 gdproptindate=timezone.now()
        )
        self.nu = datetime.datetime.now()
        self.w = Workout.objects.create(name='testworkout',workouttype='water',
                                   user=r,date=nu.strftime('%Y-%m-%d'),
                                   starttime=nu.strftime('%H:%M:%S'),
                                   duration="0:55:00",distance=8000)

    def c2_notokentest(self):
        thetoken = c2_open(self.u)
        # should raise NoTokenError
        self.assertRaises(NoTokenError)




#@pytest.mark.django_db
class subroutinetests(TestCase):
    def setUp(self):
        redis_connection.publish('tasks','KILL')
        u = User.objects.create_user('john',
                                     'sander@ds.ds',
                                     'koeinsloot')
        r = Rower.objects.create(user=u)
        nu = datetime.datetime.now()
        filename = 'rowers/tests/testdata/testdata.csv'
        self.w = Workout.objects.create(name='testworkout',
                                        workouttype='water',
                                        user=r,date=nu.strftime('%Y-%m-%d'),
                                        starttime=nu.strftime('%H:%M:%S'),
                                        duration="0:55:00",distance=8000,
                                        csvfilename=filename)


    def c2stuff(self):
        data = c2stuff.createc2workoutdata(self.w)
        jsond = json.dumps(data)
        data = c2stuff.createc2workoutdata_as_splits(w)
        jsond = json.dumps(data)
