测试views.py中的save语句

时间:2016-01-07 14:58:32

标签: python django

我最初设计了一个测试,因为想法是应用TDD,测试应该测试一个寄存器被保存并且这可以正确执行(save()),但测试应该失败,因为很明显,代码在视图模块中不存在保存,有人帮我完成测试以充分测试保存。

这是测试文件:

from django.test import TestCase
from django.http import HttpRequest
from django.conf import settings##
from django.utils.importlib import import_module##
from django.core.urlresolvers import reverse
from key_process_indicator_bsc.views.views_process_indicator import *
from key_process_indicator_bsc.models import *


class ProcessIndicatorTestCase(TestCase):
    fixtures = ['test_data_key_process_indicator_bsc.json']

    def setUp(self):
        pass

    def test_pi_insert_basic(self):
        #user = auth_user.objects.get(username="lruedc")
        indicator_type = IndicatorType.objects.get(name="eficacia")
        unite_measure = UniteMeasure.objects.get(name="horas")
        periodicity_indicator = PeriodicityIndicator.objects.get(pk = 1)
        indicator_process = IndicatorProcess.objects.get(pk = 1)
        frecuency = Frecuency.objects.get(detail="semanal")
        formula = Formula.objects.get(detail = "2ab") 

        request = HttpRequest()
        request.method = 'POST'
        request.POST['name'] = "Cumplimiento del margen EBITDA"
        request.POST['goal'] = "100"
        request.POST['weight'] = "50"
        request.POST['minimum_range'] = 20
        request.POST['hight_range'] = 40
        request.POST['acountable'] = 1
        request.POST['responsible'] = 1
        request.POST['indicator_type'] = indicator_type.id
        request.POST['unite_measure'] = unite_measure.id
        request.POST['formula'] = formula.id
        request.POST['process'] = indicator_process.process
        request.POST['indicator_process_type'] = indicator_process.indicator_process_type
        request.POST['indicator_process'] = indicator_process.id
        request.POST['frecuency'] = frecuency.id
        engine = import_module(settings.SESSION_ENGINE)
        ProcessIndicatorInsert.as_view()(request)

这是视图文件:

from django.shortcuts import render
from django.views.generic import View
from django.http import HttpResponse, HttpResponseRedirect
#from ..forms import LoginForm
from django.core.urlresolvers import reverse


class ProcessIndicatorInsert(View):

    template_name = 'key_process_indicator_bsc/index.html'
    def post(self, request):
        return render(request, self.template_name, {
        })

并且运行测试,我可以看到下一个:

.....................
----------------------------------------------------------------------
Ran 21 tests in 0.694s

OK
Destroying test database for alias 'default'...
(key_process_indicator_bsc_local) root@leidyj-VirtualBox:/home/leidyj/key_process_indicator_bsc_repository/key_process_indicator_bsc# 

你怎么看,测试没有失败,这应该,我如何完成测试?。

感谢。

0 个答案:

没有答案