diff --git a/docs/source/yaentry.rst b/docs/source/yaentry.rst index 0397881..a67acb6 100644 --- a/docs/source/yaentry.rst +++ b/docs/source/yaentry.rst @@ -38,6 +38,9 @@ } ).save(person.links['posts']) +А теперь удалим эту запись за ненадобностью:: + + nocomment_entry.delete() .. _class-yaentry: diff --git a/pyyaru/__init__.py b/pyyaru/__init__.py index 6ce65c4..90e9e74 100644 --- a/pyyaru/__init__.py +++ b/pyyaru/__init__.py @@ -1 +1 @@ -VERSION = (0, 3, 1) +VERSION = (0, 3, 2) diff --git a/pyyaru/pyyaru.py b/pyyaru/pyyaru.py index 5c916fc..b1ac905 100644 --- a/pyyaru/pyyaru.py +++ b/pyyaru/pyyaru.py @@ -32,7 +32,7 @@ NAMESPACES = { 'a': 'http://www.w3.org/2005/Atom', - 'y': 'yandex:data', # TODO: Скоро будет http://api.yandex.ru/yaru/ + 'y': 'http://api.yandex.ru/yaru/', 'thr': 'http://purl.org/syndication/thread/1.0', } @@ -238,22 +238,27 @@ def save(self, target_url=None): if self.id is None: resource_data = yaResource(target_url).create(data, self._content_type) - if not resource_data[2]: + if resource_data[2] == False: raise yaOperationError('Unable to create resource at "%s".' % target_url) else: resource_data = yaResource(self.links['edit']).update(data, self._content_type) - if not resource_data[2]: + if resource_data[2] == False: raise yaOperationError('Unable to update resource at "%s".' % self.links['edit']) if resource_data is not None and resource_data[2]: self._parse(resource_data) def delete(self): - """Используется для удаления ресурса.""" + """Используется для удаления ресурса. + В случае удачного свершения свойство id объекта становится равным None. + + """ if self.id is not None: resource_data = yaResource(self.links['edit']).delete() - if not resource_data[2]: + if resource_data[2] == False: raise yaOperationError('Unable to delete resource at "%s".' % self.links['edit']) + else: + self.id = None class yaCollection(yaBase): diff --git a/pyyaru/tests.py b/pyyaru/tests.py index f257ec4..3f1245b 100644 --- a/pyyaru/tests.py +++ b/pyyaru/tests.py @@ -57,7 +57,10 @@ def test_lazy_load_on_attrib_access(self): self.assertEqual(person.id, resource_urn_person) def test_me_resource(self): - """Загрузка профиля с ресурса /me/. Требует авторизации.""" + """Загрузка профиля с ресурса /me/. + Требует авторизации. + + """ person = pyyaru.yaPerson(resource_uri_me).get() self.assertNotEqual(person.id, resource_uri_me) @@ -172,12 +175,31 @@ def test_kwarg_attributes_wrong(self): self.assertRaises(pyyaru.yaEntryAccessUnknownError, pyyaru.yaEntry, attributes={'access': 'me-and-my-kitten'}) def test_init_properties(self): - """Проверка инициализации свойств несвязанного объяекта.""" + """Проверка инициализации свойств несвязанного объекта.""" entry = pyyaru.yaEntry() self.assertEqual(entry.access, 'private') self.assertEqual(entry.comments_disabled, False) self.assertEqual(entry.type, 'text') + def test_create_delete(self): + """Проверка создания и удаления публикации. + Требует авторизации. + + """ + me = pyyaru.yaPerson(resource_uri_me).get() + entry = pyyaru.yaEntry( + attributes={ + 'type': 'text', + 'title': 'Тестовый заголовок из pyyaru', + 'content': 'Это сообщение является тестовым.', + 'access': 'private', + 'comments_disabled': True, + } + ).save(me.links['posts']) + self.assertNotEqual(entry.id, None) + entry.delete() + self.assertEqual(entry.id, None) + class yaCollectionCheck(unittest.TestCase):