Пример #1
0
    def test_path(self):
        k1 = caps115.Key("algo", "node")
        k2 = caps115.Key("somealgo", "somenode")

        self.assertEqual(
            k1.path,
            pathlib.Path("hashes") / "{}_{}.xml".format("algo", "node"),
        )

        self.assertEqual(
            k2.path,
            pathlib.Path("hashes") /
            "{}_{}.xml".format("somealgo", "somenode"),
        )
Пример #2
0
 def test_calculate_keys_on_real_data(self):
     key, = self.i.calculate_keys(TEST_DB_ENTRY)
     self.assertEqual(
         key,
         caps115.Key(
             TEST_DB_ENTRY_HASH,
             "{}#{}".format(self.node, TEST_DB_ENTRY_VER),
         ))
Пример #3
0
    def test_equality(self):
        k1 = caps115.Key("algo", "node")
        k2 = caps115.Key("algo", "node")
        k3 = caps115.Key("somealgo", "somenode")

        self.assertTrue(k1 == k2)
        self.assertFalse(k1 != k2)
        self.assertFalse(k1 == k3)
        self.assertTrue(k1 != k3)

        self.assertTrue(k2 == k1)
        self.assertFalse(k2 != k1)
        self.assertFalse(k2 == k3)
        self.assertTrue(k2 != k3)

        self.assertFalse(k3 == k1)
        self.assertTrue(k3 != k1)
        self.assertFalse(k3 == k2)
        self.assertTrue(k3 != k2)
Пример #4
0
    def test_extract_keys_obtains_Key_from_Caps115_info(self):
        p = unittest.mock.Mock(spec=aioxmpp.Presence)
        p.xep0115_caps.ver = "ver"
        p.xep0115_caps.node = "node"
        p.xep0115_caps.hash_ = "hashfun"
        p.xep0115_caps.ext = None

        self.assertSequenceEqual(
            [caps115.Key("hashfun", "node#ver")],
            list(self.i.extract_keys(p)),
        )
Пример #5
0
    def test_init_via_kwargs(self):
        k = caps115.Key(algo="somealgo", node="somenode")

        self.assertEqual(
            k.algo,
            "somealgo",
        )
        self.assertEqual(
            k.node,
            "somenode",
        )
Пример #6
0
    def test_init_via_args(self):
        k = caps115.Key("algo", "node")

        self.assertEqual(
            k.algo,
            "algo",
        )
        self.assertEqual(
            k.node,
            "node",
        )
Пример #7
0
    def test_ver(self):
        pieces = unittest.mock.Mock()
        node = unittest.mock.Mock()
        node.rsplit.return_value = [
            pieces.wrong,
            pieces.ver,
        ]
        k = caps115.Key("algo", node)

        ver = k.ver

        node.rsplit.assert_called_once_with("#", 1)

        self.assertEqual(ver, pieces.ver)
Пример #8
0
    def test_path_uses_urlescape(self):
        k = caps115.Key("algo", unittest.mock.sentinel.node)

        with contextlib.ExitStack() as stack:
            urlescape = stack.enter_context(
                unittest.mock.patch("urllib.parse.quote"), )
            urlescape.return_value = "urlescape_result"

            path = k.path

            urlescape.assert_called_once_with(unittest.mock.sentinel.node,
                                              safe="")

            self.assertEqual(
                path,
                pathlib.Path("hashes") / "algo_urlescape_result.xml")
Пример #9
0
    def test_put_keys_generates_Caps115_object(self):
        key = caps115.Key("algo", "node#ver_from_key")

        p = unittest.mock.Mock(["xep0115_caps"])
        p.xep0115_caps = None

        self.i.put_keys(iter([key]), p)

        self.assertIsInstance(
            p.xep0115_caps,
            caps_xso.Caps115,
        )

        self.assertEqual(
            p.xep0115_caps.node,
            self.node,
        )

        self.assertEqual(p.xep0115_caps.ver, key.ver)

        self.assertEqual(
            p.xep0115_caps.hash_,
            key.algo,
        )
Пример #10
0
    def test_hashable(self):
        k1 = caps115.Key("algo", "node")
        k2 = caps115.Key("algo", "node")

        self.assertEqual(hash(k1), hash(k2))
Пример #11
0
 def test_init_default(self):
     with self.assertRaises(TypeError):
         caps115.Key()