test_views.py :  » Content-Management-Systems » PyLucid » PyLucid_standalone » dbpreferences » tests » 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 » Content Management Systems » PyLucid 
PyLucid » PyLucid_standalone » dbpreferences » tests » test_views.py

from django.db.models import signals
from django.http import HttpResponse
from dbpreferences.models import UserSettings

save_count = 0
def post_save_handler(sender, **kwargs):
    global save_count
    save_count += 1

init_count = 0
def pre_init_handler(*args, **kwargs):
    global init_count
    init_count += 1

def test_user_settings(request, test_name, key, value):
    if test_name == "base_test":
        output = key + value
    elif test_name == "get":
        output = request.user_settings.get(key, value)
    elif test_name == "setitem":
        output = request.user_settings[key] = value
    else:
        raise

    return HttpResponse(output, mimetype="text/plain")



def test_user_settings_cache(request, no):
    signals.post_save.connect(post_save_handler, sender=UserSettings)
    signals.pre_init.connect(pre_init_handler, sender=UserSettings)

    should_value = "initial value"
    value = request.user_settings.get("test", "initial value")

    if no == "0":
        # First call
        should_save_count = 0
        should_init_count = 0
    elif no == "1":
        # second call
        should_save_count = 1
        should_init_count = 1
    elif no in ("2", "3", "4"):
        # Use cached Version
        should_save_count = 1
        should_init_count = 1
    elif no == "5":
        # Change the value
        request.user_settings["test"] = "new value"
        should_value = "new value"
        should_save_count = 1
        should_init_count = 1
    else:
        # After 5
        should_value = "new value"
        should_save_count = 2
        should_init_count = 1

    global save_count
    assert save_count == should_save_count, "Wrong save count %r (should %r) in no %r" % (
        save_count, should_save_count, no
    )

    global init_count
    assert init_count == should_init_count, "Wrong init count %r (should %r) in no %r" % (
        init_count, should_init_count, no
    )

    return HttpResponse(no, mimetype="text/plain")
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.