예제 #1
0
 def test_to_dictionary_returns_instance_variables_as_dictionary(self):
     message = Message()
     message.banana = 5
     message.apple = 7
     message.inner_dictionary = {
         'foo': 2,
         'bar': 4
     }
     dictionary = message.to_dictionary()
     self.assertEqual(7, dictionary['apple'])
     self.assertEqual(4, dictionary['inner_dictionary']['bar'])
     self.assertEqual(3, len(dictionary.keys()))
예제 #2
0
    def test_reading_from_the_queue_returns_a_message_object(self):
        queue = Queue(database='karait_test', queue='queue_test')

        write_message = Message()
        write_message.apple = 5
        write_message.banana = 6
        write_message.inner_object = {'foo': 1, 'bar': 2}
        queue.write(write_message)

        read_message = queue.read()[0]
        self.assertEqual(5, read_message.apple)
        self.assertEqual(2, read_message.inner_object['bar'])
        self.assertEqual(3, len(read_message.to_dictionary().keys()))
예제 #3
0
    def test_writing_a_message_to_the_queue_populates_it_within_mongodb(self):
        queue = Queue(database='karait_test', queue='queue_test')

        message = Message()
        message.apple = 5
        message.banana = 6
        message.inner_object = {'foo': 1, 'bar': 2}
        queue.write(message)

        collection = Connection().karait_test.queue_test
        obj = collection.find_one({})
        self.assertEqual(6, obj['banana'])
        self.assertEqual(2, obj['inner_object']['bar'])
        self.assertTrue(obj['_meta']['expire'])
        self.assertTrue(obj['_meta']['timestamp'])
예제 #4
0
 def test_reading_from_the_queue_returns_a_message_object(self):
     queue = Queue(
         database='karait_test',
         queue='queue_test'
     )
     
     write_message = Message()
     write_message.apple = 5
     write_message.banana = 6
     write_message.inner_object = {
         'foo': 1,
         'bar': 2
     }
     queue.write(write_message)
     
     read_message = queue.read()[0]
     self.assertEqual(5, read_message.apple)
     self.assertEqual(2, read_message.inner_object['bar'])
     self.assertEqual(3, len(read_message.to_dictionary().keys()))
예제 #5
0
    def test_writing_a_message_to_the_queue_populates_it_within_mongodb(self):
        queue = Queue(
            database='karait_test',
            queue='queue_test'
        )
        
        message = Message()
        message.apple = 5
        message.banana = 6
        message.inner_object = {
            'foo': 1,
            'bar': 2
        }
        queue.write(message)

        collection = Connection().karait_test.queue_test
        obj = collection.find_one({})
        self.assertEqual(6, obj['banana'])
        self.assertEqual(2, obj['inner_object']['bar'])
        self.assertTrue(obj['_meta']['expire'])
        self.assertTrue(obj['_meta']['timestamp'])