Skip to content

Commit

Permalink
refactor: Change a few test case function signatures to be more pythonic
Browse files Browse the repository at this point in the history
  • Loading branch information
pselkirk committed Jun 20, 2023
1 parent 051c87c commit 8519a35
Showing 1 changed file with 23 additions and 35 deletions.
58 changes: 23 additions & 35 deletions ietf/nomcom/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,20 +688,16 @@ def test_public_nominate_with_automatic_questionnaire(self):
self.assertIn('nominee@', outbox[1]['To'])


def nominate_view(self, *args, **kwargs):
public = kwargs.pop('public', True)
searched_email = kwargs.pop('searched_email', None)
nominee_email = kwargs.pop('nominee_email', '[email protected]')
def nominate_view(self, public=True, searched_email=None,
nominee_email='[email protected]',
nominator_email=COMMUNITY_USER+EMAIL_DOMAIN,
position='IAOC', confirmation=False):

if not searched_email:
searched_email = Email.objects.filter(address=nominee_email).first()
if not searched_email:
searched_email = EmailFactory(address=nominee_email, primary=True, origin='test')
searched_email = Email.objects.filter(address=nominee_email).first() or EmailFactory(address=nominee_email, primary=True, origin='test')
if not searched_email.person:
searched_email.person = PersonFactory()
searched_email.save()
nominator_email = kwargs.pop('nominator_email', "%s%s" % (COMMUNITY_USER, EMAIL_DOMAIN))
position_name = kwargs.pop('position', 'IAOC')
confirmation = kwargs.pop('confirmation', False)

if public:
nominate_url = self.public_nominate_url
Expand All @@ -725,7 +721,7 @@ def nominate_view(self, *args, **kwargs):
q = PyQuery(response.content)
self.assertEqual(len(q("#nominate-form")), 1)

position = Position.objects.get(name=position_name)
position = Position.objects.get(name=position)
comment_text = 'Test nominate view. Comments with accents äöåÄÖÅ éáíóú âêîôû ü àèìòù.'
candidate_phone = '123456'

Expand Down Expand Up @@ -763,12 +759,9 @@ def nominate_view(self, *args, **kwargs):
comments=feedback,
nominator_email="%s%s" % (COMMUNITY_USER, EMAIL_DOMAIN))

def nominate_newperson_view(self, *args, **kwargs):
public = kwargs.pop('public', True)
nominee_email = kwargs.pop('nominee_email', '[email protected]')
nominator_email = kwargs.pop('nominator_email', "%s%s" % (COMMUNITY_USER, EMAIL_DOMAIN))
position_name = kwargs.pop('position', 'IAOC')
confirmation = kwargs.pop('confirmation', False)
def nominate_newperson_view(self, public=True, nominee_email='[email protected]',
nominator_email=COMMUNITY_USER+EMAIL_DOMAIN,
position='IAOC', confirmation=False):

if public:
nominate_url = self.public_nominate_newperson_url
Expand All @@ -792,7 +785,7 @@ def nominate_newperson_view(self, *args, **kwargs):
q = PyQuery(response.content)
self.assertEqual(len(q("#nominate-form")), 1)

position = Position.objects.get(name=position_name)
position = Position.objects.get(name=position)
candidate_email = nominee_email
candidate_name = 'nominee'
comment_text = 'Test nominate view. Comments with accents äöåÄÖÅ éáíóú âêîôû ü àèìòù.'
Expand Down Expand Up @@ -847,15 +840,13 @@ def test_add_questionnaire(self):
return self.add_questionnaire()
self.client.logout()

def add_questionnaire(self, *args, **kwargs):
public = kwargs.pop('public', False)
nominee_email = kwargs.pop('nominee_email', '[email protected]')
nominator_email = kwargs.pop('nominator_email', "%s%s" % (COMMUNITY_USER, EMAIL_DOMAIN))
position_name = kwargs.pop('position', 'IAOC')
def add_questionnaire(self, public=False, nominee_email='[email protected]',
nominator_email=COMMUNITY_USER+EMAIL_DOMAIN,
position='IAOC'):

self.nominate_view(public=public,
nominee_email=nominee_email,
position=position_name,
position=position,
nominator_email=nominator_email)

response = self.client.get(self.add_questionnaire_url)
Expand All @@ -874,7 +865,7 @@ def add_questionnaire(self, *args, **kwargs):
self.assertEqual(response.status_code, 200)
self.assertContains(response, "questionnnaireform")

position = Position.objects.get(name=position_name)
position = Position.objects.get(name=position)
nominee = Nominee.objects.get(email__address=nominee_email)

comment_text = 'Test add questionnaire view. Comments with accents äöåÄÖÅ éáíóú âêîôû ü àèìòù.'
Expand Down Expand Up @@ -922,16 +913,13 @@ def test_private_feedback(self):
self.access_member_url(self.private_feedback_url)
return self.feedback_view(public=False)

def feedback_view(self, *args, **kwargs):
public = kwargs.pop('public', True)
nominee_email = kwargs.pop('nominee_email', '[email protected]')
nominator_email = kwargs.pop('nominator_email', "%s%s" % (COMMUNITY_USER, EMAIL_DOMAIN))
position_name = kwargs.pop('position', 'IAOC')
confirmation = kwargs.pop('confirmation', False)
def feedback_view(self, public=True, nominee_email='[email protected]',
nominator_email=COMMUNITY_USER+EMAIL_DOMAIN,
position='IAOC', confirmation=False):

self.nominate_view(public=public,
nominee_email=nominee_email,
position=position_name,
position=position,
nominator_email=nominator_email)

feedback_url = self.public_feedback_url
Expand All @@ -954,7 +942,7 @@ def feedback_view(self, *args, **kwargs):
self.assertEqual(response.status_code, 200)
self.assertNotContains(response, "feedbackform")

position = Position.objects.get(name=position_name)
position = Position.objects.get(name=position)
nominee = Nominee.objects.get(email__address=nominee_email)

feedback_url += "?nominee=%d&position=%d" % (nominee.id, position.id)
Expand All @@ -970,7 +958,7 @@ def feedback_view(self, *args, **kwargs):
comments = 'Test feedback view. Comments with accents äöåÄÖÅ éáíóú âêîôû ü àèìòù.'

test_data = {'comment_text': comments,
'position_name': position.name,
'position': position.name,
'nominee_name': nominee.email.person.name,
'nominee_email': nominee.email.address,
'confirmation': confirmation}
Expand Down Expand Up @@ -2131,7 +2119,7 @@ def test_public_accepting_feedback(self):
self.assertIn('not currently accepting feedback', unicontent(response))

test_data = {'comment_text': 'junk',
'position_name': pos.name,
'position': pos.name,
'nominee_name': pos.nominee_set.first().email.person.name,
'nominee_email': pos.nominee_set.first().email.address,
'confirmation': False,
Expand Down

0 comments on commit 8519a35

Please sign in to comment.