text: # -*- coding: utf-8 -*-
  from openprocurement.tender.belowthreshold.tests.base import test_organization, test_cancellation
  
  from openprocurement.tender.competitivedialogue.tests.base import test_tenderer
  from openprocurement.api.models import get_now
  from openprocurement.api.constants import RELEASE_2020_04_19
  from openprocurement.tender.core.tests.cancellation import activate_cancellation_after_2020_04_19
  
  
  # TenderAwardCompaintDocument EU
  
  
  def create_tender_award_complaint_document(self):
      response = self.app.post(
          "/tenders/{}/awards/{}/complaints/{}/documents".format(self.tender_id, self.award_id, self.complaint_id),
          upload_files=[("file", "name.doc", "content")],
          status=403,
      )
      self.assertEqual(response.status, "403 Forbidden")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(
          response.json["errors"][0]["description"], "Can't add document in current (draft) complaint status"
      )
  
      response = self.app.post(
          "/tenders/{}/awards/{}/complaints/{}/documents?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, self.complaint_owner_token
          ),
          upload_files=[("file", "name.doc", "content")],
      )
      self.assertEqual(response.status, "201 Created")
      self.assertEqual(response.content_type, "application/json")
      doc_id = response.json["data"]["id"]
      self.assertIn(doc_id, response.headers["Location"])
      self.assertEqual("name.doc", response.json["data"]["title"])
      key = response.json["data"]["url"].split("?")[-1]
  
      response = self.app.get(
          "/tenders/{}/awards/{}/complaints/{}/documents".format(self.tender_id, self.award_id, self.complaint_id)
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(doc_id, response.json["data"][0]["id"])
      self.assertEqual("name.doc", response.json["data"][0]["title"])
  
      response = self.app.get(
          "/tenders/{}/awards/{}/complaints/{}/documents?all=true".format(
              self.tender_id, self.award_id, self.complaint_id
          )
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(doc_id, response.json["data"][0]["id"])
      self.assertEqual("name.doc", response.json["data"][0]["title"])
  
      response = self.app.get(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?download=some_id".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id
          ),
          status=404,
      )
      self.assertEqual(response.status, "404 Not Found")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(
          response.json["errors"], [{u"description": u"Not Found", u"location": u"url", u"name": u"download"}]
      )
  
      response = self.app.get(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?{}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, key
          )
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/msword")
      self.assertEqual(response.content_length, 7)
      self.assertEqual(response.body, "content")
  
      response = self.app.get(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id
          )
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(doc_id, response.json["data"]["id"])
      self.assertEqual("name.doc", response.json["data"]["title"])
  
      cancellation = dict(**test_cancellation)
      cancellation.update({
          "status": "active",
          "cancellationOf": "lot",
          "relatedLot": self.lots[0]["id"],
      })
      response = self.app.post_json(
          "/tenders/{}/cancellations".format(self.tender_id),
          {"data": cancellation},
      )
      self.assertEqual(response.status, "201 Created")
      cancellation_id = response.json["data"]["id"]
      if RELEASE_2020_04_19 < get_now():
          activate_cancellation_after_2020_04_19(self, cancellation_id)
  
      response = self.app.post(
          "/tenders/{}/awards/{}/complaints/{}/documents".format(self.tender_id, self.award_id, self.complaint_id),
          upload_files=[("file", "name.doc", "content")],
          status=403,
      )
      self.assertEqual(response.status, "403 Forbidden")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["errors"][0]["description"], "Can add document only in active lot status")
  
  
  def put_tender_award_complaint_document(self):
      response = self.app.post(
          "/tenders/{}/awards/{}/complaints/{}/documents?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, self.complaint_owner_token
          ),
          upload_files=[("file", "name.doc", "content")],
      )
      self.assertEqual(response.status, "201 Created")
      self.assertEqual(response.content_type, "application/json")
      doc_id = response.json["data"]["id"]
      self.assertIn(doc_id, response.headers["Location"])
  
      response = self.app.put(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id
          ),
          status=404,
          upload_files=[("invalid_name", "name.doc", "content")],
      )
      self.assertEqual(response.status, "404 Not Found")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(response.json["errors"], [{u"description": u"Not Found", u"location": u"body", u"name": u"file"}])
  
      response = self.app.put(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id
          ),
          upload_files=[("file", "name.doc", "content2")],
          status=403,
      )
      self.assertEqual(response.status, "403 Forbidden")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["errors"][0]["description"], "Can update document only author")
  
      response = self.app.put(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, self.complaint_owner_token
          ),
          upload_files=[("file", "name.doc", "content2")],
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(doc_id, response.json["data"]["id"])
      key = response.json["data"]["url"].split("?")[-1]
  
      response = self.app.get(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?{}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, key
          )
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/msword")
      self.assertEqual(response.content_length, 8)
      self.assertEqual(response.body, "content2")
  
      response = self.app.get(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id
          )
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(doc_id, response.json["data"]["id"])
      self.assertEqual("name.doc", response.json["data"]["title"])
  
      response = self.app.put(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, self.complaint_owner_token
          ),
          "content3",
          content_type="application/msword",
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(doc_id, response.json["data"]["id"])
      key = response.json["data"]["url"].split("?")[-1]
  
      response = self.app.get(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?{}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, key
          )
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/msword")
      self.assertEqual(response.content_length, 8)
      self.assertEqual(response.body, "content3")
  
      response = self.app.put(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, self.complaint_owner_token
          ),
          "content4",
          content_type="application/msword",
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      key = response.json["data"]["url"].split("?")[-1]
  
      response = self.app.get(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?{}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, key
          )
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/msword")
      self.assertEqual(response.content_length, 8)
      self.assertEqual(response.body, "content4")
  
      cancellation = dict(**test_cancellation)
      cancellation.update({
          "status": "active",
          "cancellationOf": "lot",
          "relatedLot": self.lots[0]["id"],
      })
      response = self.app.post_json(
          "/tenders/{}/cancellations".format(self.tender_id),
          {"data": cancellation},
      )
      self.assertEqual(response.status, "201 Created")
      cancellation_id = response.json["data"]["id"]
      if RELEASE_2020_04_19 < get_now():
          activate_cancellation_after_2020_04_19(self, cancellation_id)
  
      response = self.app.put(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, self.complaint_owner_token
          ),
          upload_files=[("file", "name.doc", "content3")],
          status=403,
      )
      self.assertEqual(response.status, "403 Forbidden")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["errors"][0]["description"], "Can update document only in active lot status")
  
  
  def patch_tender_award_complaint_document(self):
      response = self.app.post(
          "/tenders/{}/awards/{}/complaints/{}/documents?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, self.complaint_owner_token
          ),
          upload_files=[("file", "name.doc", "content")],
      )
      self.assertEqual(response.status, "201 Created")
      self.assertEqual(response.content_type, "application/json")
      doc_id = response.json["data"]["id"]
      self.assertIn(doc_id, response.headers["Location"])
  
      response = self.app.patch_json(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id
          ),
          {"data": {"description": "document description"}},
          status=403,
      )
      self.assertEqual(response.status, "403 Forbidden")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["errors"][0]["description"], "Can update document only author")
  
      response = self.app.patch_json(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, self.complaint_owner_token
          ),
          {"data": {"description": "document description"}},
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(doc_id, response.json["data"]["id"])
  
      response = self.app.get(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id
          )
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(doc_id, response.json["data"]["id"])
      self.assertEqual("document description", response.json["data"]["description"])
  
      response = self.app.patch_json(
          "/tenders/{}/awards/{}/complaints/{}?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, self.complaint_owner_token
          ),
          {"data": {"status": "pending"}},
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.json["data"]["status"], "pending")
  
      response = self.app.patch_json(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, self.complaint_owner_token
          ),
          {"data": {"description": "document description2"}},
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["data"]["description"], "document description2")
  
      cancellation = dict(**test_cancellation)
      cancellation.update({
          "status": "active",
          "cancellationOf": "lot",
          "relatedLot": self.lots[0]["id"],
      })
      response = self.app.post_json(
          "/tenders/{}/cancellations".format(self.tender_id),
          {"data": cancellation},
      )
      self.assertEqual(response.status, "201 Created")
      cancellation_id = response.json["data"]["id"]
      if RELEASE_2020_04_19 < get_now():
          activate_cancellation_after_2020_04_19(self, cancellation_id)
  
      response = self.app.patch_json(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, self.complaint_owner_token
          ),
          {"data": {"description": "document description"}},
          status=403,
      )
      self.assertEqual(response.status, "403 Forbidden")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["errors"][0]["description"], "Can update document only in active lot status")
  
  
  # TenderAwardResourseTest UA
  
  
  def create_tender_award_invalid(self):
      self.app.authorization = ("Basic", ("token", ""))
      request_path = "/tenders/{}/awards?acc_token={}".format(self.tender_id, self.tender_token)
      response = self.app.post(request_path, "data", status=415)
      self.assertEqual(response.status, "415 Unsupported Media Type")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(
          response.json["errors"],
          [
              {
                  u"description": u"Content-Type header should be one of ['application/json']",
                  u"location": u"header",
                  u"name": u"Content-Type",
              }
          ],
      )
  
      response = self.app.post(request_path, "data", content_type="application/json", status=422)
      self.assertEqual(response.status, "422 Unprocessable Entity")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(
          response.json["errors"],
          [{u"description": u"No JSON object could be decoded", u"location": u"body", u"name": u"data"}],
      )
  
      response = self.app.post_json(request_path, "data", status=422)
      self.assertEqual(response.status, "422 Unprocessable Entity")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(
          response.json["errors"], [{u"description": u"Data not available", u"location": u"body", u"name": u"data"}]
      )
  
      response = self.app.post_json(request_path, {"not_data": {}}, status=422)
      self.assertEqual(response.status, "422 Unprocessable Entity")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(
          response.json["errors"], [{u"description": u"Data not available", u"location": u"body", u"name": u"data"}]
      )
  
      response = self.app.post_json(request_path, {"data": {"invalid_field": "invalid_value"}}, status=422)
      self.assertEqual(response.status, "422 Unprocessable Entity")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(
          response.json["errors"], [{u"description": u"Rogue field", u"location": u"body", u"name": u"invalid_field"}]
      )
  
      response = self.app.post_json(request_path, {"data": {"suppliers": [{"identifier": "invalid_value"}]}}, status=422)
      self.assertEqual(response.status, "422 Unprocessable Entity")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(
          response.json["errors"],
          [
              {
                  u"description": {
                      u"identifier": [u"Please use a mapping for this field or Identifier instance instead of unicode."]
                  },
                  u"location": u"body",
                  u"name": u"suppliers",
              }
          ],
      )
  
      response = self.app.post_json(request_path, {"data": {"suppliers": [{"identifier": {"id": 0}}]}}, status=422)
      self.assertEqual(response.status, "422 Unprocessable Entity")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(
          response.json["errors"],
          [
              {
                  u"description": [
                      {
                          u"contactPoint": [u"This field is required."],
                          u"identifier": {u"scheme": [u"This field is required."]},
                          u"name": [u"This field is required."],
                          u"address": [u"This field is required."],
                      }
                  ],
                  u"location": u"body",
                  u"name": u"suppliers",
              },
              {u"description": [u"This field is required."], u"location": u"body", u"name": u"bid_id"},
          ],
      )
  
      response = self.app.post_json(
          request_path, {"data": {"suppliers": [{"name": "name", "identifier": {"uri": "invalid_value"}}]}}, status=422
      )
      self.assertEqual(response.status, "422 Unprocessable Entity")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(
          response.json["errors"],
          [
              {
                  u"description": [
                      {
                          u"contactPoint": [u"This field is required."],
                          u"identifier": {
                              u"scheme": [u"This field is required."],
                              u"id": [u"This field is required."],
                              u"uri": [u"Not a well formed URL."],
                          },
                          u"address": [u"This field is required."],
                      }
                  ],
                  u"location": u"body",
                  u"name": u"suppliers",
              },
              {u"description": [u"This field is required."], u"location": u"body", u"name": u"bid_id"},
          ],
      )
  
      response = self.app.post_json(
          request_path,
          {
              "data": {
                  "suppliers": [test_organization],
                  "status": "pending",
                  "bid_id": self.initial_bids[0]["id"],
                  "lotID": "0" * 32,
              }
          },
          status=422,
      )
      self.assertEqual(response.status, "422 Unprocessable Entity")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(
          response.json["errors"],
          [{u"description": [u"lotID should be one of lots"], u"location": u"body", u"name": u"lotID"}],
      )
  
      response = self.app.post_json(
          "/tenders/some_id/awards",
          {"data": {"suppliers": [test_organization], "bid_id": self.initial_bids[0]["id"]}},
          status=404,
      )
      self.assertEqual(response.status, "404 Not Found")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(
          response.json["errors"], [{u"description": u"Not Found", u"location": u"url", u"name": u"tender_id"}]
      )
  
      response = self.app.get("/tenders/some_id/awards", status=404)
      self.assertEqual(response.status, "404 Not Found")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(
          response.json["errors"], [{u"description": u"Not Found", u"location": u"url", u"name": u"tender_id"}]
      )
  
      self.set_status("complete")
  
      response = self.app.post_json(
          "/tenders/{}/awards".format(self.tender_id),
          {"data": {"suppliers": [test_organization], "status": "pending", "bid_id": self.initial_bids[0]["id"]}},
          status=403,
      )
      self.assertEqual(response.status, "403 Forbidden")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(
          response.json["errors"][0]["description"], "Can't create award in current (complete) tender status"
      )
  
  
  def get_tender_award(self):
      auth = self.app.authorization
      self.app.authorization = ("Basic", ("token", ""))
      response = self.app.post_json(
          "/tenders/{}/awards".format(self.tender_id),
          {"data": {"suppliers": [test_tenderer], "status": "pending", "bid_id": self.bids[0]["id"]}},
      )
      self.assertEqual(response.status, "201 Created")
      self.assertEqual(response.content_type, "application/json")
      award = response.json["data"]
  
      self.app.auth = auth
      response = self.app.get("/tenders/{}/awards/{}".format(self.tender_id, award["id"]))
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      award_data = response.json["data"]
      self.assertEqual(award_data, award)
  
      response = self.app.get("/tenders/{}/awards/some_id".format(self.tender_id), status=404)
      self.assertEqual(response.status, "404 Not Found")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(
          response.json["errors"], [{u"description": u"Not Found", u"location": u"url", u"name": u"award_id"}]
      )
  
      response = self.app.get("/tenders/some_id/awards/some_id", status=404)
      self.assertEqual(response.status, "404 Not Found")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["status"], "error")
      self.assertEqual(
          response.json["errors"], [{u"description": u"Not Found", u"location": u"url", u"name": u"tender_id"}]
      )
  
  
  def patch_tender_award_Administrator_change(self):
      self.app.authorization = ("Basic", ("token", ""))
      response = self.app.post_json(
          "/tenders/{}/awards".format(self.tender_id),
          {"data": {"suppliers": [test_tenderer], "status": "pending", "bid_id": self.bids[0]["id"]}},
      )
      self.assertEqual(response.status, "201 Created")
      self.assertEqual(response.content_type, "application/json")
      award = response.json["data"]
      complaintPeriod = award["complaintPeriod"][u"startDate"]
  
      self.app.authorization = ("Basic", ("administrator", ""))
      response = self.app.patch_json(
          "/tenders/{}/awards/{}".format(self.tender_id, award["id"]),
          {"data": {"complaintPeriod": {"endDate": award["complaintPeriod"][u"startDate"]}}},
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      self.assertIn("endDate", response.json["data"]["complaintPeriod"])
      self.assertEqual(response.json["data"]["complaintPeriod"]["endDate"], complaintPeriod)
  
  
  # TenderStage2UAAwardComplaintDocumentResourceTest
  
  
  def patch_tender_award_complaint_document(self):
      response = self.app.post(
          "/tenders/{}/awards/{}/complaints/{}/documents?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, self.complaint_owner_token
          ),
          upload_files=[("file", "name.doc", "content")],
      )
      self.assertEqual(response.status, "201 Created")
      self.assertEqual(response.content_type, "application/json")
      doc_id = response.json["data"]["id"]
      self.assertIn(doc_id, response.headers["Location"])
  
      response = self.app.patch_json(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, self.tender_token
          ),
          {"data": {"description": "document description"}},
          status=403,
      )
      self.assertEqual(response.status, "403 Forbidden")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(response.json["errors"][0]["description"], "Can update document only author")
  
      response = self.app.patch_json(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, self.complaint_owner_token
          ),
          {"data": {"description": "document description"}},
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(doc_id, response.json["data"]["id"])
  
      response = self.app.get(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id
          )
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(doc_id, response.json["data"]["id"])
      self.assertEqual("document description", response.json["data"]["description"])
  
      response = self.app.patch_json(
          "/tenders/{}/awards/{}/complaints/{}?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, self.complaint_owner_token
          ),
          {"data": {"status": "pending"}},
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.json["data"]["status"], "pending")
  
      response = self.app.put(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, self.complaint_owner_token
          ),
          "content2",
          content_type="application/msword",
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/json")
      key = response.json["data"]["url"].split("?")[-1]
  
      response = self.app.get(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?{}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, key
          )
      )
      self.assertEqual(response.status, "200 OK")
      self.assertEqual(response.content_type, "application/msword")
      self.assertEqual(response.content_length, 8)
      self.assertEqual(response.body, "content2")
  
      self.set_status("complete")
  
      response = self.app.patch_json(
          "/tenders/{}/awards/{}/complaints/{}/documents/{}?acc_token={}".format(
              self.tender_id, self.award_id, self.complaint_id, doc_id, self.complaint_owner_token
          ),
          {"data": {"description": "document description"}},
          status=403,
      )
      self.assertEqual(response.status, "403 Forbidden")
      self.assertEqual(response.content_type, "application/json")
      self.assertEqual(
          response.json["errors"][0]["description"], "Can't update document in current (complete) tender status"
      )
  