3 initial tests, more to come
This commit is contained in:
parent
6be7324d4b
commit
a28ee20828
@ -1,26 +1,93 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from genericpath import exists
|
||||
import imp
|
||||
import os
|
||||
from tempfile import TemporaryDirectory
|
||||
from unittest import TestCase
|
||||
from os.path import join, expanduser
|
||||
import sqlite3
|
||||
|
||||
foobar = imp.load_source('buku', '../buku')
|
||||
buku = imp.load_source('buku', '../buku')
|
||||
|
||||
TEST_TEMP_DIR_OBJ = TemporaryDirectory(prefix='bukutest_')
|
||||
TEST_TEMP_DIR_PATH = TEST_TEMP_DIR_OBJ.name
|
||||
TEST_TEMP_DBDIR_PATH = join(TEST_TEMP_DIR_PATH, 'buku')
|
||||
TEST_TEMP_DBFILE_PATH = join(TEST_TEMP_DBDIR_PATH, 'bookmarks.db')
|
||||
|
||||
from buku import BukuDb, parse_tags
|
||||
|
||||
from buku import BukuDb
|
||||
|
||||
class TestBukuDb(TestCase):
|
||||
def test_get_dbfile_path(self):
|
||||
self.fail()
|
||||
|
||||
def test_move_legacy_dbfile(self):
|
||||
self.fail()
|
||||
def setUp(self):
|
||||
os.environ['XDG_DATA_HOME'] = TEST_TEMP_DIR_PATH
|
||||
|
||||
def tearDown(self):
|
||||
os.environ['XDG_DATA_HOME'] = TEST_TEMP_DIR_PATH
|
||||
|
||||
def test_get_dbdir_path(self):
|
||||
dbdir_expected = TEST_TEMP_DBDIR_PATH
|
||||
dbdir_local_expected = join(expanduser('~'), '.local', 'share', 'buku')
|
||||
dbdir_relative_expected = join('.', 'buku')
|
||||
|
||||
# desktop linux
|
||||
self.assertEqual(dbdir_expected, BukuDb.get_dbdir_path())
|
||||
|
||||
# desktop generic
|
||||
os.environ.pop('XDG_DATA_HOME')
|
||||
self.assertEqual(dbdir_local_expected, BukuDb.get_dbdir_path())
|
||||
|
||||
# no desktop
|
||||
|
||||
# -- home is defined differently on various platforms.
|
||||
# -- keep a copy and set it back once done
|
||||
originals = {}
|
||||
for env_var in ['HOME', 'HOMEPATH', 'HOMEDIR']:
|
||||
try:
|
||||
originals[env_var] = os.environ.pop(env_var)
|
||||
except KeyError:
|
||||
pass
|
||||
self.assertEqual(dbdir_relative_expected, BukuDb.get_dbdir_path())
|
||||
for key, value in originals.items():
|
||||
os.environ[key] = value
|
||||
|
||||
# # not sure how to test this in nondestructive manner
|
||||
# def test_move_legacy_dbfile(self):
|
||||
# self.fail()
|
||||
|
||||
def test_initdb(self):
|
||||
self.fail()
|
||||
if exists(TEST_TEMP_DBFILE_PATH):
|
||||
os.remove(TEST_TEMP_DBFILE_PATH)
|
||||
self.assertIs(False, exists(TEST_TEMP_DBFILE_PATH))
|
||||
conn, curr = BukuDb.initdb()
|
||||
self.assertIsInstance(conn, sqlite3.Connection)
|
||||
self.assertIsInstance(curr, sqlite3.Cursor)
|
||||
self.assertIs(True, exists(TEST_TEMP_DBFILE_PATH))
|
||||
curr.close()
|
||||
conn.close()
|
||||
|
||||
def test_get_bookmark_index(self):
|
||||
self.fail()
|
||||
|
||||
def test_add_bookmark(self):
|
||||
self.fail()
|
||||
def test_add_and_retrieve_bookmark(self):
|
||||
URL = 'http://slashdot.org'
|
||||
TITLE = 'SLASHDOT'
|
||||
TAGS = ['old', 'news']
|
||||
DESC = "News for old nerds, stuff that doesn't matter"
|
||||
|
||||
# start from clean slate
|
||||
if exists(TEST_TEMP_DBFILE_PATH):
|
||||
os.remove(TEST_TEMP_DBFILE_PATH)
|
||||
|
||||
bdb = BukuDb()
|
||||
bdb.add_bookmark(URL,
|
||||
tag_manual=parse_tags(TAGS),
|
||||
title_manual=TITLE,
|
||||
desc=DESC)
|
||||
|
||||
index = bdb.get_bookmark_index(URL)
|
||||
|
||||
self.assertEqual(1, index)
|
||||
# TODO: retrieve and compare
|
||||
# TODO: tags should be passed to the api as a sequence...
|
||||
|
||||
def test_update_bookmark(self):
|
||||
self.fail()
|
||||
|
Loading…
Reference in New Issue
Block a user