Example #1
0
    def test_with_detection(self):
        target = Target()
        target.collection = Mock()
        actual = target.insert(ObjectId("012345678901234567890123"),
                               Direction.IN,
                               "text_value",
                               detection="detection_value",
                               now=datetime(2000, 1, 1),
                               _id=ObjectId('992345678901234567890123'))

        self.assertEqual(1, target.collection.insert.call_count)

        self.assertDictEqual(
            {
                '_id': ObjectId('992345678901234567890123'),
                'context_id': ObjectId('012345678901234567890123'),
                'detection': "detection_value",
                'updated': '2000-01-01T00:00:00',
                'created': '2000-01-01T00:00:00',
                'text': 'text_value',
                'direction': 1,
                'version': "0.0.3"
            }, target.collection.insert.call_args_list[0][0][0])

        self.assertDictEqual(
            {
                '_id': ObjectId('992345678901234567890123'),
                'context_id': ObjectId('012345678901234567890123'),
                'created': '2000-01-01T00:00:00',
                'direction': 1,
                'detection': 'detection_value',
                'text': 'text_value',
                'updated': '2000-01-01T00:00:00',
                'version': '0.0.3'
            }, actual)
Example #2
0
    def test_regular(self):
        target = Target()
        target.collection = MagicMock()
        target.collection.find().sort.return_value = ["first", "second"]
        actual = target.find(ObjectId("012345678901234567890123"))

        self.assertListEqual(['first', 'second'], actual)

        self.assertEqual(2, target.collection.find.call_count)
Example #3
0
    def test_regular(self):
        target = Target()
        target.collection = MagicMock()
        target.collection.find().sort.return_value = ["first", "second"]
        actual = target.find(ObjectId("012345678901234567890123"))

        self.assertListEqual(['first', 'second'], actual)

        self.assertEqual(2, target.collection.find.call_count)
Example #4
0
    def test_regular(self):
        target = Target()
        target.collection = Mock()
        target.update(ObjectId("012345678901234567890123"),
                      now=datetime(2000, 1, 1))

        self.assertEqual(1, target.collection.update.call_count)
        self.assertDictEqual({'_id': ObjectId('012345678901234567890123')},
                             target.collection.update.call_args_list[0][0][0])
        self.assertDictEqual(
            {'$set': {
                'updated': '2000-01-01T00:00:00'
            }},
            target.collection.update.call_args_list[0][0][1],
        )
Example #5
0
    def test_regular(self):
        target = Target()
        target.collection = Mock()
        target.update(
            ObjectId("012345678901234567890123"),
            now=datetime(2000, 1, 1)
        )

        self.assertEqual(1, target.collection.update.call_count)
        self.assertDictEqual(
            {
                '_id': ObjectId('012345678901234567890123')
            },
            target.collection.update.call_args_list[0][0][0]
        )
        self.assertDictEqual(
            {'$set': {'updated': '2000-01-01T00:00:00'}},
            target.collection.update.call_args_list[0][0][1],

        )
Example #6
0
    def test_with_detection(self):
        target = Target()
        target.collection = Mock()
        actual = target.insert(
            ObjectId("012345678901234567890123"),
            Direction.IN,
            "text_value",
            detection="detection_value",
            now=datetime(2000, 1, 1),
            _id=ObjectId('992345678901234567890123')
        )

        self.assertEqual(1, target.collection.insert.call_count)

        self.assertDictEqual(
            {
                '_id': ObjectId('992345678901234567890123'),
                'context_id': ObjectId('012345678901234567890123'),
                'detection': "detection_value",
                'updated': '2000-01-01T00:00:00',
                'created': '2000-01-01T00:00:00',
                'text': 'text_value',
                'direction': 1,
                'version': "0.0.3"
            },
            target.collection.insert.call_args_list[0][0][0]
        )

        self.assertDictEqual(
            {
                '_id': ObjectId('992345678901234567890123'),
                'context_id': ObjectId('012345678901234567890123'),
                'created': '2000-01-01T00:00:00',
                'direction': 1,
                'detection': 'detection_value',
                'text': 'text_value',
                'updated': '2000-01-01T00:00:00',
                'version': '0.0.3'
            },
            actual
        )