[#2020] working on getting environment more sane

Signed-off-by: Rick Copeland <rcopeland@geek.net>
diff --git a/Allura/allura/config/environment.py b/Allura/allura/config/environment.py
index 24f01b3..30971ec 100644
--- a/Allura/allura/config/environment.py
+++ b/Allura/allura/config/environment.py
@@ -1,6 +1,13 @@
 # -*- coding: utf-8 -*-
 """WSGI environment setup for allura."""
 
+import pylons
+import pylons.middleware
+import tg
+import tg.error
+pylons.c = pylons.tmpl_context
+pylons.g = pylons.app_globals
+
 from allura.config.app_cfg import base_config
 
 __all__ = ['load_environment']
diff --git a/Allura/allura/config/middleware.py b/Allura/allura/config/middleware.py
index 434a9dc..7f4a9c1 100644
--- a/Allura/allura/config/middleware.py
+++ b/Allura/allura/config/middleware.py
@@ -2,7 +2,12 @@
 """WSGI middleware initialization for the allura application."""
 import mimetypes
 
+import pylons
+import pylons.middleware
 import tg
+import tg.error
+pylons.c = pylons.tmpl_context
+pylons.g = pylons.app_globals
 import pkg_resources
 from tg import config
 from paste.deploy.converters import asbool
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 3831fb8..b1823f4 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -13,7 +13,8 @@
 import webob.multidict
 from formencode import Invalid
 from tg.decorators import before_validate
-from pylons import response, c
+from pylons import response
+from pylons import tmpl_context as c
 from paste.httpheaders import CACHE_CONTROL, EXPIRES
 from webhelpers.html import literal
 from webob import exc
diff --git a/Allura/allura/templates/widgets/neighborhood_add_project.html b/Allura/allura/templates/widgets/neighborhood_add_project.html
index 3223ad3..7987ee5 100644
--- a/Allura/allura/templates/widgets/neighborhood_add_project.html
+++ b/Allura/allura/templates/widgets/neighborhood_add_project.html
@@ -15,7 +15,7 @@
             </label>
         </div>
         <div class="grid-10">{{widget.display_field(widget.fields.project_unixname)}}
-            <br/><div id="project_url">http://{{c.environ['HTTP_HOST']}}{{neighborhood.url()}}<span id="url_fragment"></span></div>
+            <br/><div id="project_url">http://{{request.environ['HTTP_HOST']}}{{neighborhood.url()}}<span id="url_fragment"></span></div>
         </div>
         <div class="grid-9" style="position:relative; overflow:visible">
             <b id="error_icon" data-icon="!" class="allura" title="Caution">!</b>
diff --git a/Allura/allura/tests/functional/test_root.py b/Allura/allura/tests/functional/test_root.py
index de3f85c..fc7f36f 100644
--- a/Allura/allura/tests/functional/test_root.py
+++ b/Allura/allura/tests/functional/test_root.py
@@ -47,7 +47,7 @@
             'text/html,application/xhtml+xml,application/xml;q=0.9;text/plain;q=0.8,image/png,*/*;q=0.5' ]
         for hdr in hdrs:
             # malformed headers used to return 500, just make sure they don't now
-            self.app.get('/', headers=dict(Accept=hdr))
+            self.app.get('/', headers=dict(Accept=hdr), validate_skip=True)
 
     def test_project_browse(self):
         com_cat = M.ProjectCategory.query.find(dict(label='Communications')).first()
diff --git a/Allura/allura/tests/model/test_discussion.py b/Allura/allura/tests/model/test_discussion.py
index f18850b..2388ce6 100644
--- a/Allura/allura/tests/model/test_discussion.py
+++ b/Allura/allura/tests/model/test_discussion.py
@@ -62,7 +62,7 @@
     assert t.attachment_class() == M.DiscussionAttachment
     p0 = t.post('This is a post')
     p1 = t.post('This is another post')
-    time.sleep(1)
+    time.sleep(0.25)
     p2 = t.post('This is a reply', parent_id=p0._id)
     ThreadLocalORMSession.flush_all()
     ThreadLocalORMSession.close_all()
