~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/tests/test_chat.py

  • Committer: mattgiuca
  • Date: 2008-01-30 05:09:03 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:331
Console: Configured console to display properly as a "floating" window in the
tutorial page.
The console now has two "modes" (normal mode and "windowpane" mode). This is
switched by the JavaScript, and enables different CSS styling (and will
further enable different behaviour).

Styled the console (black). In windowpane mode, there is an additional div at
the bottom which fills up the space, and the console is floated on top of it.
(With position:fixed). This lets it appear at the bottom of the screen no
matter where the user scrolls.

Added console_app.css and console_app.js, which are necessary for things
specific to the "Console" application but not all instances of the console.

Changed the styling and layout of tutorial HTML/CSS to accomodate the console
(it needed to go outside the padded box).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# IVLE - Informatics Virtual Learning Environment
2
 
# Copyright (C) 2007-2010 The University of Melbourne
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
 
 
18
 
import socket
19
 
 
20
 
from nose import with_setup
21
 
from nose.tools import assert_equal, raises
22
 
 
23
 
import ivle.chat
24
 
 
25
 
 
26
 
TIMEOUT = 0.1
27
 
NULLNETSTRING = "0:,"
28
 
SIMPLESTRING = "Hello world!"
29
 
SIMPLENETSTRING = "12:Hello world!,"
30
 
 
31
 
 
32
 
class TestChat(object):
33
 
    def setUp(self):
34
 
        """Creates a socket pair for testing"""
35
 
        self.s1, self.s2 = socket.socketpair()
36
 
        self.s1.settimeout(TIMEOUT)
37
 
        self.s2.settimeout(TIMEOUT)
38
 
 
39
 
    def tearDown(self):
40
 
        """Closes the socket pair"""
41
 
        self.s1.close()
42
 
        self.s2.close()
43
 
 
44
 
    def test_send_null_netstring(self):
45
 
        """Check that we construct a empty Netstring correctly"""
46
 
        ivle.chat.send_netstring(self.s1, "")
47
 
        assert_equal(self.s2.recv(1024), NULLNETSTRING)
48
 
 
49
 
    def test_send_simple_netstring(self):
50
 
        """Check that we construct a simple Netstring correctly"""
51
 
        ivle.chat.send_netstring(self.s1, SIMPLESTRING)
52
 
        assert_equal(self.s2.recv(1024), SIMPLENETSTRING)
53
 
 
54
 
    def test_recv_null_netstring(self):
55
 
        """Check that we can decode a null Netstring"""
56
 
        self.s1.sendall(NULLNETSTRING)
57
 
        assert_equal(ivle.chat.recv_netstring(self.s2), "")
58
 
 
59
 
    def test_recv_null_netstring(self):
60
 
        """Check that we can decode a simple Netstring"""
61
 
        self.s1.sendall(SIMPLENETSTRING)
62
 
        assert_equal(ivle.chat.recv_netstring(self.s2), SIMPLESTRING)
63
 
 
64
 
    @raises(socket.timeout)
65
 
    def test_short_netstring(self):
66
 
        self.s1.sendall("1234:not that long!,")
67
 
        assert ivle.chat.recv_netstring(self.s2) is None
68
 
 
69
 
    @raises(ivle.chat.ProtocolError)
70
 
    def test_long_netstring(self):
71
 
        self.s1.sendall("5:not that short!,")
72
 
        assert ivle.chat.recv_netstring(self.s2) is None
73