def test_count_all_speakers(self): self.assertEqual(cospeaker.count_all_speakers([]).total_number_of_speakers(), 0) t = talk.Talk(parent=self.spk1.key) t.title = "Talk talk" t.put() sub_key1 = submissionrecord.make_submission(t.key, self.c.key, "TrackB", "format") submissions = [sub_key1] self.assertEqual(cospeaker.count_all_speakers(submissions).total_number_of_speakers(), 1) t2 = talk.Talk(parent=self.spk1.key) t2.title = "More talk" t2.put() sub_key2 = submissionrecord.make_submission(t2.key, self.c.key, "TrackB", "format") submissions = [sub_key1, sub_key2] self.assertEqual(cospeaker.count_all_speakers(submissions).total_number_of_speakers(), 1) cospeak = cospeaker.make_cospeaker(sub_key2, "Harry", "*****@*****.**") self.assertEqual(cospeaker.count_all_speakers(submissions).total_number_of_speakers(), 2) cospeak = cospeaker.make_cospeaker(sub_key2, "Ron", "*****@*****.**") self.assertEqual(cospeaker.count_all_speakers(submissions).total_number_of_speakers(), 3) cospeak = cospeaker.make_cospeaker(sub_key1, "Ron", "*****@*****.**") self.assertEqual(cospeaker.count_all_speakers(submissions).total_number_of_speakers(), 3)
def test_filter_for_cospeakers(self): t = talk.Talk(parent=self.spk1.key) t.title = "Talk talk" t.put() sub_key1 = submissionrecord.make_submission(t.key, self.c.key, "TrackB", "format") t2 = talk.Talk(parent=self.spk1.key) t2.title = "More talk" t2.put() sub_key2 = submissionrecord.make_submission(t2.key, self.c.key, "TrackB", "format") cospeak = cospeaker.make_cospeaker(sub_key2, "Harry", "*****@*****.**") submissions = [ sub_key1, sub_key2 ] sub_speakers_map = cospeaker.filter_for_cospeakers(submissions) self.assertFalse(sub_speakers_map.has_key(sub_key1)) self.assertTrue(sub_speakers_map.has_key(sub_key2)) self.assertEqual(sub_speakers_map[sub_key2][0].name, "Harry") cospeak = cospeaker.make_cospeaker(sub_key2, "Ron", "*****@*****.**") sub_speakers_map = cospeaker.filter_for_cospeakers(submissions) self.assertFalse(sub_speakers_map.has_key(sub_key1)) self.assertTrue(sub_speakers_map.has_key(sub_key2)) cospeakers = sub_speakers_map[sub_key2] cospeakers.sort(key=lambda speaker: speaker.name) self.assertEqual(sub_speakers_map[sub_key2][0].name, "Harry") self.assertEqual(sub_speakers_map[sub_key2][1].name, "Ron")
def mk_test_data(self, name): new_conf = conference.Conference() new_conf.name = name new_conf.put() subm_key = submissionrecord.make_submission(None, new_conf.key, "Track", "Format") confoptions.make_conference_track(new_conf.key, "Track") voterecord.cast_new_vote(subm_key, "Harry", 2, "No comment", 1) cospeaker.make_cospeaker(subm_key, "Ron", "ron2hogwarts.com") return new_conf.key, subm_key
def test_export_submission(self): c = conference.Conference() c.name = "TestConf" c.put() track1 = confoptions.make_conference_track(c.key, "track") format1 = confoptions.make_conference_option(confoptions.TalkFormatOption, c.key, "lecture") duration1 = confoptions.make_conference_option(confoptions.DurationOption, c.key, "10mins") expenses1 = confoptions.make_conference_option(confoptions.ExpenseOptions, c.key, "Long haul") s = speaker.make_new_speaker("*****@*****.**") s.name = 'Arnold "J" Rimmer' s.telephone = "051 652 0538" s.address = "Cabin 42, Deck 3, Red Dwarf" s.set_field("affiliation", "Mining Corp") s.set_field("twitter", "@arnold") s.bio = "Arnold 'J' Rimmer joined Mining Corp (Space Division) at, what now seems, a very young age." s.put() t = talk.Talk(parent=s.key) t.title = "A testing talk" t.set_field(talk.SHORT_SYNOPSIS, "A few words about the tests you need") t.set_field(talk.LONG_SYNOPSIS, "Many more words about testing.... 1, 2, 3") t.put() sub_key = submissionrecord.make_submission_plus(t.key, c.key, track1.shortname(), format1.shortname(), duration1.shortname(), expenses1.shortname()) cospeak = cospeaker.make_cospeaker(sub_key, "Harry Potter", "*****@*****.**") output = MockOutStream() exportcsv.write_sub(output, sub_key.get()) self.assertEquals(output.sequence[0], 'No decision, ') self.assertEquals(output.sequence[1], "Arnold 'J' Rimmer, ") self.assertEquals(output.sequence[2], '[email protected], ') self.assertEquals(output.sequence[3], '051 652 0538, ') self.assertEquals(output.sequence[4], '"Cabin 42, Deck 3, Red Dwarf", ') self.assertEquals(output.sequence[5], 'Harry Potter, ') self.assertEquals(output.sequence[6], ', ') self.assertEquals(output.sequence[7], 'Mining Corp, ') self.assertEquals(output.sequence[8], '@arnold, ') self.assertEquals(output.sequence[9], """"Arnold 'J' Rimmer joined Mining Corp (Space Division) at, what now seems, a very young age.", """) self.assertEquals(output.sequence[10], 'None, ') self.assertEquals(output.sequence[11], 'A testing talk, ') self.assertEquals(output.sequence[12], "A few words about the tests you need, ") self.assertEquals(output.sequence[13], '"Many more words about testing.... 1, 2, 3", ') self.assertEquals(output.sequence[14], 'track, ') self.assertEquals(output.sequence[15], 'lecture, ') self.assertEquals(output.sequence[16], '10mins, ') self.assertEquals(output.sequence[17], 'Long haul, ') self.assertEquals(output.number_of_writes(), 18)
def test_listed_cospeaker(self): self.assertFalse(cospeaker.is_listed_cospeaker("*****@*****.**")) t = talk.Talk(parent=self.spk1.key) t.title = "Talk talk" t.put() sub_key1 = submissionrecord.make_submission(t.key, self.c.key, "TrackB", "format") cospeak = cospeaker.make_cospeaker(sub_key1, "Harry", "*****@*****.**") self.assertFalse(speaker.speaker_exists("*****@*****.**")) self.assertFalse(cospeaker.is_listed_cospeaker("*****@*****.**"))
def test_get_co_speaker_text(self): speakers = cospeaker.count_all_speakers([]) self.assertEqual(speakers.total_number_of_speakers(), 0) self.assertFalse(speakers.has_speaker("*****@*****.**")) self.assertFalse(speakers.has_speaker("*****@*****.**")) self.assertFalse(speakers.has_speaker("who@email")) t = talk.Talk(parent=self.spk1.key) t.title = "Talk talk" t.put() sub_key1 = submissionrecord.make_submission(t.key, self.c.key, "TrackB", "format") self.assertEquals("", cospeaker.get_pretty_list(sub_key1)) submissions = [sub_key1] self.assertEqual(cospeaker.count_all_speakers(submissions).total_number_of_speakers(), 1) cospeak = cospeaker.make_cospeaker(sub_key1, "Harry", "*****@*****.**") self.assertEqual(cospeaker.count_all_speakers(submissions).total_number_of_speakers(), 2) self.assertEquals("Harry ([email protected])", cospeaker.get_pretty_list(sub_key1)) cospeak = cospeaker.make_cospeaker(sub_key1, u"Ron\xc1", "*****@*****.**") self.assertEqual(cospeaker.count_all_speakers(submissions).total_number_of_speakers(), 3) self.assertEquals(u"Harry ([email protected]), Ron\xc1 ([email protected])", cospeaker.get_pretty_list(sub_key1)) speakers = cospeaker.count_all_speakers(submissions) self.assertTrue(speakers.has_speaker("*****@*****.**")) self.assertEquals("Harry", speakers.name("*****@*****.**")) self.assertTrue(speakers.has_speaker("*****@*****.**")) self.assertEquals(u"Ron\xc1", speakers.name("*****@*****.**")) self.assertFalse(speakers.has_speaker("*****@*****.**")) self.assertEquals(self.spk1.key, speakers.speaker_key("who@email")) self.assertEquals(None, speakers.speaker_key("*****@*****.**")) self.assertEquals(None, speakers.speaker_key("*****@*****.**"))
def test_ctor(self): t = talk.Talk(parent=self.spk1.key) t.title = "Talk talk" t.put() sub_key1 = submissionrecord.make_submission(t.key, self.c.key, "TrackB", "format") cospeak = cospeaker.make_cospeaker(sub_key1, "Harry", "*****@*****.**") self.assertFalse(speaker.speaker_exists("*****@*****.**")) self.assertEquals(cospeak.name, "Harry") self.assertFalse(speaker.speaker_exists("*****@*****.**")) self.assertEquals(cospeak.email, "*****@*****.**") self.assertFalse(speaker.speaker_exists("*****@*****.**")) self.assertEquals(cospeak.profile().bio, "No bio supplied") self.assertFalse(speaker.speaker_exists("*****@*****.**")) self.assertFalse(cospeak.profile_exists()) spk2 = speaker.make_new_speaker("*****@*****.**") spk2.name="Harry" spk2.bio="The child who lived" spk2.put() # add a speaker profile on that email address self.assertTrue(cospeak.profile_exists()) self.assertEquals(cospeak.profile().bio, "The child who lived")
def test_excel_export_with_data(self, mock_storage_open, mock_sheet_write): sub_report_key = customexport.mk_report(self.conf.key, "AllTheFieldsReport") sub_report = sub_report_key.get() self.assertEquals([], sub_report.submission_options()) sub_report.add_submission_options([ "created", "grdp_agreed", "track", "duration", "decision1", "decision2", "format", "withdrawn", "speaker_comms", "expenses", "title", "short_synopsis", "long_synopsis", "email", "first_name", "last_name", "picture", "blog", "cospeakers", "address" ]) # add some detail to conference to check mappings track_option = confoptions.make_conference_track( self.conf.key, "New Track") time_option = confoptions.make_conference_option( confoptions.DurationOption, self.conf.key, "30 minutes") format_option = confoptions.make_conference_option( confoptions.TalkFormatOption, self.conf.key, "Lecture") expenses_option = confoptions.make_conference_option( confoptions.ExpenseOptions, self.conf.key, "Longhaul") spk_key = speaker.make_and_store_new_speaker("*****@*****.**") spk = spk_key.get() spk.set_first_name("Harry") spk.set_later_names("J Potter") spk.set_field(speaker.Speaker.FIELD_BLOG, "www.myblog.com") zurich = "Z\xc3\xbcric" spk.set_field(speaker.Speaker.FIELD_ADDRESS, zurich) spk.put() t1 = talk.Talk(parent=spk_key) t1.title = "Talk T1" t1.set_field("shortsynopsis", "Very short synopsis") t1.set_field("longsynopsis", "A much much longer synopsis that goes on and on") t1.put() sub = submissionrecord.make_submission_plus( t1.key, self.conf.key, track_option.shortname(), format_option.shortname(), time_option.shortname(), expenses_option.shortname()).get() sub.set_review_decision(1, "Shortlist") sub.set_review_decision(2, "Decline") cospeaker.make_cospeaker(sub.key, "Ron Weesley", "*****@*****.**") cospeaker.make_cospeaker(sub.key, "H Granger", "*****@*****.**") sub_report.export_submissions_to_excel([sub.key]) self.assertEquals(40, mock_sheet_write.call_count) # test header row call_cnt = 0 header_row = 0 # cell A1 (1,1) contains "created" self.assertEquals((header_row, 0, "Date and time created"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 1, "Agreed GDPR policy"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 2, "Track"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 3, "Length"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 4, "Decision round 1"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 5, "Decision round 2"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 6, "Format"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 7, "Withdrawn"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 8, "Communication"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 9, "Expenses"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 10, "Talk title"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 11, "Short synopsis"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 12, "Long synopsis"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 13, "Email"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 14, "First name"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 15, "Later names"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 16, "Picture"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 17, "Blog"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 18, "Co-speakers"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((header_row, 19, "Address"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 # test data rows data_row1 = 1 # worksheet entry for Created (cell 2,1) - excel is zero based so A1 is 0,0 self.assertEquals((data_row1, 0), mock_sheet_write.mock_calls[call_cnt][1][1:3]) # datetime.now hasn't been stubbed so just test it is not empty self.assertIsNot(0, len(mock_sheet_write.mock_calls[call_cnt][1][3])) call_cnt += 1 # worksheet entry for GDPR (cell 2,2) self.assertEquals((data_row1, 1, "False"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 2, "New Track"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 3, "30 minutes"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 4, "Shortlist"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 5, "Decline"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 6, "Lecture"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 7, "False"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 8, submissionnotifynames.SUBMISSION_NEW), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 9, "Longhaul"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 10, "Talk T1"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 11, "Very short synopsis"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals( (data_row1, 12, "A much much longer synopsis that goes on and on"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 13, "*****@*****.**"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 14, "Harry"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 15, "J Potter"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 # odd return on local but server address makes sense when live self.assertEquals( (data_row1, 16, "https:///sorry_page?reason=NoImage"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 17, "www.myblog.com"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals(( data_row1, 18, "Ron Weesley ([email protected]), H Granger ([email protected])"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1 self.assertEquals((data_row1, 19, "Z\xc3\xbcric"), mock_sheet_write.mock_calls[call_cnt][1][1:]) call_cnt += 1