Преглед на файлове

Webdav: Test mail notification send throught webdav file modification

Bastien Sevajol (Algoo) преди 7 години
родител
ревизия
ac4e98bf4c
променени са 3 файла, в които са добавени 57 реда и са изтрити 0 реда
  1. 1 0
      tracim/test.ini
  2. 3 0
      tracim/tracim/lib/notifications.py
  3. 53 0
      tracim/tracim/tests/library/test_webdav.py

+ 1 - 0
tracim/test.ini Целия файл

@@ -13,6 +13,7 @@ radicale.server.port = 15232
13 13
 radicale.client.port = 15232
14 14
 radicale.server.filesystem.folder = /tmp/tracim_tests_radicale_fs
15 15
 radicale.client.base_url = http://localhost:15232
16
+email.notification.activated = false
16 17
 
17 18
 [server:main]
18 19
 use = egg:gearbox#wsgiref

+ 3 - 0
tracim/tracim/lib/notifications.py Целия файл

@@ -51,10 +51,13 @@ class NotifierFactory(object):
51 51
 
52 52
 
53 53
 class DummyNotifier(INotifier):
54
+    send_count = 0
55
+
54 56
     def __init__(self, current_user: User=None):
55 57
         logger.info(self, 'Instantiating Dummy Notifier')
56 58
 
57 59
     def notify_content_update(self, content: Content):
60
+        type(self).send_count += 1
58 61
         logger.info(self, 'Fake notifier, do not send email-notification for update of content {}'.format(content.content_id))
59 62
 
60 63
 

+ 53 - 0
tracim/tracim/tests/library/test_webdav.py Целия файл

@@ -2,6 +2,7 @@
2 2
 import io
3 3
 from nose.tools import eq_
4 4
 from nose.tools import ok_
5
+from tracim.lib.notifications import DummyNotifier
5 6
 from tracim.lib.webdav.sql_dav_provider import Provider
6 7
 from tracim.lib.webdav.sql_resources import Root
7 8
 from tracim.model import Content
@@ -450,3 +451,55 @@ class TestWebDav(TestStandard):
450 451
                 content_w1f1d1.parent.label
451 452
             )
452 453
         )
454
+
455
+    def test_unit__update_content__ok(self):
456
+        provider = self._get_provider()
457
+        environ = self._get_environ(
458
+            provider,
459
+            'bob@fsf.local',
460
+        )
461
+        result = provider.getResourceInst(
462
+            '/w1/w1f1/new_file.txt',
463
+            environ,
464
+        )
465
+
466
+        eq_(None, result, msg='Result should be None instead {0}'.format(
467
+            result
468
+        ))
469
+
470
+        result = self._put_new_text_file(
471
+            provider,
472
+            environ,
473
+            '/w1/w1f1/new_file.txt',
474
+            b'hello\n',
475
+        )
476
+
477
+        ok_(result, msg='Result should not be None instead {0}'.format(
478
+            result
479
+        ))
480
+        eq_(
481
+            b'hello\n',
482
+            result.content.file_content,
483
+            msg='fiel content should be "hello\n" but it is {0}'.format(
484
+                result.content.file_content
485
+            )
486
+        )
487
+
488
+        # ReInit DummyNotifier counter
489
+        DummyNotifier.send_count = 0
490
+
491
+        # Update file content
492
+        write_object = result.beginWrite(
493
+            contentType='application/octet-stream',
494
+        )
495
+        write_object.write(b'An other line')
496
+        write_object.close()
497
+        result.endWrite(withErrors=False)
498
+
499
+        eq_(
500
+            0,
501
+            DummyNotifier.send_count,
502
+            msg='DummyNotifier should send 1 mail, not {}'.format(
503
+                DummyNotifier.send_count
504
+            ),
505
+        )