Esempio n. 1
0
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)
Esempio n. 2
0
def init_app(request):
    if request.method == 'GET':
        User.create_admin('admin', 'aos').put()
        Room.init_rooms()
        if not Talk.all().count(1) > 0:
            talk = Talk(title = 'Android', session=1)
            talk.set_room(Room.get_rooms()[0])
            talk.put()
            talk = Talk(title = 'Kanban', session=5)
            talk.set_room(Room.get_rooms()[1])
            talk.put()
        if not Attendant.all().count(1) > 0:
            bill = Attendant.create('Bill', 'Gates', '*****@*****.**', 'Zaragoza', False)
            bill.twitter_id = 'fbgblog'
            bill.set_as_speaker()
            bill.put()
            richard = Attendant.create('Richard', 'Stallman', '*****@*****.**', 'Pamplona', True)
            richard.twitter_id = 'GNUplusLINUX'
            richard.set_as_speaker()
            richard.put()
        return HttpResponse("App ready to rumble...", mimetype="text/plain")
Esempio n. 3
0
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())