Browse Source

fixes tests

Damien ACCORSI 9 years ago
parent
commit
5cf03bec94

+ 7 - 4
tracim/tracim/lib/user.py View File

@@ -68,10 +68,13 @@ class UserStaticApi(object):
68 68
 
69 69
     @classmethod
70 70
     def get_current_user(cls) -> User:
71
-        identity = tg.request.identity
72
-
73
-        if tg.request.identity:
74
-            return cls._get_user(tg.request.identity['repoze.who.userid'])
71
+        # HACK - D.A. - 2015-09-02
72
+        # In tests, the tg.request.identity may not be set
73
+        # (this is a buggy case, but for now this is how the software is;)
74
+        if tg.request != None:
75
+            if hasattr(tg.request, 'identity'):
76
+                if tg.request.identity != None:
77
+                    return cls._get_user(tg.request.identity['repoze.who.userid'])
75 78
 
76 79
         return None
77 80
 

+ 1 - 0
tracim/tracim/model/data.py View File

@@ -494,6 +494,7 @@ class Content(DeclarativeBase):
494 494
     def created_as_delta(self, delta_from_datetime:datetime=None):
495 495
         if not delta_from_datetime:
496 496
             delta_from_datetime = datetime.now()
497
+
497 498
         return format_timedelta(delta_from_datetime - self.created,
498 499
                                 locale=tg.i18n.get_lang()[0])
499 500
 

+ 8 - 1
tracim/tracim/tests/__init__.py View File

@@ -7,6 +7,8 @@ from paste.deploy import loadapp
7 7
 from webtest import TestApp
8 8
 
9 9
 from gearbox.commands.setup_app import SetupAppCommand
10
+
11
+import tg
10 12
 from tg import config
11 13
 from tg.util import Bunch
12 14
 
@@ -128,8 +130,10 @@ def teardown_db():
128 130
 
129 131
 class TestStandard(object):
130 132
 
133
+    application_under_test = application_name
134
+
131 135
     def setUp(self):
132
-        self.app = load_app('main')
136
+        self.app = load_app(self.application_under_test)
133 137
 
134 138
         logger.debug(self, 'Start setUp() by trying to clean database...')
135 139
         try:
@@ -146,6 +150,9 @@ class TestStandard(object):
146 150
         setup_db()
147 151
         logger.debug(self, 'Start Database Setup... -> done')
148 152
 
153
+        self.app.get('/_test_vars')  # Allow to create fake context
154
+        tg.i18n.set_lang('en')  # Set a default lang
155
+
149 156
     def tearDown(self):
150 157
         transaction.commit()
151 158
 

+ 46 - 55
tracim/tracim/tests/library/test_serializers.py View File

@@ -1,5 +1,6 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
+from datetime import datetime
3 4
 from nose.tools import eq_
4 5
 from nose.tools import ok_
5 6
 from nose.tools import raises
@@ -7,6 +8,7 @@ from nose.tools import raises
7 8
 from sqlalchemy.orm.exc import NoResultFound
8 9
 
9 10
 import transaction
11
+import tg
10 12
 
11 13
 from tracim.model import DBSession
12 14
 
@@ -73,6 +75,8 @@ class TestSerializers(TestStandard):
73 75
         eq_(3, len(res.keys()))
74 76
 
75 77
     def test_serialize_Content_DEFAULT(self):
78
+        self.app.get('/_test_vars')  # Allow to create fake context
79
+
76 80
         obj = Content()
77 81
         obj.content_id = 132
78 82
         obj.label = 'Some label'
@@ -92,61 +96,50 @@ class TestSerializers(TestStandard):
92 96
         eq_(None, res.workspace, res)
93 97
         eq_(4, len(res.keys()), res)
94 98
 
99
+    def test_serialize_Content_comment_THREAD(self):
100
+        wor = Workspace()
101
+        wor.workspace_id = 4
95 102
 
103
+        fol = Content()
104
+        fol.type = ContentType.Folder
105
+        fol.content_id = 72
106
+        fol.workspace = wor
96 107
 