@@ -74,7 +74,9 @@
     posts0 = t.find_posts(page=0, limit=10, style='threaded')
     posts1 = t.find_posts(page=0, limit=10, style='timestamp')
     assert posts0 != posts1
-    posts2 = t.find_posts(page=0, limit=10, style='threaded', timestamp=p0.timestamp)
+    ts = p0.timestamp.replace(
+        microsecond=int(p0.timestamp.microsecond // 1000) * 1000)
+    posts2 = t.find_posts(page=0, limit=10, style='threaded', timestamp=ts)
     assert len(posts2) > 0
 
     assert 'wiki/_discuss/' in t.url()
diff --git a/Allura/setup.py b/Allura/setup.py
index ec9d4f2..0fbc030 100644
--- a/Allura/setup.py
+++ b/Allura/setup.py
@@ -6,7 +6,7 @@
     use_setuptools()
     from setuptools import setup, find_packages
 
-from allura.version import __version__
+exec open('allura/version.py').read()
 
 PROJECT_DESCRIPTION='''
 Allura is an open source implementation of a software "forge", a web site
@@ -38,10 +38,15 @@
         'License :: OSI Approved :: Apache Software License',
         ],
     install_requires=[
-        "TurboGears2 >= 2.1a1",
+        "TurboGears2",
+        "tg.devtools",
+        "pypeline",
+        "datadiff",
+        "BeautifulSoup",
         "PasteScript",
         "Babel >= 0.9.4",
-        "pymongo >= 1.7",
+        "pymongo >= 1.9,<2.0",
+        "jinja2",
         "pysolr",
         "repoze.what-quickstart",
         "sqlalchemy-migrate",
@@ -51,20 +56,21 @@
         "python-openid >= 2.2.4",
         "python-dateutil >= 1.4.1",
         "WebOb >= 0.9.8",
-        "WebTest == 1.2",
+        "WebTest >= 1.2",
         "EasyWidgets >= 0.1.1",
         "PIL >= 1.1.7",
         "iso8601",
-        "chardet == 1.0.1",
+        "chardet >= 1.0.1",
         "feedparser >= 5.0.1",
-        "oauth2 == 1.2.0",
+        "oauth2 >= 1.2.0",
+        "Ming >= 0.2.2dev-20110930",
         ],
     setup_requires=["PasteScript >= 1.7"],
     paster_plugins=['PasteScript', 'Pylons', 'TurboGears2', 'tg.devtools', 'Ming'],
     packages=find_packages(exclude=['ez_setup']),
     include_package_data=True,
     test_suite='nose.collector',
-    tests_require=['WebTest >= 1.2', 'BeautifulSoup', 'pytidylib', 'poster'],
+    tests_require=['WebTest >= 1.2', 'BeautifulSoup', 'pytidylib', 'poster', 'nose'],
     package_data={'allura': ['i18n/*/LC_MESSAGES/*.mo',
                                  'templates/*/*',
                                  'public/*/*']},
diff --git a/AlluraTesting/alluratest/validation.py b/AlluraTesting/alluratest/validation.py
index f6b27b9..bfa6aff 100644
--- a/AlluraTesting/alluratest/validation.py
+++ b/AlluraTesting/alluratest/validation.py
@@ -17,7 +17,7 @@
 import beaker.session
 from paste.deploy import loadapp
 from paste.script.appinstall import SetupCommand
-from pylons import c, g, h, url, request, response, session
+from pylons import c, g, url, request, response, session
 from webtest import TestApp
 from webob import Request, Response
 from tidylib import tidy_document
diff --git a/AlluraTesting/setup.py b/AlluraTesting/setup.py
index 4a5155c..73a8ec3 100644
--- a/AlluraTesting/setup.py
+++ b/AlluraTesting/setup.py
@@ -16,6 +16,8 @@
       include_package_data=True,
       zip_safe=False,
       install_requires=[
+        'pytidylib',
+        "poster",
           # -*- Extra requirements: -*-
       ]
       )