コード例 #1
0
    def test_update_successfully(self):
        attachment = AttachmentFileFactory(external_id=1,
                                           source_type='DOCUMENTCLOUD')
        attachment.update_to_documentcloud('title', 'some title')

        expect(self.mock_client.documents.get).to.be.called_with(1)
        expect(self.mock_doc.save).to.be.called()
        expect(self.mock_logger.error).not_to.be.called()
        expect(self.mock_doc.title).to.be.eq('some title')
コード例 #2
0
    def test_not_update_when_cannot_get_documentcloud_document(self):
        self.mock_client.documents.get.side_effect = DoesNotExistError()
        attachment = AttachmentFileFactory(external_id=1,
                                           source_type='DOCUMENTCLOUD')
        attachment.update_to_documentcloud('title', 'some title')

        expect(self.mock_doc.save).not_to.be.called()
        expect(self.mock_logger.error).to.be.called_with(
            'Cannot find document with external id 1 on DocumentCloud')
コード例 #3
0
    def test_not_update_when_cannot_save_documentcloud_document(self):
        self.mock_doc.save.side_effect = HTTPError('', '404', '', None, None)
        attachment = AttachmentFileFactory(external_id=1,
                                           source_type='DOCUMENTCLOUD')
        attachment.update_to_documentcloud('title', 'some title')

        expect(self.mock_doc.title).to.be.eq('some title')
        expect(self.mock_logger.error).to.be.called_with(
            'Cannot save document with external id 1 on DocumentCloud')
コード例 #4
0
    def test_not_update_when_no_change(self):
        attachment = AttachmentFileFactory(external_id=1,
                                           source_type='DOCUMENTCLOUD',
                                           title='no changed title')
        setattr(self.mock_doc, 'title', 'no changed title')

        attachment.update_to_documentcloud('title', 'no changed title')

        expect(self.mock_client.documents.get).to.be.called_with(1)
        expect(self.mock_doc.save).not_to.be.called()
コード例 #5
0
 def test_not_update_with_wrong_source_type(self):
     attachment = AttachmentFileFactory(source_type='something wrong')
     attachment.update_to_documentcloud('title', 'some title')
     expect(self.mock_client.documents.get).not_to.be.called()
     expect(self.mock_doc.save).not_to.be.called()
     expect(self.mock_logger.error).not_to.be.called()