class TalksTestCase(unittest.TestCase, TestBedInitializer): def setUp(self): self.init_testbed_for_datastore_tests() self.init_django_settings() self.room1 = Room(key_name = 'sala1', name = "sala1") room_key1 = self.room1.put() room_key2 = Room(key_name = 'sala2', name = "sala2").put() Talk(title = 'Titulo1', schedule = '18:30', room = room_key1).put() Talk(title = 'Titulo2', schedule = '19:30', room = room_key1).put() Talk(title = 'Titulo3', schedule = '20:30', room = room_key2).put() #@authorize_web_access() def test_fetch_talks_from_room(self): room = Room.all().filter('name', 'sala1').get() self.assertEquals('Titulo1', room.talks[0].title) self.assertEquals('Titulo2', room.talks[1].title) def test_filter_by_talk_name(self): talk = self.room1.talks.filter('title', 'Titulo2').get() self.assertEquals('19:30', talk.schedule) def test_serialize_to_json(self): logging.error("AG: %s " % self.room1.to_json()) logging.error("AG: %s " % self.room1.talks[0].to_json())
def setUp(self): self.init_testbed_for_datastore_tests() self.init_django_settings() self.room1 = Room(key_name = 'sala1', name = "sala1") self.room2 = Room(key_name = 'sala2', name = "sala2") self.room1.put() self.room2.put() self.talk = Talk(title = 'Titulo1', room = self.room1, session=1)
def setUp(self): self.init_testbed_for_datastore_tests() self.init_django_settings() self.room1 = Room.create_room('1', 'sala1') room_key1 = self.room1.put() room_key2 = Room.create_room('2', 'sala2').put() Talk(title = 'Titulo1', session = 1, room = room_key1).put() Talk(title = 'Titulo2', session = 2, room = room_key1).put() Talk(title = 'Titulo3', session = 3, room = room_key2).put()
def setUp(self): self.init_testbed_for_datastore_tests() self.init_django_settings() self.room1 = Room(name="sala1") self.room2 = Room(name="sala2") room_key1 = self.room1.put() room_key2 = self.room2.put() self.attendant_key = Attendant.create("Ponente1", "Apellido1", "*****@*****.**", "Zaragoza", False).put() self.talk1 = Talk(title="Titulo1", speaker=self.attendant_key, room=room_key1, session=4) self.talk1.put() Talk(title="Titulo2", speaker=self.attendant_key, room=room_key2).put() Talk(title="Titulo3", speaker=self.attendant_key, room=room_key1).put() self.talk_key_4 = Talk(title="Titulo4", speaker=self.attendant_key).put()
class TimetableTestCase(unittest.TestCase, TestBedInitializer): def setUp(self): self.init_testbed_for_datastore_tests() self.init_django_settings() self.room1 = Room(key_name = 'sala1', name = "sala1") self.room2 = Room(key_name = 'sala2', name = "sala2") self.room1.put() self.room2.put() self.talk = Talk(title = 'Titulo1', room = self.room1, session=1) def test_empty_schedule_grid(self): grid = Timetable().get_grid() for session in Talk.get_talk_sessions(): for room in Room.get_rooms(): self.assertFalse(grid[session][room.name]) def test_schedule_grid_with_one_talk(self): self.talk.put() grid = Timetable().get_grid() self.assertEquals('Titulo1', grid[1]['sala1'].title) def test_add_talk_to_schedule_grid(self): timetable = Timetable() timetable.add_talk(self.talk) self.assertEquals('Titulo1', timetable.get_grid()[1]['sala1'].title) def test_get_rows_for_template(self): self.talk.room = self.room2 timetable = Timetable() timetable.add_talk(self.talk) number_of_sessions = len(Talk.get_talk_sessions()) self.assertEquals(number_of_sessions, len(timetable.get_rows_for_template())) for row in timetable.get_rows_for_template(): self.assertEquals(2, len(row.talks_by_room())) if row.session == 1: self.assertEquals(row.talks_by_room()[0], None) self.assertEquals(row.talks_by_room()[1], self.talk) def test_timetable_json(self): timetable = Timetable() timetable.add_talk(self.talk) self.talk.put() talk2 = Talk(title = 'Titulo2', room = self.room2, session=1).put() talks = timetable.get_talks() talks_json = timetable.get_talks_json() logging.error("AG: %s " % talks_json)
def setUp(self): self.init_testbed_for_datastore_tests() self.init_django_settings() self.room1 = Room(key_name = 'sala1', name = "sala1") room_key1 = self.room1.put() room_key2 = Room(key_name = 'sala2', name = "sala2").put() Talk(title = 'Titulo1', schedule = '18:30', room = room_key1).put() Talk(title = 'Titulo2', schedule = '19:30', room = room_key1).put() Talk(title = 'Titulo3', schedule = '20:30', room = room_key2).put()
def test_empty_schedule_grid(self): grid = Timetable().get_grid() for session in Talk.get_talk_sessions(): for room in Room.get_rooms(): self.assertFalse(grid[session][room.name])
def test_fetch_talks_from_room(self): room = Room.all().filter('name', 'sala1').get() self.assertEquals('Titulo1', room.talks[0].title) self.assertEquals('Titulo2', room.talks[1].title)
class TalksTestCase(unittest.TestCase, TestBedInitializer): def setUp(self): self.init_testbed_for_datastore_tests() self.init_django_settings() self.room1 = Room(name="sala1") self.room2 = Room(name="sala2") room_key1 = self.room1.put() room_key2 = self.room2.put() self.attendant_key = Attendant.create("Ponente1", "Apellido1", "*****@*****.**", "Zaragoza", False).put() self.talk1 = Talk(title="Titulo1", speaker=self.attendant_key, room=room_key1, session=4) self.talk1.put() Talk(title="Titulo2", speaker=self.attendant_key, room=room_key2).put() Talk(title="Titulo3", speaker=self.attendant_key, room=room_key1).put() self.talk_key_4 = Talk(title="Titulo4", speaker=self.attendant_key).put() def test_search_unexisting_attendant(self): attendant = Attendant.all().filter("name", "PonenteN").fetch(1000) self.assertFalse(attendant) def test_fetch_talks_from_attendant(self): attendant = Attendant.all().filter("first_name", "Ponente1").get() self.assertEquals("Titulo1", attendant.talks[0].title) self.assertEquals("Titulo2", attendant.talks[1].title) def test_create_talk(self): talk = Talk.create_talk("Titulo5", self.attendant_key) self.assertEquals("*****@*****.**", talk.speaker.email) def test_add_room_to_talk(self): talk = Talk.add_room_to_talk(self.talk_key_4.id(), self.room1.key()) self.assertEquals("sala1", talk.room.name) def test_get_talks_from_room(self): talks = Talk.get_talks_from_room(self.room1.key()) self.assertEqual("Titulo1Titulo3", talks[0].title + talks[1].title) def test_get_talks_during_hour(self): Talk.create_talk("Charla1", self.attendant_key, session=1).put() Talk.create_talk("Charla2", self.attendant_key, session=1).put() talks = Talk.get_talks_during_session(1) self.assertEquals("Charla1Charla2", talks[0].title + talks[1].title) def test_serialize_to_json(self): expected = { "room": {"name": u"sala1"}, "title": "Titulo1", "duration": 1, "session": 4, "speaker": { "city": u"Zaragoza", "first_name": u"Ponente1", "last_name": u"Apellido1", "twitter_id": u"", "computers_needed": False, "speaker": False, "email": u"*****@*****.**", }, "time": "13:00", "date": "2012-06-23", "description": "", } logging.error("Talk json: %s " % self.talk1.to_json()) self.assertEqual(expected, self.talk1.to_json())