def test_set_state_of_two_models(self): """ This shoudn't failed with `MultipleObjectsReturned`. """ api_key = self.__login("user", "pass") headers = self.__build_headers("user", api_key) self.workflow.set_to_model(Author) set_state(self.author, self.state1) set_state(self.author_two, self.state1) author_patch = json.dumps({ "state": self.state2.codename }) response = self.client.patch("/admin-api/author/100/", data=author_patch, content_type='application/json', **headers) tools.assert_equals(response.status_code, 202) tools.assert_equals(get_state(self.author), self.state2) response = self.client.patch("/admin-api/author/101/", data=author_patch, content_type='application/json', **headers) tools.assert_equals(response.status_code, 202) tools.assert_equals(get_state(self.author_two), self.state2) response = self.client.get("/admin-api/author/", **headers) tools.assert_equals(response.status_code, 200) self.__logout(headers)
def _add_state_fields(self, bundle): """Adds current state and next allowed states of object.""" state = get_state(bundle.obj) if (((state and state.codename != "published") or not state) and bundle.obj and bundle.obj.published): set_state(bundle.obj, "published") state = get_state(bundle.obj) if state: bundle.data["state"] = state.codename # FIXME: Use correct transition table bundle.data["allowed_states"] = State.objects.get_states_choices_as_dict() return bundle
def test_set_state_via_api(self): api_key = self.__login("user", "pass") headers = self.__build_headers("user", api_key) self.workflow.set_to_model(Author) set_state(self.author, self.state1) author_patch = json.dumps({ "state": self.state2.codename }) response = self.client.patch("/admin-api/author/100/", data=author_patch, content_type='application/json', **headers) tools.assert_equals(get_state(self.author), self.state2) self.__logout(headers)
def test_get_state(self): tools.assert_equals(get_state(self.author), None)
def test_set_state(self): set_state(self.author, self.state1) set_state(self.author, self.state2) tools.assert_equals(get_state(self.author), self.state2)