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

"""Test the limited signup process 

 

""" 

import logging 

 

from nose.tools import eq_ 

from nose.tools import ok_ 

 

from bookie.models import DBSession 

from bookie.models.auth import Activation 

from bookie.models.auth import User 

from bookie.models.auth import UserMgr 

 

from bookie.tests import gen_random_word 

from bookie.tests import TestDBBase 

from bookie.tests import TestViewBase 

 

LOG = logging.getLogger(__name__) 

 

 

class TestInviteSetup(TestDBBase): 

    """Verify we have/can work with the invite numbers""" 

 

    def testHasNoInvites(self): 

        """Verify that if the user has no invites, they can't invite""" 

        u = User() 

        u.invite_ct = 0 

        ok_(not u.has_invites(), 'User should have no invites') 

        ok_(not u.invite('me@you.com'), 'Should not be able to invite a user') 

 

    def testInviteCreatesUser(self): 

        """We should get a new user when inviting something""" 

        me = User() 

        me.username = 'me' 

        me.email = 'me.com' 

        me.invite_ct = 2 

        you = me.invite('you.com') 

 

        eq_('you.com', you.username, 

            'The email should be the username') 

        eq_('you.com', you.email, 

            'The email should be the email') 

        ok_(len(you.api_key), 

            'The api key should be generated for the user') 

        ok_(not you.activated, 

            'The new user should not be activated') 

        eq_(1, me.invite_ct, 

            'My invite count should be deprecated') 

 

 

class TestSigningUpUser(TestDBBase): 

    """Start out by verifying a user starts out in the right state""" 

 

    def testInitialUserInactivated(self): 

        """A new user signup should be a deactivated user""" 

        u = User() 

        u.email = gen_random_word(10) 

        DBSession.add(u) 

 

        eq_(False, u.activated, 

            'A new signup should start out deactivated by default') 

        ok_(u.activation.code is not None, 

            'A new signup should start out as deactivated') 

        eq_('signup', u.activation.created_by, 

            'This is a new signup, so mark is as thus') 

 

 

class TestOpenSignup(TestViewBase): 

    """New users can request a signup for an account.""" 

 

    def tearDown(self): 

        super(TestOpenSignup, self).tearDown() 

        User.query.filter(User.email == 'testing@newuser.com').delete() 

 

    def testSignupRenders(self): 

        """A signup form is kind of required.""" 

        res = self.app.get('/signup') 

 

        self.assertIn('Sign up for Bookie', res.body) 

        self.assertNotIn('class="error"', res.body) 

 

    def testEmailRequired(self): 

        """Signup requires an email entry.""" 

        res = self.app.post('/signup_process') 

        self.assertIn('Please supply', res.body) 

 

    def testEmailNotAlreadyThere(self): 

        """Signup requires an email entry.""" 

        res = self.app.post( 

            '/signup_process', 

            params={ 

                'email': 'testing@dummy.com' 

            } 

        ) 

        self.assertIn('already signed up', res.body) 

 

    def testSignupWorks(self): 

        """Signing up stores an activation.""" 

        email = 'testing@newuser.com' 

        UserMgr.signup_user(email, 'testcase') 

 

        activations = Activation.query.all() 

 

        self.assertTrue(len(activations) == 1) 

        act = activations[0] 

 

        self.assertEqual( 

            email, 

            act.user.email, 

            "The activation email is the correct one.")