Example #1
0
def send_voters_handler(newemail, seen_email_data, unused_voters,
                        gmail_client):
    # get message from secret (apart from the voters)
    # get voters
    # combine
    # send to newemail.sender using gmail_handling
    # add voters to newemail.sender's entry (and create entry if necessary)
    # change/leave entry['active'] to 'y'
    # delete voters
    intro_message = config.BOT_MESSAGES['MESSAGE_WHEN_SENDING_VOTERS']
    voters_to_add = data_handling.get_voters(unused_voters,
                                             config.NUMBER_OF_VOTERS_TO_SEND)
    pretty_voters = utils.pretty_format_voters(voters_to_add)
    message = intro_message + "\n\n" + pretty_voters
    gmail_handling.send_email(gmail_client, newemail.sender, message)
    seen_email_data = data_handling.update_for_sent_voters(
        newemail.sender, voters_to_add, seen_email_data)
    seen_email_data = data_handling.mark_existing_entry_active(
        newemail.sender, seen_email_data)
    data_handling.delete_voters(unused_voters, voters_to_add)
    print("replied to {0} with voters".format(newemail.sender))
    return seen_email_data, unused_voters
Example #2
0
	def test_basic_new_entry(self):
		sender = '*****@*****.**'
		some_voters = ['1','2','3']
		found = data_handling.update_for_sent_voters(sender, some_voters, self.seen_data)[sender]
		expected =  {'sender':'*****@*****.**', 'voters':['1','2','3']}
		self.assertEqual(found, expected)
Example #3
0
	def test_seen_data_is_type_list(self):
		with self.assertRaises(AssertionError):
			data_handling.update_for_sent_voters('a', ['a'], [self.seen_data])
Example #4
0
	def test_voters_is_type_str(self):
		with self.assertRaises(AssertionError):
			data_handling.update_for_sent_voters('a', 'new voter', self.seen_data)
Example #5
0
	def test_sender_is_type_int(self):
		with self.assertRaises(AssertionError):
			data_handling.update_for_sent_voters(1, ['a'], self.seen_data)
Example #6
0
	def test_basic_update_existing_entry(self):
		sender = '*****@*****.**'
		some_voters = ['1','2','3']
		found = data_handling.update_for_sent_voters(sender, some_voters, self.seen_data)
		expected = {'*****@*****.**':{'sender':'*****@*****.**','voters':['a','b','c','1','2','3']}}
		self.assertEqual(found, expected)