## 一个问题

def test_update_article(self):
resp = self.c.post(
reverse('apiary_update_article'),
content_type='application/json'
)
self.assertJSONEqual(
json.dumps({'status': 'ok', 'article_id': 1}),
resp.content
)
# repost article with the same payload
# case to ensure the article wont be duplicated


## 一个过程

class SomeTest(unittest.case.TestCase):
def setUp(self):
super(SomeTest, self).setUp()
setup_db() # 初始化数据库，通常是在建立连接、创建表、创建初始数据等。

def tearDown(self):
clean_db() # 清理数据库现场，通常是在删除用例里产生的新数据、断开连接。
super(SomeTest, self).tearDown()


## 一个真 Bug

Important
Because sequences are non-transactional, changes made by setval are not undone if the transaction rolls back.
This function requires UPDATE privilege on the sequence.

Postgres 特别提醒：由于自增序列（像上边用例的 article_id）是非事务性的，所以事务回滚是没法撤销自增序列上的修改的。

Why？

Aaron 解释说：

It would not be a good idea to rollback sequences. Imagine two transactions happening at the same time, each of which uses the sequence for a unique id. If the second transaction commits and the first transaction rolls back, then the second inserted a row with "2" while the first rolls the sequence back to "1".
If that sequence is then used again, the value of the sequence will become "2" which could lead to a unique constraint problem.