Skip to content

Commit

Permalink
Merge pull request #86 from gorserg/fix_questions_of_second_stage
Browse files Browse the repository at this point in the history
Виправлення багу для запитань другого етапу
  • Loading branch information
kroman0 committed Oct 12, 2016
2 parents efe085e + 4d17f61 commit fbeaf9d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,42 @@ def test_create_tender_question_invalid(self):
self.assertEqual(response.json['errors'], [
{u'description': u'Author can\'t create question', u'location': u'body', u'name': u'author'}])

def test_create_tender_question_with_questionOf(self):
response = self.app.post_json('/tenders/{}/questions'.format(self.tender_id),
{'data': {'title': 'question title',
'description': 'question description',
'author': author,
'questionOf': 'tender',
'relatedItem': self.tender_id}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
question = response.json['data']
self.assertEqual(question['author']['name'], author['name'])
self.assertIn('id', question)
self.assertIn(question['id'], response.headers['Location'])

self.time_shift('enquiryPeriod_ends')

response = self.app.post_json('/tenders/{}/questions'.format(self.tender_id),
{'data': {'title': 'question title',
'description': 'question description',
'author': author}},
status=403)
self.assertEqual(response.status, '403 Forbidden')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['errors'][0]["description"], "Can add question only in enquiryPeriod")

self.time_shift('active.pre-qualification')
self.check_chronograph()
response = self.app.post_json('/tenders/{}/questions'.format(self.tender_id),
{'data': {'title': 'question title',
'description': 'question description',
'author': author}},
status=403)
self.assertEqual(response.status, '403 Forbidden')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['errors'][0]["description"], "Can add question only in enquiryPeriod")

def test_create_tender_question(self):
response = self.app.post_json('/tenders/{}/questions'.format(self.tender_id),
{'data': {'title': 'question title',
Expand Down Expand Up @@ -770,6 +806,42 @@ def test_create_tender_question_invalid(self):
self.assertEqual(response.json['errors'], [
{u'description': u'Author can\'t create question', u'location': u'body', u'name': u'author'}])

def test_create_tender_question_with_questionOf(self):
response = self.app.post_json('/tenders/{}/questions'.format(self.tender_id),
{'data': {'title': 'question title',
'description': 'question description',
'author': author,
'questionOf': 'tender',
'relatedItem': self.tender_id}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
question = response.json['data']
self.assertEqual(question['author']['name'], author['name'])
self.assertIn('id', question)
self.assertIn(question['id'], response.headers['Location'])

self.time_shift('enquiryPeriod_ends')

response = self.app.post_json('/tenders/{}/questions'.format(self.tender_id),
{'data': {'title': 'question title',
'description': 'question description',
'author': author}},
status=403)
self.assertEqual(response.status, '403 Forbidden')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['errors'][0]["description"], "Can add question only in enquiryPeriod")

self.time_shift('active.pre-qualification')
self.check_chronograph()
response = self.app.post_json('/tenders/{}/questions'.format(self.tender_id),
{'data': {'title': 'question title',
'description': 'question description',
'author': author}},
status=403)
self.assertEqual(response.status, '403 Forbidden')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['errors'][0]["description"], "Can add question only in enquiryPeriod")

def test_create_tender_question(self):
response = self.app.post_json('/tenders/{}/questions'.format(self.tender_id),
{'data': {'title': 'question title',
Expand Down
8 changes: 7 additions & 1 deletion openprocurement/tender/competitivedialogue/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,15 @@ def prepare_shortlistedFirms(shortlistedFirms):


def prepare_author(obj):
""" Make key
{author.identifier.id}_{author.identifier.scheme}
or
{author.identifier.id}_{author.identifier.scheme}_{lot.id}
if obj has relatedItem and questionOf != tender or obj has relatedLot than
"""
base_key = u"{id}_{scheme}".format(scheme=obj['author']['identifier']['scheme'],
id=obj['author']['identifier']['id'])
if obj.get('relatedLot') or obj.get('relatedItem'):
if obj.get('relatedLot') or (obj.get('relatedItem') and obj.get('questionOf') == 'lot'):
base_key = u"{base_key}_{lotId}".format(base_key=base_key,
lotId=obj.get('relatedLot') or obj.get('relatedItem'))
return base_key
Expand Down
6 changes: 4 additions & 2 deletions openprocurement/tender/competitivedialogue/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ def get_item_by_id(tender, id):


def validate_author(request, shortlistedFirms, obj):
""" Compare author key and key from shortlistedFirms """
error_message = 'Author can\'t {} {}'.format('create' if request.method == 'POST' else 'patch',
obj.__class__.__name__.lower())
firms_keys = prepare_shortlistedFirms(shortlistedFirms)
author_key = prepare_author(obj)
if obj.get('questionOf') == 'item':
if shortlistedFirms[0].get('lots'): # question can create on item
if obj.get('questionOf') == 'item': # question can create on item
if shortlistedFirms[0].get('lots'):
item_id = author_key.split('_')[-1]
item = get_item_by_id(request.validated['tender'], item_id)
author_key = author_key.replace(author_key.split('_')[-1], item['relatedLot'])
Expand All @@ -69,6 +70,7 @@ def validate_author(request, shortlistedFirms, obj):
return False
return True


def validate_complaint_data_stage2(request):
if not request.check_accreditation(request.tender.edit_accreditation):
request.errors.add('procurementMethodType', 'accreditation', 'Broker Accreditation level does not permit complaint creation')
Expand Down

0 comments on commit fbeaf9d

Please sign in to comment.