1
# Twisted, the Framework of Your Internet
2
# Copyright (C) 2001 Matthew W. Lefkowitz
4
# This library is free software; you can redistribute it and/or
5
# modify it under the terms of version 2.1 of the GNU Lesser General Public
6
# License as published by the Free Software Foundation.
8
# This library is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# Lesser General Public License for more details.
13
# You should have received a copy of the GNU Lesser General Public
14
# License along with this library; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from pyunit import unittest
19
from twisted.news import news, database
20
from twisted.protocols import nntp, loopback
21
from twisted.protocols import protocol
23
ALL_GROUPS = ('alt.test.nntp', 0, 0, 'y')
24
GROUP = ('0', '0', '0', 'alt.test.nntp', 'group', 'selected')
26
POST_STRING = """Path: not-for-mail
27
From: <exarkun@somehost.domain.com>
29
Newsgroups: alt.test.nntp
33
User-Agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.4.17 (i686))
38
"One World, one Web, one Program." - Microsoft(R) promotional ad
39
"Ein Volk, ein Reich, ein Fuhrer." - Adolf Hitler
41
10:56pm up 4 days, 4:42, 1 user, load average: 0.08, 0.08, 0.12
44
class TestNNTPClient(nntp.NNTPClient):
46
nntp.NNTPClient.__init__(self)
48
def assertEquals(self, foo, bar):
49
if foo != bar: raise AssertionError("%s != %s!" % (foo, bar))
51
def connectionMade(self):
52
nntp.NNTPClient.connectionMade(self)
55
def gotAllGroups(self, info):
56
self.assertEquals(len(info), 1)
57
self.assertEquals(info[0], ALL_GROUPS)
59
self.fetchGroup('alt.test.nntp')
61
def gotGroup(self, info):
62
self.assertEquals(len(info), 6)
63
self.assertEquals(info, GROUP)
65
self.postArticle(string.replace(POST_STRING, '\n', '\r\n'))
67
def postFailed(self, err):
73
def gotArticle(self, info):
74
self.transport.loseConnection()
77
class NNTPTestCase(unittest.TestCase):
79
# Re-init pickle db, we depend on no articles
80
database.PickleStorage.sharedDB = {'alt.test.nntp': {}, 'groups': ['alt.test.nntp']}
82
def testLoopback(self):
83
server = nntp.NNTPServer(database.PickleStorage)
84
client = TestNNTPClient()
85
loopback.loopback(server, client)
88
# Clean up the pickle file
89
os.remove('news.pickle')