def post(self): ''' Returns file which is attached to post corresponding to a given date (we assumed a user can't post two posts at the same time). Expected data : * path : file name * date : date on which post was posted * contactKey : the key of the contact which claims the file. ''' data = self.get_body_as_dict(expectedFields=["path", "date", "contactKey"]) if data: contact = ContactManager.getTrustedContact(data["contactKey"]) micropost = MicroPostManager.get_first(data["date"]) if micropost and contact: try: fileContent = micropost.fetch_attachment(data["path"]) self.return_file(data["path"], fileContent) except ResourceNotFound: self.return_failure("File not found", 404) else: self.return_failure("Micropost not found.", 404) else: self.return_failure("Wrong data.", 400)
def when_i_retrieve_a_post_for_a_given_date(step): world.micropost = MicroPostManager.get_first("2011-01-01T11:05:12Z")