Exemple #1
0
    def testTitleFormater(self):
        dbutils.getOrCreateProject("x", interactive=False)
        dbutils.getOrCreateKeyword("k1", interactive=False)
        dbutils.getOrCreateKeyword("k2", interactive=False)
        t1 = dbutils.addTask("x", "t1", {})
        t2 = dbutils.addTask("x", "t2", {"k1": None, "k2": 12})
        longerTask = dbutils.addTask("x", "A longer task name", {})
        longerTask.description = "And it has a description"

        out = StringIO()
        renderer = TextListRenderer(out,
                                    termWidth=80,
                                    cryptoMgr=YokadiCryptoManager())
        renderer.addTaskList("Foo", [t1])
        self.assertEquals(renderer.maxTitleWidth, 5)
        renderer.end()
        expected = unicode(\
              "%(CYAN)s              Foo               %(RESET)s\n" \
            + "%(BOLD)sID|Title|U  |S|Age     |Due date%(RESET)s\n" \
            + "--------------------------------\n" \
            + "1 |t1   %(RESET)s|0  |N|0m      |        \n" \
            ) % dict(CYAN=C.CYAN, RESET=C.RESET, BOLD=C.BOLD)
        testutils.multiLinesAssertEqual(self, out.getvalue(), expected)

        out = StringIO()
        renderer = TextListRenderer(out,
                                    termWidth=80,
                                    cryptoMgr=YokadiCryptoManager())
        renderer.addTaskList("Foo", [t1, t2])
        self.assertEquals(renderer.maxTitleWidth, 11)
        renderer.end()
        expected = unicode(\
              "%(CYAN)s                 Foo                  %(RESET)s\n" \
            + "%(BOLD)sID|Title      |U  |S|Age     |Due date%(RESET)s\n" \
            + "--------------------------------------\n" \
            + "1 |t1         %(RESET)s|0  |N|0m      |        \n" \
            + "2 |t2 (%(BOLD)sk1, k2)%(RESET)s|0  |N|0m      |        \n" \
            ) % dict(CYAN=C.CYAN, RESET=C.RESET, BOLD=C.BOLD)
        testutils.multiLinesAssertEqual(self, out.getvalue(), expected)

        out = StringIO()
        renderer = TextListRenderer(out,
                                    termWidth=80,
                                    cryptoMgr=YokadiCryptoManager())
        renderer.addTaskList("Foo", [t2, longerTask])
        self.assertEquals(renderer.maxTitleWidth, len(longerTask.title) + 1)
        renderer.end()
        expected = unicode(\
              "%(CYAN)s                     Foo                      %(RESET)s\n" \
            + "%(BOLD)sID|Title              |U  |S|Age     |Due date%(RESET)s\n" \
            + "----------------------------------------------\n" \
            + "2 |t2 (%(BOLD)sk1, k2)        %(RESET)s|0  |N|0m      |        \n" \
            + "3 |A longer task name%(RESET)s*|0  |N|0m      |        \n" \
            ) % dict(CYAN=C.CYAN, RESET=C.RESET, BOLD=C.BOLD)
        testutils.multiLinesAssertEqual(self, out.getvalue(), expected)
Exemple #2
0
 def testEncryptLongSentence(self):
     mgr = YokadiCryptoManager()
     mgr.force_decrypt = True  # Simulate user ask for decryption
     tui.addInputAnswers("mySecretPassphrase")
     important_sentence = '''This sentence is long long long long
                             This sentence is long
                             This sentence is long
                             This sentence is long
                             This sentence is long long long'''
     encrypted_sentence = mgr.encrypt(important_sentence)
     decrypted_sentence = mgr.decrypt(encrypted_sentence)
     self.assertEqual(important_sentence, decrypted_sentence)
    def testFullRendering(self):
        dbutils.getOrCreateProject("x", interactive=False)
        dbutils.getOrCreateKeyword("k1", interactive=False)
        dbutils.getOrCreateKeyword("k2", interactive=False)
        t1 = dbutils.addTask("x", "t1", {})
        t2 = dbutils.addTask("x", "t2", {"k1": None, "k2": 12})
        longTask = dbutils.addTask("x", "A longer task name", {})
        longTask.description = "And it has a description"

        out = StringIO()
        renderer = TextListRenderer(out,
                                    termWidth=80,
                                    cryptoMgr=YokadiCryptoManager())
        renderer.addTaskList("Foo", [t2, longTask])
        self.assertEqual(renderer.maxTitleWidth, len(longTask.title) + 1)
        renderer.end()
        out = stripColor(out.getvalue())

        expected = \
              "                     Foo                      \n" \
            + "ID│Title              │U  │S│Age     │Due date\n" \
            + "──┼───────────────────┼───┼─┼────────┼────────\n" \
            + "2 │t2 (k1, k2)        │0  │N│0m      │        \n" \
            + "3 │A longer task name*│0  │N│0m      │        \n"
        self.assertMultiLineEqual(out, expected)
Exemple #4
0
    def testIfEncrypted(self):
        mgr = YokadiCryptoManager()
        mgr.force_decrypt = True  # Simulate user ask for decryption
        tui.addInputAnswers("mySecretPassphrase")
        important_sentence = "Don't tell anyone"
        encrypted_sentence = mgr.encrypt(important_sentence)
        self.assertTrue(mgr.isEncrypted(encrypted_sentence))
        self.assertFalse(mgr.isEncrypted(important_sentence))

        # Should not fail with empty data
        self.assertFalse(mgr.isEncrypted(None))
Exemple #5
0
    def testBadPassphrase(self):
        mgr = YokadiCryptoManager()
        mgr.force_decrypt = True  # Simulate user ask for decryption
        tui.addInputAnswers("mySecretPassphrase")
        important_sentence = "Don't tell anyone"
        encrypted_sentence = mgr.encrypt(important_sentence)

        mgr = YokadiCryptoManager()  # Define new manager with other passphrase
        mgr.force_decrypt = True  # Simulate user ask for decryption
        tui.addInputAnswers("theWrongSecretPassphrase")
        self.assertRaises(YokadiException, mgr.decrypt, encrypted_sentence)
Exemple #6
0
 def testEncrypt(self):
     mgr = YokadiCryptoManager()
     mgr.force_decrypt = True  # Simulate user ask for decryption
     tui.addInputAnswers("mySecretPassphrase")
     important_sentence = "Don't tell anyone"
     encrypted_sentence = mgr.encrypt(important_sentence)
     decrypted_sentence = mgr.decrypt(encrypted_sentence)
     self.assertEqual(important_sentence, decrypted_sentence)
     # Enter again same passphrase and check it is ok
     mgr = YokadiCryptoManager()
     tui.addInputAnswers("mySecretPassphrase")