~didrocks/unity/altf10

« back to all changes in this revision

Viewing changes to grackle/tests/test_client.py

  • Committer: Curtis Hovey
  • Date: 2012-02-29 22:29:35 UTC
  • Revision ID: curtis.hovey@canonical.com-20120229222935-txjobf042vsykgnr
Rename variable for clarity.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
class ForkedFakeService:
64
64
    """A Grackle service fake, as a ContextManager."""
65
65
 
66
 
    def __init__(self, port, messages=None, write_logs=False):
 
66
    def __init__(self, port, message_archives=None, write_logs=False):
67
67
        """Constructor.
68
68
 
69
69
        :param port: The tcp port to use.
70
 
        :param messages: A dict of lists of dicts representing messages.  The
71
 
            outer dict represents the archive, the list represents the list of
72
 
            messages for that archive.
 
70
        :param message_archives: A dict of lists of dicts representing
 
71
            archives of messages. The outer dict represents the archive,
 
72
            the list represents the list of messages for that archive.
73
73
        :param write_logs: If true, log messages will be written to stdout.
74
74
        """
75
75
        self.pid = None
76
76
        self.port = port
77
 
        if messages is None:
78
 
            self.messages = {}
 
77
        if message_archives is None:
 
78
            self.message_archives = {}
79
79
        else:
80
 
            self.messages = messages
 
80
            self.message_archives = message_archives
81
81
        self.read_end, self.write_end = os.pipe()
82
82
        self.write_logs = write_logs
83
83
 
84
84
    @staticmethod
85
 
    def from_client(client, messages=None):
 
85
    def from_client(client, message_archives=None):
86
86
        """Instantiate a ForkedFakeService from the client.
87
87
 
88
88
        :param port: The client to provide service for.
89
 
        :param messages: A dict of lists of dicts representing messages.  The
90
 
            outer dict represents the archive, the list represents the list of
91
 
            messages for that archive.
 
89
        :param message_archives: A dict of lists of dicts representing
 
90
            archives of messages. The outer dict represents the archive,
 
91
            the list represents the list of messages for that archive.
92
92
        """
93
 
        return ForkedFakeService(client.port, messages)
 
93
        return ForkedFakeService(client.port, message_archives)
94
94
 
95
95
    def is_ready(self):
96
96
        """Tell the parent process that the server is ready for writes."""
111
111
    def start_server(self):
112
112
        """Start the HTTP server."""
113
113
        service = HTTPServer(('', self.port), FakeGrackleRequestHandler)
114
 
        service.store = MemoryStore(self.messages)
115
 
        for archive_id, messages in service.store.messages.iteritems():
 
114
        service.store = MemoryStore(self.message_archives)
 
115
        for archive_id, messages in service.store.message_archives.iteritems():
116
116
            for message in messages:
117
117
                message.setdefault('headers', {})
118
118
        self.is_ready()