def test_post_new_user_with_data_but_not_setting_new_data(self): # The database has no to-do list yet. req = pyatdl_pb2.MergeToDoListRequest() req.sanity_check = views.MERGETODOLISTREQUEST_SANITY_CHECK req.latest.CopyFrom(self._cksum()) response = self._happy_post(req.SerializeToString()) assert response.status_code == 409 assert response.content == b'{"error": "This backend has no to-do list. You passed one in but did not set the \'new_data\' boolean to true. We are aborting out of an abundance of caution. You might wish to call this API once with different arguments to trigger the creation of the default to-do list for new users."}'
def test_post_new_user_without_data_without_setting_new_data(self): # The database has no to-do list yet but it will create a starter template req = pyatdl_pb2.MergeToDoListRequest() req.sanity_check = views.MERGETODOLISTREQUEST_SANITY_CHECK response = self._happy_post(req.SerializeToString()) assert response.status_code == 200 pbresp = pyatdl_pb2.MergeToDoListResponse.FromString(response.content) assert pbresp.starter_template assert 'Read the book' in text_format.MessageToString(pbresp)
def test_ill_formed_input(self): self._populate_todolist() req = pyatdl_pb2.MergeToDoListRequest() req.sanity_check = views.MERGETODOLISTREQUEST_SANITY_CHECK pb = self._existing_todolist_protobuf() a = pb.inbox.actions.add() a.common.metadata.name = "testing10013" # SKIP a.common.uid = 373737 req.latest.CopyFrom(self._cksum(pb)) req.previous_sha1_checksum = self._cksum().sha1_checksum response = self._happy_post(req.SerializeToString()) assert response.status_code == 422 assert response.content == b'{"error": "The given to-do list is ill-formed: A UID is missing from or explicitly zero in the protocol buffer!"}'
def test_post_existing_user_but_requires_merge(self): self._populate_todolist() req = pyatdl_pb2.MergeToDoListRequest() req.sanity_check = views.MERGETODOLISTREQUEST_SANITY_CHECK pb = self._existing_todolist_protobuf() a = pb.inbox.actions.add() a.common.metadata.name = "testing10013" a.common.uid = 373737 req.latest.CopyFrom(self._cksum(pb)) req.previous_sha1_checksum = "37" * 20 response = self._happy_post(req.SerializeToString()) assert response.status_code == 500 assert response.content == b'{"error": "The server does not yet implement merging, but merging is required because the sha1_checksum of the todolist prior to your input is \'3737373737373737373737373737373737373737\' and the sha1_checksum of the database is \'32d20be5b6e144d5b665e5690310a0e92ddd70e3\'"}'
def test_post_inactive_user(self): self._populate_todolist() did_it = False for model in User.objects.filter(pk=self.user.pk): model.is_active = False model.save() did_it = True assert did_it req = pyatdl_pb2.MergeToDoListRequest() req.sanity_check = views.MERGETODOLISTREQUEST_SANITY_CHECK response = self._happy_post(req.SerializeToString()) assert response.status_code == 403 assert response.content == b'<h1>403 Forbidden</h1>\n\n <p>The properly formatted "Authorization" header has an invalid username or password.</p>\n\n'
def test_post_previous_sha1_given_for_existing_user(self): self._populate_todolist() req = pyatdl_pb2.MergeToDoListRequest() req.sanity_check = views.MERGETODOLISTREQUEST_SANITY_CHECK pb = self._existing_todolist_protobuf() a = pb.inbox.actions.add() a.common.metadata.name = "testing10013" a.common.uid = 373737 req.latest.CopyFrom(self._cksum(pb)) req.previous_sha1_checksum = self._cksum().sha1_checksum response = self._happy_post(req.SerializeToString()) assert response.status_code == 200 pbresp = pyatdl_pb2.MergeToDoListResponse.FromString(response.content) assert not pbresp.starter_template assert text_format.MessageToString(pbresp) == r""" sha1_checksum: "%s" sanity_check: 18369614221190021342 """.lstrip() % req.latest.sha1_checksum
def test_post_new_user_setting_new_data(self): # The database has no to-do list yet. req = pyatdl_pb2.MergeToDoListRequest() req.sanity_check = views.MERGETODOLISTREQUEST_SANITY_CHECK response = self._happy_post(req.SerializeToString()) assert response.status_code == 200, 'response.content is %s' % response.content pbresp = pyatdl_pb2.MergeToDoListResponse.FromString(response.content) assert text_format.MessageToString(pbresp) == r""" sha1_checksum: "b2f2761dc24359cace7809eaf7cb0e1cf9c3f05e" to_do_list { inbox { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "inbox" } uid: 1 } is_complete: false is_active: true } root { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "" } uid: 2 } projects { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "miscellaneous" } uid: 8677894846078606063 } is_complete: false is_active: true } projects { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "learn how to use this to-do list" } uid: 95864267963049347 } is_complete: false is_active: true actions { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "Watch the video on the \"Help\" page -- find it on the top navigation bar" } uid: -9061335006543989703 } is_complete: false } actions { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "Read the book \"Getting Things Done\" by David Allen" } uid: -5075438498450816768 } is_complete: false } actions { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "After reading the book, try out a Weekly Review -- on the top navigation bar, find it underneath the \"Other\" drop-down" } uid: 4206351632466587494 } is_complete: false } } } ctx_list { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "Contexts" } uid: 1987761140110186971 } contexts { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "@computer" } uid: 277028180750618930 } is_active: true } contexts { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "@phone" } uid: 8923216991658685487 } is_active: true } contexts { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "@home" } uid: 7844860928174339221 } is_active: true } contexts { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "@work" } uid: 4355858073736897916 } is_active: true } contexts { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "@the store" } uid: -8310047117500551536 } is_active: true } contexts { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "@someday/maybe" } uid: 7926615695106819409 } is_active: false } contexts { common { is_deleted: false timestamp { ctime: 37000037 dtime: -1 mtime: 37000037 } metadata { name: "@waiting for" } uid: 3780713555715847339 } is_active: false } } } starter_template: true sanity_check: 18369614221190021342 """.lstrip()
def test_post_existing_user(self): self._populate_todolist() req = pyatdl_pb2.MergeToDoListRequest() req.sanity_check = views.MERGETODOLISTREQUEST_SANITY_CHECK response = self._happy_post(req.SerializeToString()) assert response.status_code == 200 pbresp = pyatdl_pb2.MergeToDoListResponse.FromString(response.content) assert not pbresp.starter_template assert text_format.MessageToString(pbresp) == r""" sha1_checksum: "32d20be5b6e144d5b665e5690310a0e92ddd70e3" to_do_list { inbox { common { is_deleted: false timestamp { ctime: 0 dtime: 0 mtime: 0 } metadata { name: "" } uid: 1 } is_complete: false is_active: false actions { common { is_deleted: false timestamp { ctime: 0 dtime: 0 mtime: 0 } metadata { name: "increase the tests\' branch coverage" } uid: -42 } is_complete: false } } root { common { is_deleted: false timestamp { ctime: 0 dtime: 0 mtime: 0 } metadata { name: "" } uid: 2 } } ctx_list { common { is_deleted: false timestamp { ctime: 1500000000000000 dtime: -1 mtime: 1500000000000000 } metadata { name: "We \342\235\244 Contexts" } uid: -1 } } } sanity_check: 18369614221190021342 """.lstrip()