#from __future__ import print_function
import pytest

pytestmark = pytest.mark.django_db

from bs4 import BeautifulSoup
import re
from nose_parameterized import parameterized
from django.test import TestCase, Client,override_settings
from django.core.management import call_command
from django.utils.six import StringIO
from django.test.client import RequestFactory
from rowers.views import checkworkoutuser,c2_open
from rowers.models import Workout, User, Rower, WorkoutForm,RowerForm,GraphImage
from rowers.forms import DocumentsForm,CNsummaryForm,RegistrationFormUniqueEmail
import rowers.plots as plots
import rowers.interactiveplots as iplots
import datetime
from rowingdata import rowingdata as rdata
from rowingdata import rower as rrower
from django.utils import timezone
from rowers.rows import handle_uploaded_file
from django.core.files.uploadedfile import SimpleUploadedFile
from time import strftime,strptime,mktime,time,daylight
import os
from rowers.tasks import handle_makeplot
from rowers.utils import serialize_list,deserialize_list
from rowers.utils import NoTokenError
from shutil import copyfile
from nose.tools import assert_true
from mock import Mock, patch
from minimocktest import MockTestCase
import pandas as pd
import rowers.c2stuff as c2stuff

import json
import numpy as np

from rowers import urls
from rowers.views import error500_view,error404_view,error400_view,error403_view

from rowers.dataprep import delete_strokedata

from redis import StrictRedis
redis_connection = StrictRedis()

class AjaxTests(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,gdproptin=True,
                                 gdproptindate=timezone.now()
        )
	self.nu = datetime.datetime.now()

	self.filename = 'rowers/tests/testdata/testdata.csv'
	self.wotw = Workout.objects.create(name='testworkout',
					workouttype='water',
					user=r,date=self.nu.strftime('%Y-%m-%d'),
					starttime=self.nu.strftime('%H:%M:%S'),
					duration="0:55:00",distance=8000,
					csvfilename=self.filename)
	
	self.wote = Workout.objects.create(name='testworkout',
					workouttype='Indoor Rower',
					user=r,date=self.nu.strftime('%Y-%m-%d'),
					starttime=self.nu.strftime('%H:%M:%S'),
					duration="0:55:00",distance=8000,
					csvfilename=self.filename)


        self.c = Client()
        
    def test_toggle_ranking(self):
        response = self.c.get(
            '/rowers/workout/1/toggle-ranking/',
            **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'})

        jsondata = json.loads(response.json())
        self.assertIn('result',jsondata)
