From 37d22efaea1d7669d4df44d86ff7f7bf7c6d31e5 Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Tue, 16 Feb 2016 15:58:53 +0000 Subject: [PATCH] Improve test for Magic Folder statistics and move it from test_system.py to test_magic_folder.py. --- src/allmydata/test/test_magic_folder.py | 29 ++++++++++++++++++++++++- src/allmydata/test/test_system.py | 16 -------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/allmydata/test/test_magic_folder.py b/src/allmydata/test/test_magic_folder.py index 14cd0f94e..8df3ca6a7 100644 --- a/src/allmydata/test/test_magic_folder.py +++ b/src/allmydata/test/test_magic_folder.py @@ -1,6 +1,6 @@ import os, sys -import shutil +import shutil, simplejson from twisted.trial import unittest from twisted.internet import defer, task @@ -1340,6 +1340,33 @@ class MockTest(MagicFolderTestMixin, unittest.TestCase): d.addCallback(cleanup) return d + def test_statistics(self): + self.set_up_grid() + self.local_dir = abspath_expanduser_unicode(u"test_statistics", base=self.basedir) + self.mkdir_nonascii(self.local_dir) + + d = self.create_invite_join_magic_folder(u"Alice\u0101", self.local_dir) + d.addCallback(self._restart_client) + + # Write something short enough for a LIT file. + d.addCallback(lambda ign: self._check_file(u"short", "test")) + + # test magic-folder statistics + d.addCallback(lambda res: self.GET("statistics")) + def _got_stats(res): + self.failUnlessIn("Operational Statistics", res) + self.failUnlessIn("Magic Folder", res) + d.addCallback(_got_stats) + d.addCallback(lambda res: self.GET("statistics?t=json")) + def _got_stats_json(res): + data = simplejson.loads(res) + print data["counters"] + self.failUnlessEqual(data["counters"]["magic_folder.uploader.files_uploaded"], 1) + d.addCallback(_got_stats_json) + d.addBoth(self.cleanup) + return d + + class RealTest(MagicFolderTestMixin, unittest.TestCase): """This is skipped unless both Twisted and the platform support inotify.""" diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index cf992e313..e039b4aac 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -697,22 +697,6 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase): # the key, which should cause the download to fail the post-download # plaintext_hash check. - def test_statistics_for_magic_folder(self): - self.basedir = "system/SystemTest/test_statistics_for_magic_folder" - d = self.set_up_nodes() - # see if the statistics page exists - d.addCallback(lambda res: self.GET("statistics")) - def _got_stats(res): - self.failUnlessIn("Operational Statistics", res) - self.failUnlessIn("Magic Folder", res) - d.addCallback(_got_stats) - d.addCallback(lambda res: self.GET("statistics?t=json")) - def _got_stats_json(res): - data = simplejson.loads(res) - #self.failUnlessEqual(data["counters"]["uploader.files_uploaded"], 0) - d.addCallback(_got_stats_json) - return d - def test_filesystem(self): self.basedir = "system/SystemTest/test_filesystem" self.data = LARGE_DATA