File: test_collection.py

package info (click to toggle)
calypso 2.1-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 276 kB
  • sloc: python: 1,675; sh: 119; makefile: 4
file content (48 lines) | stat: -rw-r--r-- 1,697 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# vim: set fileencoding=utf-8 :

import subprocess
import tempfile
import shutil
import unittest

from calypso.webdav import Collection
from calypso import paths

from .testutils import CalypsoTestCase


class TestCollection(CalypsoTestCase):
    test_vcard = "tests/data/import.vcard"
    test_resource_with_slash = "tests/data/from-tripsync.ics"

    def test_import_file(self):
        collection = Collection("")
        self.assertTrue(collection.import_file(self.test_vcard))
        self.assertEqual(len(collection.items), 2)
        org = u'Universitetet i Tromsø'
        self.assertEqual(org, collection.items[0].object.org.value[0])

    def test_remove_existent_item(self):
        collection = Collection("")
        self.assertTrue(collection.import_file(self.test_vcard))
        self.assertEqual(len(collection.items), 2)
        name = collection.items[0].name
        collection.remove(name, {})
        self.assertEqual(len(collection.items), 1)

    def test_remove_nonexistent_item(self):
        collection = Collection("")
        self.assertTrue(collection.import_file(self.test_vcard))
        self.assertEqual(len(collection.items), 2)
        collection.remove("doesnotexist", {})
        self.assertEqual(len(collection.items), 2)

    def test_uid_with_slash(self):
        collection = Collection("/")
        self.assertTrue(collection.import_file(self.test_resource_with_slash))
        self.assertEqual(len(collection.items), 1)
        veventuid = collection.items[0].object.vevent.uid.value
        r = paths.resource_from_path(veventuid)
        c = paths.collection_from_path(veventuid)
        self.assertEqual(r, veventuid)
        self.assertEqual("/", c)