Statistics
| Branch: | Tag: | Revision:

root / invitations / tests.py @ c0f6fb49

History | View | Annotate | Download (3.3 kB)

1
# Copyright 2011 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or without
4
# modification, are permitted provided that the following conditions
5
# are met:
6
#
7
#   1. Redistributions of source code must retain the above copyright
8
#      notice, this list of conditions and the following disclaimer.
9
#
10
#  2. Redistributions in binary form must reproduce the above copyright
11
#     notice, this list of conditions and the following disclaimer in the
12
#     documentation and/or other materials provided with the distribution.
13
#
14
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
# SUCH DAMAGE.
25
#
26
# The views and conclusions contained in the software and documentation are
27
# those of the authors and should not be interpreted as representing official
28
# policies, either expressed or implied, of GRNET S.A.
29

    
30

    
31
from django.test import TestCase
32
from django.test.client import Client
33

    
34
import invitations
35
from synnefo.db.models import SynnefoUser
36
from django.conf import settings
37

    
38

    
39
class InvitationsTestCase(TestCase):
40

    
41
    token = '46e427d657b20defe352804f0eb6f8a2'
42

    
43
    def setUp(self):
44
        self.client = Client()
45

    
46
    def test_add_invitation(self):
47
        """
48
            Tests whether invitations can be added
49
        """
50
        source = SynnefoUser.objects.filter(auth_token = self.token)[0]
51
        invitations.add_invitation(source, "Test", "test@gmail.com")
52

    
53
        # Check whether the invited user has been added to the database
54
        added_user = SynnefoUser.objects.filter(name = "Test",
55
                                                uniq = "test@gmail.com")
56
        self.assertNotEquals(added_user, None)
57

    
58
        # Re-adding an existing invitation
59
        try:
60
            invitations.add_invitation(source, u'', "test@gmail.com")
61
            self.assertTrue(False)
62
        except invitations.AlreadyInvited:
63
            self.assertTrue(True)
64

    
65
    def test_get_invitee_level(self):
66
        """
67
            Checks whether invitation levels and their limits are being respected
68
        """
69
        source = SynnefoUser.objects.filter(auth_token = self.token)[0]
70

    
71
        self.assertEqual(invitations.get_user_inv_level(source), -1)
72

    
73
        inv = invitations.add_invitation(source, "Test", "test@gmail.com")
74
        self.assertEqual(inv.target.max_invitations, settings.INVITATIONS_PER_LEVEL[0])
75
        self.assertEqual(invitations.get_user_inv_level(inv.target), 0)
76

    
77
        inv = invitations.add_invitation(inv.target, "Test2", "test2@gmail.com")
78
        self.assertEqual(invitations.get_user_inv_level(inv.target), 1)
79
        self.assertEqual(inv.target.max_invitations, settings.INVITATIONS_PER_LEVEL[1])