#coding=utf-8

import json

from django.test import TestCase
from django.core.urlresolvers import reverse
from django.conf import settings

from models import User

class AccountTests(TestCase):
    username = 'firefish'
    password = '1111'

    def setUp(self):
        User.objects.create_user(self.username, self.password, gender=settings.MALE)

    def test_login(self):
        url = reverse('account_login')
        # 正确密码
        resp = self.client.post(url, {'username':self.username, 'password':self.password})
        self.assertEquals(resp.status_code, 200)
        data = json.loads(resp.content)
        self.assertEquals(data['code'], 0)

        # 错误密码
        resp = self.client.post(url, {'username': self.username, 'password': 'err'})
        self.assertEquals(resp.status_code, 200)
        #print unicode(resp.content)
        data = json.loads(resp.content)
        self.assertEquals(data['code'], 1)

        # 无效数据
        resp = self.client.post(url, {'-': self.username})
        #print unicode(resp.content)
        data = json.loads(resp.content)
        self.assertEquals(data['code'], 1)


