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

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

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

from nose.tools import eq_ 

from pyramid import testing 

 

from bookie.models import DBSession 

from bookie.models import Bmark 

from bookie.models import BmarkMgr 

from bookie.models.auth import User 

 

from bookie.tests import empty_db 

from bookie.tests import gen_random_word 

from bookie.tests import TestDBBase 

 

 

class TestBmarkMgrStats(TestDBBase): 

    """Handle some bmarkmgr 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 

        user = User() 

        user.username = gen_random_word(10) 

        DBSession.add(user) 

        for i in range(ct): 

            b = Bmark( 

                url=gen_random_word(12), 

                username=user.username 

            ) 

            b.hash_id = gen_random_word(3) 

            DBSession.add(b) 

 

        ct = BmarkMgr.count() 

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

 

    def test_unique_ct(self): 

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

        ct = 5 

        common = 'testing.com' 

        users = [] 

        for i in range(ct): 

            user = User() 

            user.username = gen_random_word(10) 

            DBSession.add(user) 

            users.append(user) 

 

        for i in range(ct - 2): 

            b = Bmark( 

                url=gen_random_word(12), 

                username=users[i].username 

            ) 

            DBSession.add(b) 

 

        # Add in our dupes 

        c = Bmark( 

            url=common, 

            username=users[3].username 

        ) 

        DBSession.add(c) 

        DBSession.flush() 

 

        d = Bmark( 

            url=common, 

            username=users[4].username 

        ) 

        DBSession.add(d) 

        DBSession.flush() 

 

        ct = BmarkMgr.count(distinct=True) 

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

 

    def test_per_user(self): 

        """We should only get a pair of results for this single user""" 

        ct = 5 

        common = 'testing.com' 

        user = User() 

        user.username = gen_random_word(10) 

        DBSession.add(user) 

 

        usercommon = User() 

        usercommon.username = common 

        DBSession.add(usercommon) 

 

        for i in range(ct - 2): 

            b = Bmark( 

                url=gen_random_word(12), 

                username=user.username 

            ) 

            DBSession.add(b) 

 

        # add in our dupes 

        c = Bmark( 

            url=gen_random_word(10), 

            username=usercommon.username, 

        ) 

        DBSession.add(c) 

        DBSession.flush() 

 

        d = Bmark( 

            url=gen_random_word(10), 

            username=usercommon.username, 

        ) 

        DBSession.add(d) 

        DBSession.flush() 

 

        ct = BmarkMgr.count(username=usercommon.username) 

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