def create_document(self, document_id, title, path, created=None, description=None, content=None, promote=None, language=None, tags=None): """Create a new document given its document_id and attributes. Both title and path are required, as are at least one of description and content. """ if not description and not content: raise ValueError( 'must provide at least one of description, content' ) data = self._make_document_data( title=title, path=path, created=util.prep_datetime(created), description=description, content=content, promote=promote, language=language, tags=util.prep_tags(tags) ) data['document_id'] = document_id return self.request('post', self.class_url(), data=data)
def update_document(self, document_id, title=None, path=None, created=None, description=None, content=None, changed=None, promote=None, language=None, tags=None): """Update a document given its document_id and changed attributes.""" data = self._make_document_data( title=title, path=path, created=util.prep_datetime(created), description=description, content=content, changed=util.prep_datetime(changed), promote=promote, language=language, tags=util.prep_tags(tags) ) return self.request('put', self.instance_url(document_id), data=data)
def test_none_returns_none(self): self.assertIsNone(prep_datetime(None))
def test_non_datetime_raises_valueerror(self): with self.assertRaises(ValueError): prep_datetime('foo')
def test_datetime_returns_isoformat(self): self.assertEqual(prep_datetime(datetime(2017, 1, 2, 3, 4, 5, 123456)), '2017-01-02T03:04:05.123456')