97
-    # def test_serialize_Content_comment_THREAD(self):
98
-    #
99
-    #     wor = Workspace()
100
-    #     wor.workspace_id = 4
101
-    #
102
-    #     fol = Content()
103
-    #     fol.type = ContentType.Folder
104
-    #     fol.content_id = 72
105
-    #     fol.workspace = wor
106
-    #
107
-    #     par = Content()
108
-    #     par.type = ContentType.Thread
109
-    #     par.content_id = 37
110
-    #     par.parent = fol
111
-    #     par.workspace = wor
112
-    #
113
-    #     obj = Content()
114
-    #     obj.type = ContentType.Comment
115
-    #     obj.content_id = 132
116
-    #     obj.label = 'some label'
117
-    #     obj.description = 'Some Description'
118
-    #     obj.parent = par
119
-    #
120
-    #     res = Context(CTX.THREAD).toDict(obj)
121
-    #     eq_(res.__class__, DictLikeClass, res)
122
-    #
123
-    #     ok_('label' in res.keys())
124
-    #     eq_(obj.label, res.label, res)
125
-    #
126
-    #     ok_('content' in res.keys())
127
-    #     eq_(obj.description, res.content, res)
128
-    #
129
-    #     ok_('created' in res.keys())
130
-    #
131
-    #     ok_('icon' in res.keys())
132
-    #     eq_(ContentType.icon(obj.type), res.icon, res)
133
-    #
134
-    #     ok_('id' in res.folder.keys())
135
-    #     eq_(obj.content_id, res.id, res)
136
-    #
137
-    #     ok_('owner' in res.folder.keys())
138
-    #     eq_(None, res.owner, res) # TODO - test with a owner value
139
-    #
140
-    #     ok_('type' in res.folder.keys())
141
-    #     eq_(obj.type, res.type, res)
142
-    #
143
-    #     ok_('urls' in res.folder.keys())
144
-    #     ok_('delete' in res.urls.keys())
145
-    #
146
-    #     eq_(8, len(res.keys()), res)
108
+        par = Content()
109
+        par.type = ContentType.Thread
110
+        par.content_id = 37
111
+        par.parent = fol
112
+        par.workspace = wor
113
+        par.created = datetime.now()
147 114
 
148
-    def test_serializer_get_converter_return_CTX_DEFAULT(self):
115
+        obj = Content()
116
+        obj.type = ContentType.Comment
117
+        obj.content_id = 132
118
+        obj.label = 'some label'
119
+        obj.description = 'Some Description'
120
+        obj.parent = par
121
+        obj.created = datetime.now()
122
+
123
+        print('LANGUAGES #2 ARE', tg.i18n.get_lang())
124
+        res = Context(CTX.THREAD).toDict(obj)
125
+        eq_(res.__class__, DictLikeClass, res)
126
+
127
+        ok_('label' in res.keys())
128
+        eq_(obj.label, res.label, res)
129
+
130
+        ok_('content' in res.keys())
131
+        eq_(obj.description, res.content, res)
149 132
 
133
+        ok_('created' in res.keys())
134
+
135
+        ok_('icon' in res.keys())
136
+        eq_(ContentType.get_icon(obj.type), res.icon, res)
137
+
138
+        ok_('delete' in res.urls.keys())
139
+
140
+        eq_(10, len(res.keys()), len(res.keys()))
141
+
142
+    def test_serializer_get_converter_return_CTX_DEFAULT(self):
150 143
         class A(object):
151 144
             pass
152 145
 
@@ -168,8 +161,9 @@ class TestSerializers(TestStandard):
168 161
 
169 162
         converter = Context.get_converter(CTX.FILE, A)
170 163
 
171
-    def test_serializer_toDict_int_str_and_LazyString(self):
172 164
 
165
+
166
+    def test_serializer_toDict_int_str_and_LazyString(self):
173 167
         s = Context(CTX.DEFAULT).toDict(5)
174 168
         ok_(isinstance(s, int))
175 169
         eq_(5, s)
@@ -184,7 +178,6 @@ class TestSerializers(TestStandard):
184 178
         eq_(lazystr, s3)
185 179
 
186 180
     def test_serializer_toDict_for_list_of_objects(self):
187
-
188 181
         class A(object):
189 182
             def __init__(self, name):
190 183
                 self.name = name
@@ -226,8 +219,6 @@ class TestSerializers(TestStandard):
226 219
 
227 220
 
228 221
     def test_serializer_content__menui_api_context__children(self):
229
-        self.app.get('/_test_vars')  # Allow to create fake context
230
-
231 222
         folder_without_child = Content()
232 223
         folder_without_child.type = ContentType.Folder
233 224
         res = Context(CTX.MENU_API).toDict(folder_without_child)