# -*- coding: utf-8 -*-
import unittest

from openprocurement.api.tests.base import snitch

from openprocurement.tender.openeu.tests.base import test_lots
from openprocurement.tender.openeu.tests.base import (
    BaseTenderContentWebTest,
    test_bids,
)
from openprocurement.tender.belowthreshold.tests.complaint_blanks import (
    # TenderComplaintDocumentResourceTest
    not_found,
    create_tender_complaint_document,
    create_tender_complaint_invalid,
    get_tender_complaint,
    get_tender_complaints,
)
from openprocurement.tender.openeu.tests.complaint_blanks import (
    # TenderComplaintDocumentResourceTest
    put_tender_complaint_document,
)
from openprocurement.tender.openua.tests.complaint_blanks import (
    # TenderComplaintResourceTest
    review_tender_complaint,
    create_tender_complaint,
    patch_tender_complaint,
    # TenderComplaintDocumentResourceTest
    patch_tender_complaint_document,
    # TenderLotAwardComplaintResourceTest
    create_tender_lot_award_complaint,
)


class TenderComplaintResourceTest(BaseTenderContentWebTest):
    initial_auth = ('Basic', ('broker', ''))

    test_create_tender_complaint_invalid = snitch(create_tender_complaint_invalid)
    test_create_tender_complaint = snitch(create_tender_complaint)
    test_patch_tender_complaint = snitch(patch_tender_complaint)
    test_review_tender_complaint = snitch(review_tender_complaint)
    test_get_tender_complaint = snitch(get_tender_complaint)
    test_get_tender_complaints = snitch(get_tender_complaints)


class TenderLotAwardComplaintResourceTest(BaseTenderContentWebTest):
    initial_lots = test_lots
    author = test_bids[0]["tenderers"][0]
    initial_auth = ('Basic', ('broker', ''))

    test_create_tender_complaint = snitch(create_tender_lot_award_complaint)


class TenderComplaintDocumentResourceTest(BaseTenderContentWebTest):

    author = test_bids[0]["tenderers"][0]
    initial_auth = ('Basic', ('broker', ''))

    def setUp(self):
        super(TenderComplaintDocumentResourceTest, self).setUp()
        # Create complaint
        response = self.app.post_json('/tenders/{}/complaints'.format(
            self.tender_id), {'data': {'title': 'complaint title',
                                       'description': 'complaint description',
                                       'author': self.author
                                       }})
        complaint = response.json['data']
        self.complaint_id = complaint['id']
        self.complaint_owner_token = response.json['access']['token']

    test_not_found = snitch(not_found)
    test_create_tender_complaint_document = snitch(create_tender_complaint_document)
    test_put_tender_complaint_document = snitch(put_tender_complaint_document)
    test_patch_tender_complaint_document = snitch(patch_tender_complaint_document)


def suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TenderComplaintDocumentResourceTest))
    suite.addTest(unittest.makeSuite(TenderComplaintResourceTest))
    return suite


if __name__ == '__main__':
    unittest.main(defaultTest='suite')

@@ -117,144 +117,78 @@
 der.
-openeu.tests.base import test_lots%0Afrom openprocurement.tender.openeu.tests.base import (%0A    BaseTenderContentWebTest,%0A    test_bids,%0A)
+belowthreshold.tests.complaint import TenderComplaintResourceTestMixin
 %0Afro
@@ -358,95 +358,86 @@
 nt,%0A
-    create_tender_complaint_invalid,%0A    get_tender_complaint,%0A    get_t
+)%0A%0Afrom openprocurement.tender.openua.tests.complaint import T
 ender
-_c
+UAC
 omplaint
 s,%0A)
@@ -436,12 +436,25 @@
 aint
-s,%0A)
+ResourceTestMixin
 %0Afro
@@ -486,10 +486,10 @@
 open
-e
 u
+a
 .tes
@@ -564,18 +564,20 @@
 st%0A    p
-ut
+atch
 _tender_
@@ -600,77 +600,8 @@
 nt,%0A
-)%0Afrom openprocurement.tender.openua.tests.complaint_blanks import (%0A
     
@@ -600,32 +600,40 @@
 nt,%0A    # Tender
+LotAward
 ComplaintResourc
@@ -642,30 +642,30 @@
 est%0A    
+c
 re
-view
+ate
 _tender_
 complain
@@ -648,32 +648,42 @@
   create_tender_
+lot_award_
 complaint,%0A    c
@@ -681,64 +681,77 @@
 nt,%0A
-    create_tender_complaint,%0A    patch_tender_complaint,
+)%0A%0Afrom openprocurement.tender.openeu.tests.complaint_blanks import (
 %0A   
@@ -786,36 +786,34 @@
 sourceTest%0A    p
-atch
+ut
 _tender_complain
@@ -828,87 +828,123 @@
 nt,%0A
-    # TenderLotAwardComplaintResource
+)%0Afrom openprocurement.tender.openeu.tests.base import (%0A    BaseTenderContentWeb
 Test
+,
 %0A    
-create_tender_lot_award_complaint
+test_bids,%0A    test_lots
 ,%0A)%0A
@@ -1007,89 +1007,59 @@
 Test
-):
+,
 %0A    
-initial_auth = ('Basic', ('broker', ''))%0A%0A    test_create_t
+                              T
 ender
-_c
+C
 omplaint
 _inv
@@ -1058,287 +1058,78 @@
 aint
-_invalid = snitch(create_tender_complaint_invalid)%0A    test_create_tender_complaint = snitch(create_tender_complaint)%0A    test_patch_tender_complaint = snitch(patch_tender_complaint)%0A    test_review_tender_complaint = snitch(review_tender_complaint)%0A    test_get_t
+ResourceTestMixin,%0A                                  T
 ender
-_c
+UAC
 omplaint
  = s
@@ -1128,101 +1128,71 @@
 aint
- = snitch(get_tender_complaint)%0A    test_get_tender_complaints = snitch(get_tender_complaints
+ResourceTestMixin):%0A    initial_auth = ('Basic', ('broker', '')
 )%0A%0A%0A

create basic abstract classes for complaint module