def test_should_call_update_issues_in_journal(self):
     self.request.matchdict["journal_id"] = "example-journal-id"
     self.request.validated = [
         {
             "id": "issue-1",
             "ns": []
         },
         {
             "id": "issue-2",
             "ns": []
         },
     ]
     MockUpdateIssuesInJournal = Mock()
     self.request.services[
         "update_issues_in_journal"] = MockUpdateIssuesInJournal
     restfulapi.put_journal_issues(self.request)
     MockUpdateIssuesInJournal.assert_called_once_with(
         id="example-journal-id",
         issues=[{
             "id": "issue-1",
             "ns": []
         }, {
             "id": "issue-2",
             "ns": []
         }],
     )
 def test_should_not_update_if_already_exists_exception_is_raised(self):
     self.request.matchdict["journal_id"] = "example-journal-id"
     self.request.validated = [
         {
             "id": "issue-1",
             "ns": []
         },
         {
             "id": "issue-1",
             "ns": []
         },
     ]
     restfulapi.put_journal_issues(self.request)
     response = restfulapi.get_journal(self.request)
     self.assertEqual([], response.get("items"))
 def test_should_return_404_if_journal_not_found(self):
     self.request.matchdict["journal_id"] = "example-journal-id"
     self.request.validated = [{"id": "issue-1", "ns": []}]
     MockUpdateIssuesInJournal = Mock(
         side_effect=exceptions.DoesNotExist("Does Not Exist"))
     self.request.services[
         "update_issues_in_journal"] = MockUpdateIssuesInJournal
     response = restfulapi.put_journal_issues(self.request)
     self.assertIsInstance(response, HTTPNotFound)
 def test_should_return_422_if_already_exists_exception_is_raised(self):
     self.request.matchdict["journal_id"] = "example-journal-id"
     self.request.validated = [
         {
             "id": "issue-1",
             "ns": []
         },
         {
             "id": "issue-1",
             "ns": []
         },
     ]
     response = restfulapi.put_journal_issues(self.request)
     self.assertIsInstance(response, HTTPUnprocessableEntity)
 def test_should_return_204_if_journal_issues_was_updated(self):
     self.request.matchdict["journal_id"] = "example-journal-id"
     self.request.validated = [{"id": "issue-1", "ns": []}]
     response = restfulapi.put_journal_issues(self.request)
     self.assertIsInstance(response, HTTPNoContent)