Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

"""Test the basics including the bmark and tags""" 

from nose.tools import eq_ 

from nose.tools import ok_ 

from pyramid import testing 

 

from bookie.models import DBSession 

from bookie.models import Tag 

from bookie.models import TagMgr 

 

from bookie.tests import empty_db 

from bookie.tests import gen_random_word 

from bookie.tests import TestDBBase 

from bookie.tests.factory import make_tag 

 

 

class TestTagMgrStats(TestDBBase): 

    """Handle some TagMgr stats checks""" 

 

    def setUp(self): 

        """Setup Tests""" 

        from pyramid.paster import get_app 

        from bookie.tests import BOOKIE_TEST_INI 

        app = get_app(BOOKIE_TEST_INI, 'bookie') 

        from webtest import TestApp 

        self.testapp = TestApp(app) 

        testing.setUp() 

 

    def tearDown(self): 

        """Tear down each test""" 

        testing.tearDown() 

        empty_db() 

 

    def test_total_ct(self): 

        """Verify that our total count method is working""" 

        ct = 5 

        for i in range(ct): 

            t = Tag(gen_random_word(10)) 

            DBSession.add(t) 

 

        ct = TagMgr.count() 

        eq_(5, ct, 'We should have a total of 5: ' + str(ct)) 

 

    def test_basic_complete(self): 

        """Tags should provide completion options.""" 

        # Generate demo tag into the system 

        tags = [make_tag() for i in range(5)] 

        [DBSession.add(t) for t in tags] 

 

        test_str = tags[0].name[0:2] 

        suggestions = TagMgr.complete(test_str) 

 

        ok_(tags[0] in suggestions, 

            "The sample tag was found in the completion set") 

 

    def test_case_insensitive(self): 

        """Suggestion does not care about case of the prefix.""" 

        # Generate demo tag into the system 

        tags = [make_tag() for i in range(5)] 

        [DBSession.add(t) for t in tags] 

 

        test_str = tags[0].name[0:4].upper() 

        suggestions = TagMgr.complete(test_str) 

        ok_(tags[0] in suggestions, 

            "The sample tag was found in the completion set")