Statistics
| Branch: | Tag: | Revision:

root / invitations / tests.py @ 848e6d10

History | View | Annotate | Download (3.3 kB)

1 48130e66 Georgios Gousios
# Copyright 2011 GRNET S.A. All rights reserved.
2 48130e66 Georgios Gousios
#
3 48130e66 Georgios Gousios
# Redistribution and use in source and binary forms, with or without
4 48130e66 Georgios Gousios
# modification, are permitted provided that the following conditions
5 48130e66 Georgios Gousios
# are met:
6 48130e66 Georgios Gousios
#
7 48130e66 Georgios Gousios
#   1. Redistributions of source code must retain the above copyright
8 48130e66 Georgios Gousios
#      notice, this list of conditions and the following disclaimer.
9 48130e66 Georgios Gousios
#
10 48130e66 Georgios Gousios
#  2. Redistributions in binary form must reproduce the above copyright
11 48130e66 Georgios Gousios
#     notice, this list of conditions and the following disclaimer in the
12 48130e66 Georgios Gousios
#     documentation and/or other materials provided with the distribution.
13 48130e66 Georgios Gousios
#
14 48130e66 Georgios Gousios
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15 48130e66 Georgios Gousios
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 48130e66 Georgios Gousios
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 48130e66 Georgios Gousios
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18 48130e66 Georgios Gousios
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 48130e66 Georgios Gousios
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 48130e66 Georgios Gousios
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 48130e66 Georgios Gousios
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 48130e66 Georgios Gousios
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 48130e66 Georgios Gousios
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 48130e66 Georgios Gousios
# SUCH DAMAGE.
25 48130e66 Georgios Gousios
#
26 48130e66 Georgios Gousios
# The views and conclusions contained in the software and documentation are
27 48130e66 Georgios Gousios
# those of the authors and should not be interpreted as representing official
28 48130e66 Georgios Gousios
# policies, either expressed or implied, of GRNET S.A.
29 48130e66 Georgios Gousios
30 48130e66 Georgios Gousios
31 9a5e8ebe Georgios Gousios
from django.test import TestCase
32 9a5e8ebe Georgios Gousios
from django.test.client import Client
33 9a5e8ebe Georgios Gousios
34 9a5e8ebe Georgios Gousios
import invitations
35 9a5e8ebe Georgios Gousios
from synnefo.db.models import SynnefoUser
36 9f8ad4c5 Georgios Gousios
from django.conf import settings
37 9a5e8ebe Georgios Gousios
38 9a5e8ebe Georgios Gousios
39 9a5e8ebe Georgios Gousios
class InvitationsTestCase(TestCase):
40 9a5e8ebe Georgios Gousios
41 9a5e8ebe Georgios Gousios
    token = '46e427d657b20defe352804f0eb6f8a2'
42 9a5e8ebe Georgios Gousios
43 9a5e8ebe Georgios Gousios
    def setUp(self):
44 9a5e8ebe Georgios Gousios
        self.client = Client()
45 9a5e8ebe Georgios Gousios
46 9a5e8ebe Georgios Gousios
    def test_add_invitation(self):
47 9f8ad4c5 Georgios Gousios
        """
48 9f8ad4c5 Georgios Gousios
            Tests whether invitations can be added
49 9f8ad4c5 Georgios Gousios
        """
50 53e6717b Georgios Gousios
        source = SynnefoUser.objects.filter(auth_token = self.token)[0]
51 9a5e8ebe Georgios Gousios
        invitations.add_invitation(source, "Test", "test@gmail.com")
52 9a5e8ebe Georgios Gousios
53 bd1548a7 Georgios Gousios
        # Check whether the invited user has been added to the database
54 9a5e8ebe Georgios Gousios
        added_user = SynnefoUser.objects.filter(name = "Test",
55 9a5e8ebe Georgios Gousios
                                                uniq = "test@gmail.com")
56 9a5e8ebe Georgios Gousios
        self.assertNotEquals(added_user, None)
57 566cd8b2 Georgios Gousios
58 bd1548a7 Georgios Gousios
        # Re-adding an existing invitation
59 bd1548a7 Georgios Gousios
        try:
60 bd1548a7 Georgios Gousios
            invitations.add_invitation(source, u'', "test@gmail.com")
61 bd1548a7 Georgios Gousios
            self.assertTrue(False)
62 bd1548a7 Georgios Gousios
        except invitations.AlreadyInvited:
63 bd1548a7 Georgios Gousios
            self.assertTrue(True)
64 bd1548a7 Georgios Gousios
65 9f8ad4c5 Georgios Gousios
    def test_get_invitee_level(self):
66 9f8ad4c5 Georgios Gousios
        """
67 9f8ad4c5 Georgios Gousios
            Checks whether invitation levels and their limits are being respected
68 9f8ad4c5 Georgios Gousios
        """
69 9f8ad4c5 Georgios Gousios
        source = SynnefoUser.objects.filter(auth_token = self.token)[0]
70 9f8ad4c5 Georgios Gousios
71 9f8ad4c5 Georgios Gousios
        self.assertEqual(invitations.get_user_inv_level(source), -1)
72 9f8ad4c5 Georgios Gousios
73 9f8ad4c5 Georgios Gousios
        inv = invitations.add_invitation(source, "Test", "test@gmail.com")
74 9f8ad4c5 Georgios Gousios
        self.assertEqual(inv.target.max_invitations, settings.INVITATIONS_PER_LEVEL[0])
75 9f8ad4c5 Georgios Gousios
        self.assertEqual(invitations.get_user_inv_level(inv.target), 0)
76 9f8ad4c5 Georgios Gousios
77 9f8ad4c5 Georgios Gousios
        inv = invitations.add_invitation(inv.target, "Test2", "test2@gmail.com")
78 9f8ad4c5 Georgios Gousios
        self.assertEqual(invitations.get_user_inv_level(inv.target), 1)
79 9f8ad4c5 Georgios Gousios
        self.assertEqual(inv.target.max_invitations, settings.INVITATIONS_PER_LEVEL[1])