Esempio n. 1
0
    def test_when_db_return_none(self, mocked_handler):
        doc = None
        self.db.get.side_effect = iter([doc])
        mocked_handler.side_effect = iter([DummyException])

        with self.assertRaises(DummyException):
            extract_lot_adapter(self.mocked_request, self.lot_id)
        assert self.db.get.call_count == 1
        self.db.get.assert_called_with(self.lot_id)

        assert mocked_handler.call_count == 1
        mocked_handler.assert_called_with(self.mocked_request)

        assert self.mocked_request.errors.add.call_count == 1
        self.mocked_request.errors.add.assert_called_with('url', 'lot_id', 'Not Found')
        assert self.mocked_request.errors.status == 404
        self.mocked_request.errors.status = None

        assert self.mocked_request.lot_from_data.call_count == 0
Esempio n. 2
0
    def test_db_return_doc_type_equal_lot(self, mocked_handler):
        doc = {'doc_type': 'Lot'}
        self.db.get.side_effect = iter([doc])
        self.mocked_request.lot_from_data.side_effect = iter(['lotFromData'])
        returned_value = extract_lot_adapter(self.mocked_request, self.lot_id)
        assert returned_value == 'lotFromData'
        assert self.db.get.call_count == 1
        self.db.get.assert_called_with(self.lot_id)

        assert self.mocked_request.errors.add.call_count == 0
        assert self.mocked_request.errors.status is None
        assert mocked_handler.call_count == 0

        assert self.mocked_request.lot_from_data.call_count == 1
        self.mocked_request.lot_from_data.assert_called_with(doc)