def test_add_link(self): document = DocumentFactory() allegation = document.allegation allegation.crid = 1002643 allegation.save() crid = allegation.crid documentcloud_id = 1273509 normalized_title = 'cr-{crid}'.format(crid=crid) title = 'CR {crid}'.format(crid=crid) Setting.objects.create( default_site_title='CPDB', story_types_order='', requested_document_email_subject='{crid}', requested_document_email_text='{crid} {link}' ) RequestEmailFactory(document=document) response = self.client.post(reverse('dashboard-document-link'), { 'link': 'https://www.documentcloud.org/documents/%s-%s.html' % ( documentcloud_id, normalized_title) }) response.status_code.should.equal(200) content = json.loads(response.content.decode()) content['crid'].should.contain(str(crid)) document.refresh_from_db() document.documentcloud_id.should.equal(documentcloud_id) document.normalized_title.should.equal(normalized_title) document.title.should.equal(title) # email notification len(mail.outbox).should.equal(1)
def test_add_link_for_document(self): document = DocumentFactory() documentcloud_id = 111111 normalized_title = 'normalized_title' title = 'title' process_link_func = MagicMock( return_value={ 'documentcloud_id': documentcloud_id, 'normalized_title': normalized_title, 'title': title }) with patch( 'dashboard.services.documentcloud_service.DocumentcloudService.process_link', new=process_link_func): response = self.client.post( reverse('dashboard-document-link'), { 'link': 'https://www.documentcloud.org/documents/%s-%s.html' % (documentcloud_id, normalized_title), 'id': document.id }) response.status_code.should.equal(200) document.refresh_from_db() document.documentcloud_id.should.equal(documentcloud_id) document.normalized_title.should.equal(normalized_title) document.title.should.equal(title)
def test_add_link(self): document = DocumentFactory() allegation = document.allegation allegation.crid = 1002643 allegation.save() crid = allegation.crid documentcloud_id = 1273509 normalized_title = 'cr-{crid}'.format(crid=crid) title = 'CR {crid}'.format(crid=crid) Setting.objects.create(default_site_title='CPDB', story_types_order='', requested_document_email_subject='{crid}', requested_document_email_text='{crid} {link}') RequestEmailFactory(document=document) response = self.client.post( reverse('dashboard-document-link'), { 'link': 'https://www.documentcloud.org/documents/%s-%s.html' % (documentcloud_id, normalized_title) }) response.status_code.should.equal(200) content = json.loads(response.content.decode()) content['crid'].should.contain(str(crid)) document.refresh_from_db() document.documentcloud_id.should.equal(documentcloud_id) document.normalized_title.should.equal(normalized_title) document.title.should.equal(title) # email notification len(mail.outbox).should.equal(1)
def test_update_auto_set_document_status(self): document = DocumentFactory(requested=True, pending=True) # Update document with documentcloud id document.update(documentcloud_id=1) document.refresh_from_db() document.requested.should.be.false document.pending.should.be.false # Update document pending document.update(pending=False) document.refresh_from_db() document.requested.should.be.true document.documentcloud_id.should.equal(0)
def test_send_notification_on_new_document(self): document = DocumentFactory() unset_document = DocumentFactory(title='UNSET') with mock.patch(self.notification_path): with mock.patch(self.document_cloud_path) as document_cloud: title = fake.name() instance = document_cloud.return_value document = mock.Mock(title=title, id='1-2-3') # search return result instance.documents.search.return_value = [document] management.call_command('update_documents', end=unset_document.id - 1) document.refresh_from_db() document.title.should.equal(title) unset_document.refresh_from_db() unset_document.title.should.equal('UNSET') # it is being called, I've checked with pdb, but not being set send_document_notification.called.should.be.true
def test_add_link_for_document(self): document = DocumentFactory() documentcloud_id = 111111 normalized_title = 'normalized_title' title = 'title' process_link_func = MagicMock(return_value={ 'documentcloud_id': documentcloud_id, 'normalized_title': normalized_title, 'title': title }) with patch('dashboard.services.documentcloud_service.DocumentcloudService.process_link', new=process_link_func): response = self.client.post(reverse('dashboard-document-link'), { 'link': 'https://www.documentcloud.org/documents/%s-%s.html' % (documentcloud_id, normalized_title), 'id': document.id }) response.status_code.should.equal(200) document.refresh_from_db() document.documentcloud_id.should.equal(documentcloud_id) document.normalized_title.should.equal(normalized_title) document.title.should.equal(title)