class TestMongodbEnvironLagRecorder(object):
    
    #{ Fixture handling
    
    @classmethod
    def setup_class(cls):
        cls.connection = PymongoConnection()
        cls.database = cls.connection['wsgilag-tests']
    
    @classmethod
    def teardown_class(cls):
        cls.connection.drop_database(cls.database)
        cls.connection.disconnect()
    
    def setup(self):
        self.collection = self.database['fixture']
        
        self.logging_handler_fixture = LoggingHandlerFixture('wsgilag')
    
    def teardown(self):
        self.database.drop_collection(self.collection)
        
        self.logging_handler_fixture.undo()
    
    #}
    
    def test_autoreconnect(self):
        """
        Critical log entries are issued when the connection to MongoDB is lost.
        
        """
        recorder = MongodbEnvironLagRecorder(
            _UnusablePymongoCollection(), 'PATH', 'REMOTE_USER')
        
        lag_seconds = 2.5
        environ = {'PATH': '/', 'REMOTE_USER': '******'}
        recorder(lag_seconds, environ)
        
        log_messages = self.logging_handler_fixture.handler.messages
        critical_log_messages = log_messages['critical']
        eq_(1, len(critical_log_messages))
        assert_in('foobar', critical_log_messages[0])
        assert_in(str(lag_seconds), critical_log_messages[0])
        assert_in('PATH', critical_log_messages[0])
        assert_in('REMOTE_USER', critical_log_messages[0])
        assert_in('jsmith', critical_log_messages[0])
    
    def test_recording(self):
        recorder = MongodbEnvironLagRecorder(
            self.collection, 'PATH', 'REMOTE_USER')
        
        environ = {'PATH': '/', 'REMOTE_USER': '******'}
        recorder(2.5, environ)
        
        eq_(1, self.collection.count())
        
        mongo_document = self.collection.find_one()
        assert_dict_contains_subset(environ, mongo_document)
Beispiel #2
0
 def test_retrieving_non_existing_localized_names(self):
     """
     When a non-existing localized name is requested, a warning must be 
     issued and the global name returned.
     
     """
     bind = Bind("foo", String("hey"), es="fulano")
     logging_fixture = LoggingHandlerFixture()
     eq_(bind.get_localized_name("fr"), "foo")
     # Checking for the the warning:
     eq_(len(logging_fixture.handler.messages["warning"]), 1)
     warning = logging_fixture.handler.messages["warning"][0]
     eq_(warning, 'Operand "hey" bound as "foo" doesn\'t have a name in fr; '
                  'using the global one')
     # Undoing it:
     logging_fixture.undo()
Beispiel #3
0
 def test_retrieving_non_existing_localized_names(self):
     """
     When a non-existing localized name is requested, a warning must be 
     issued and the global name returned.
     
     """
     bind = Bind("foo", String("hey"), es="fulano")
     logging_fixture = LoggingHandlerFixture()
     eq_(bind.get_localized_name("fr"), "foo")
     # Checking for the the warning:
     eq_(len(logging_fixture.handler.messages["warning"]), 1)
     warning = logging_fixture.handler.messages["warning"][0]
     eq_(
         warning,
         'Operand "hey" bound as "foo" doesn\'t have a name in fr; '
         'using the global one')
     # Undoing it:
     logging_fixture.undo()
Beispiel #4
0
 def test_parsing_with_undefined_grammar_but_available_translations(self):
     """
     When an expression is written in an unsupported grammar, a parser
     based on the generic grammar must be created and used.
     
     The respective translated bindings must be used if available.
     
     """
     log_handler = LoggingHandlerFixture()
     mgr = EvaluableParseManager(self.symbol_table, Grammar())
     # Castilian grammar is not supported:
     parse_tree = mgr.parse(u"tráfico:peatones_cruzando_calle <= 3.0", "es")
     expected_tree = EvaluableParseTree(
         LessEqual(PedestriansCrossingRoad(), Number(3)))
     eq_(parse_tree, expected_tree)
     # Checking the log:
     info = "Generated parser for unknown grammar 'es'"
     ok_(info in log_handler.handler.messages['info'])
     log_handler.undo()
Beispiel #5
0
 def test_parsing_with_undefined_grammar_but_available_translations(self):
     """
     When an expression is written in an unsupported grammar, a parser
     based on the generic grammar must be created and used.
     
     The respective translated bindings must be used if available.
     
     """
     log_handler = LoggingHandlerFixture()
     mgr = EvaluableParseManager(self.symbol_table, Grammar())
     # Castilian grammar is not supported:
     parse_tree = mgr.parse(u"tráfico:peatones_cruzando_calle <= 3.0", "es")
     expected_tree = EvaluableParseTree(
         LessEqual(PedestriansCrossingRoad(), Number(3)))
     eq_(parse_tree, expected_tree)
     # Checking the log:
     info = "Generated parser for unknown grammar 'es'"
     ok_(info in log_handler.handler.messages['info'])
     log_handler.undo()
Beispiel #6
0
 def test_parsing_with_undefined_grammar_and_no_translated_bindings(self):
     """
     When an expression is written in an unsupported grammar, a parser
     based on the generic grammar must be created and used.
     
     If there are no translated bindings, the default names must be used.
     
     """
     log_handler = LoggingHandlerFixture()
     mgr = EvaluableParseManager(self.symbol_table, Grammar())
     # French grammar is not supported:
     parse_tree = mgr.parse("traffic:pedestrians_crossing_road <= 3.0", "fr")
     expected_tree = EvaluableParseTree(
         LessEqual(PedestriansCrossingRoad(), Number(3)))
     eq_(parse_tree, expected_tree)
     # Checking the log:
     info = "Generated parser for unknown grammar 'fr'"
     ok_(info in log_handler.handler.messages['info'])
     log_handler.undo()
Beispiel #7
0
 def test_parsing_with_undefined_grammar_and_no_translated_bindings(self):
     """
     When an expression is written in an unsupported grammar, a parser
     based on the generic grammar must be created and used.
     
     If there are no translated bindings, the default names must be used.
     
     """
     log_handler = LoggingHandlerFixture()
     mgr = EvaluableParseManager(self.symbol_table, Grammar())
     # French grammar is not supported:
     parse_tree = mgr.parse("traffic:pedestrians_crossing_road <= 3.0",
                            "fr")
     expected_tree = EvaluableParseTree(
         LessEqual(PedestriansCrossingRoad(), Number(3)))
     eq_(parse_tree, expected_tree)
     # Checking the log:
     info = "Generated parser for unknown grammar 'fr'"
     ok_(info in log_handler.handler.messages['info'])
     log_handler.undo()
 def setup(self):
     self.collection = self.database['fixture']
     
     self.logging_handler_fixture = LoggingHandlerFixture('wsgilag')