tests.py :  » ERP » frePPLe » frepple-0.8.0 » contrib » django » freppledb » execute » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » ERP » frePPLe 
frePPLe » frepple 0.8.0 » contrib » django » freppledb » execute » tests.py
#
# Copyright (C) 2007 by Johan De Taeye
#
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#

# file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/tags/0.8.0/contrib/django/freppledb/execute/tests.py $
# revision : $LastChangedRevision: 1198 $  $LastChangedBy: jdetaeye $
# date : $LastChangedDate: 2010-03-07 10:52:39 +0100 (Sun, 07 Mar 2010) $

import os

from django.core import management
from django.test import TransactionTestCase
from django.test.testcases import restore_transaction_methods,disable_transaction_methods
from django.conf import settings

import output.models
import input.models

class execute_from_user_interface(TransactionTestCase):

  def setUp(self):
    # Login
    self.client.login(username='frepple', password='frepple')

  def test_execute_page(self):
    response = self.client.get('/execute/')
    self.failUnlessEqual(response.status_code, 200)

  def test_run_ui(self):
    # Empty the database tables
    response = self.client.post('/execute/erase/', {'action':'erase'})
    # The answer is a redirect to a new page, which also contains the success message
    self.assertRedirects(response, '/execute/execute.html')
    self.failUnlessEqual(input.models.Calendar.objects.count(),0)
    self.failUnlessEqual(input.models.Demand.objects.count(),0)
    self.failUnlessEqual(output.models.Problem.objects.count(),0)
    self.failUnlessEqual(output.models.FlowPlan.objects.count(),0)
    self.failUnlessEqual(output.models.LoadPlan.objects.count(),0)
    self.failUnlessEqual(output.models.OperationPlan.objects.count(),0)

    # Load a dataset
    response = self.client.post('/execute/fixture/', {'action':'load', 'datafile':'small_demo'})
    self.assertRedirects(response, '/execute/execute.html')
    self.failIfEqual(input.models.Calendar.objects.count(),0)
    self.failIfEqual(input.models.Demand.objects.count(),0)

    # Run frePPLe,  and make sure the test database is used
    try: os.environ['FREPPLE_DATABASE_NAME'] = settings.TEST_DATABASE_NAME
    except: pass
    try: os.environ['FREPPLE_DATABASE_USER'] = settings.TEST_DATABASE_USER
    except: pass
    response = self.client.post('/execute/runfrepple/', {'action':'run', 'constraint':'15', 'plantype':'1'})
    self.assertRedirects(response, '/execute/execute.html')

    # Count the output records
    self.failUnlessEqual(output.models.Problem.objects.count(),26)
    self.failUnlessEqual(output.models.FlowPlan.objects.count(),234)
    self.failUnlessEqual(output.models.LoadPlan.objects.count(),58)
    self.failUnlessEqual(output.models.OperationPlan.objects.count(),138)


class execute_with_commands(TransactionTestCase):

  def test_run_cmd(self):
    # Empty the database tables
    self.failIfEqual(input.models.Calendar.objects.count(),0)
    management.call_command('frepple_flush')
    self.failUnlessEqual(input.models.Calendar.objects.count(),0)
    self.failUnlessEqual(input.models.Demand.objects.count(),0)
    self.failUnlessEqual(output.models.Problem.objects.count(),0)
    self.failUnlessEqual(output.models.FlowPlan.objects.count(),0)
    self.failUnlessEqual(output.models.LoadPlan.objects.count(),0)
    self.failUnlessEqual(output.models.OperationPlan.objects.count(),0)

    # Create a new model
    management.call_command('frepple_createmodel', cluster='1', verbosity='0')
    self.failIfEqual(input.models.Calendar.objects.count(),0)
    self.failIfEqual(input.models.Demand.objects.count(),0)

    # Run frePPLe, and make sure the test database is used
    try: os.environ['FREPPLE_DATABASE_NAME'] = settings.TEST_DATABASE_NAME
    except: pass
    try: os.environ['FREPPLE_DATABASE_USER'] = settings.TEST_DATABASE_USER
    except: pass
    management.call_command('frepple_run', plantype='1', nonfatal=True)
    self.failUnlessEqual(output.models.Problem.objects.count(),26)
    self.failUnlessEqual(output.models.FlowPlan.objects.count(),234)
    self.failUnlessEqual(output.models.LoadPlan.objects.count(),58)
    self.failUnlessEqual(output.models.OperationPlan.objects.count(),138)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.