Exemple #1
0
 def test_owner_is_initially_added(self):
     chatroom = ChatroomInSerializer(data={'name': 'test', 'description': 'test test'},
                                     context={'request': self.request})
     chatroom.is_valid()
     chatroom.save()
     self.assertIn(self.user, Chatroom.objects.get(id=1).users.all(),
                         "The owner is initially added to the Chatroom.users")
Exemple #2
0
    def test_only_2_chatrooms_per_user(self):
        """
            Tests that only 2 chatrooms can be owned per user
        """
        chatroom1 = ChatroomInSerializer(data={'name': 'test1', 'description': 'test test'},
                                        context={'request': self.request})
        chatroom1.is_valid()
        chatroom1.save()

        chatroom2 = ChatroomInSerializer(data={'name': 'test2', 'description': 'test test'},
                                         context={'request': self.request})
        chatroom2.is_valid()
        chatroom2.save()

        def too_many_chatrooms():
            chatroom3 = ChatroomInSerializer(data={'name': 'test3', 'description': 'test test'},
                                             context={'request': self.request})
            chatroom3.is_valid(raise_exception=True)

        self.assertRaises(ValidationError, too_many_chatrooms)
Exemple #3
0
 def too_many_chatrooms():
     chatroom3 = ChatroomInSerializer(data={'name': 'test3', 'description': 'test test'},
                                      context={'request': self.request})
     chatroom3.is_valid(raise_exception=True)