예제 #1
0
    def test_track_is_completed_correctly(self):
        track = Track(datetime.now())
        talk = Talk("first talk", 3 * 60)
        track.schedule_talk(talk)

        talk2 = Talk("Talk 2", 4 * 60)
        track.schedule_talk(talk2)

        assert track.is_full() is True
예제 #2
0
    def test_added_a_talk_that_exceed_the_lunch_and_raises_exception(self):
        track = Track(datetime.now())
        talk = Talk("Big KeyNote", 170)
        track.schedule_talk(talk)

        talk2 = Talk("Average Talk", 30)

        with pytest.raises(NoEnoughtSpace):
            track.schedule_talk(talk2)
예제 #3
0
    def test_track_is_not_valid(self):
        track = Track(datetime.now())
        talk = Talk("first talk", 3 * 60)
        track.schedule_talk(talk)

        talk2 = Talk("Talk 2", 2 * 60)
        track.schedule_talk(talk2)

        assert track.is_full() is False
예제 #4
0
    def test_track_is_completed_correctly_when_network_starts_at_16h(self):
        track = Track(datetime.now())
        talk = Talk("first talk", 3 * 60)
        track.schedule_talk(talk)

        talk2 = Talk("Talk 2", 3 * 60)
        track.schedule_talk(talk2)

        assert track.is_full() is True
예제 #5
0
    def test_that_i_cant_add_a_talk_when_track_is_full(self):
        track = Track(datetime.now())
        talk = Talk("Really Large Talk", 3 * 60)
        track.schedule_talk(talk)
        talk2 = Talk("Really Large Talk", 4 * 60)
        track.schedule_talk(talk2)

        talk3 = Talk("bostona veia", 30)

        with pytest.raises(NoEnoughtSpace):
            track.schedule_talk(talk3)
예제 #6
0
    def test_lunch_and_network_exists_in_track(self):
        track = Track(datetime.now())
        talk1 = Talk("Fedoka", 3 * 60)
        talk2 = Talk("Tutu de Feijão", 4 * 60)

        track.schedule_talk(talk1)
        track.schedule_talk(talk2)

        timeline_titles = [talk.title for talk in track.get_timeline()]

        assert 'Network' in timeline_titles
        assert 'Lunch' in timeline_titles
예제 #7
0
    def test_that_the_talk_date_is_based_on_previous_talk(self):
        track = Track(datetime.now())
        talk = Talk("qualquer bosta denovo", 30)
        track.schedule_talk(talk)

        talk2 = Talk("bostona veia", 30)
        track.schedule_talk(talk2)
        scheduled = track.get_timeline()[1]

        assert scheduled.title == talk2.title
        assert scheduled.duration == talk2.duration
        assert scheduled.date.hour == 9
        assert scheduled.date.minute == 30
        assert scheduled.date.second == 0
        assert scheduled.date.microsecond == 0
예제 #8
0
    def test_that_i_reeschedule_a_talk_when_is_the_lunch_hour(self):
        track = Track(datetime.now())
        talk = Talk("Talk 1", 3 * 60)
        track.schedule_talk(talk)

        talk2 = Talk("Talk on the lunch hour", 30)

        track.schedule_talk(talk2)
        scheduled = track.get_timeline()[2]

        assert scheduled.title == talk2.title
        assert scheduled.duration == talk2.duration
        assert scheduled.date.hour == 13
        assert scheduled.date.minute == 0
        assert scheduled.date.second == 0
        assert scheduled.date.microsecond == 0
예제 #9
0
    def test_insertion_talk(self):
        talk = Talk("Luna", 60)
        repo = TalksRepository()

        id_talk = repo.insert(talk)

        assert id_talk == 0
예제 #10
0
    def test_when_need_to_create_a_new_track_with_unordered_talks(self):
        talks = [Talk('Madokita', 4 * 60),
                 Talk('Tutucão', 3 * 60),
                 Talk('Luna', 3 * 60),
                 Talk('Pinkudao', 3 * 60)]

        tracks = TrackManagement(talks)
        tracks = tracks.generate_tracks_to_talks()

        talk_titles = self.__get_title_talks(tracks)

        assert talks[0].title in talk_titles[0] or talks[0].title in talk_titles[1]
        assert talks[1].title in talk_titles[0] or talks[1].title in talk_titles[1]
        assert talks[2].title in talk_titles[0] or talks[2].title in talk_titles[1]
        assert talks[3].title in talk_titles[0] or talks[3].title in talk_titles[1]
        assert 'Network' in talk_titles[0] and 'Network' in talk_titles[1]
        assert 'Lunch' in talk_titles[0] and 'Lunch' in talk_titles[1]
예제 #11
0
def talks():
    title = request.form['title']
    duration = request.form.get('duration', type=int)
    app.talk = Talk(title, duration)
    talk_id = app.talks_repository.insert(app.talk)
    talk = app.talks_repository.get(talk_id)
    return jsonify({'id': talk_id, 'title': talk.title, 'duration':
                    talk.duration})
예제 #12
0
    def test_get_talk_by_id(self):
        talk = Talk("Biancat", 30)
        repo = TalksRepository()

        id_talk = repo.insert(talk)

        assert repo.get(id_talk).title == talk.title
        assert repo.get(id_talk).duration == talk.duration
예제 #13
0
    def test_delete_talk_by_id(self):
        talk = Talk("Fedoka", 20)
        repo = TalksRepository()

        id_talk = repo.insert(talk)
        repo.delete(id_talk)

        with pytest.raises(TalkNotFoundException):
            repo.get(id_talk)
예제 #14
0
    def test_talks_is_ordered_by_hour(self):
        date = datetime(2018, 1, 1)
        track = Track(date)
        talk1 = Talk("Fedoka", 3 * 60)
        talk2 = Talk("Tutu de Feijão", 4 * 60)

        track.schedule_talk(talk1)
        track.schedule_talk(talk2)

        timeline = track.get_timeline()

        assert timeline[0].get_title() == 'Fedoka'
        assert timeline[0].get_date() == datetime(2018, 1, 1, 9)
        assert timeline[1].get_title() == 'Lunch'
        assert timeline[1].get_date() == datetime(2018, 1, 1, 12)
        assert timeline[2].get_title() == 'Tutu de Feijão'
        assert timeline[2].get_date() == datetime(2018, 1, 1, 13)
        assert timeline[3].get_title() == 'Network'
        assert timeline[3].get_date() == datetime(2018, 1, 1, 17)
예제 #15
0
    def test_when_insert_a_talk(self, mock_repo_get, mock_repo_insert):
        response = self.__send_post('/talks', dict(title='Namika',
                                                   duration=30))

        mock_repo_get.return_value = [Talk('Namika', 30)]
        data = json.loads(response.data)

        assert data['id'] == 0
        assert data['title'] == 'Namika'
        assert data['duration'] == 30

        assert len(mock_repo_get()) == 1
예제 #16
0
    def test_talk_is_added_correctly(self):
        track = Track(datetime.now())
        talk = Talk("qualquer bosta denovo", 60)
        track.schedule_talk(talk)

        scheduled = track.get_timeline()[0]

        assert scheduled.title == talk.title
        assert scheduled.duration == talk.duration
        assert scheduled.date.hour == 9
        assert scheduled.date.minute == 0
        assert scheduled.date.second == 0
        assert scheduled.date.microsecond == 0
예제 #17
0
    def test_when_return_the_conference_complete(self):
        track = Track(datetime.now())
        talks = [
            Talk("Xuxu", 3 * 60),
            Talk("Abacaxi", 4 * 60),
            Talk("Couve", 3 * 60),
            Talk("Frango", 4 * 60)
        ]
        track_management = TrackManagement(talks)
        tracks = track_management.generate_tracks_to_talks()
        conference = Conference(tracks)

        conference = conference.get_formatted_tracks_for_conference()

        assert conference == {
            'Track 1': [
                '09:00AM Xuxu 180', '12:00PM Lunch 60', '01:00PM Abacaxi 240',
                '05:00PM Network 60'
            ],
            'Track 2': [
                '09:00AM Couve 180', '12:00PM Lunch 60', '01:00PM Frango 240',
                '05:00PM Network 60'
            ]
        }
예제 #18
0
class TestTalksAPI:
    @patch('src.web.TalksRepository.insert', return_value=0)
    @patch('src.web.TalksRepository.get', return_value=Talk('Namika', 30))
    def test_when_insert_a_talk(self, mock_repo_get, mock_repo_insert):
        response = self.__send_post('/talks', dict(title='Namika',
                                                   duration=30))

        mock_repo_get.return_value = [Talk('Namika', 30)]
        data = json.loads(response.data)

        assert data['id'] == 0
        assert data['title'] == 'Namika'
        assert data['duration'] == 30

        assert len(mock_repo_get()) == 1

    @patch('src.web.TalksRepository.delete', return_value=[])
    def test_when_delete_a_talk_by_id(self, mock_delete):
        response = self.__send_delete('/talks/0')

        assert response.status_code == 204
        assert len(mock_delete()) == 0

    @patch('src.web.TalksRepository.delete', side_effect=TalkNotFoundException)
    def test_when_delete_an_inexistent_talk(self, mock_delete):
        response = self.__send_delete('/talks/0')
        with pytest.raises(TalkNotFoundException):
            mock_delete()

        assert response.status_code == 404

    @patch(
        'src.web.TalksRepository.get',
        return_value=[Talk('Namika', 30),
                      Talk('Luna', 30),
                      Talk('Pink', 30)])
    def test_when_insert_multiple_talks_then_return_a_list_of_talks(
            self, mock_get):
        response = self.__send_get('/talks')
        data = json.loads(response.data)

        assert data[0]['id'] == 0
        assert data[0]['title'] == 'Namika'
        assert data[0]['duration'] == 30
        assert data[1]['id'] == 1
        assert data[1]['title'] == 'Luna'
        assert data[1]['duration'] == 30
        assert data[2]['id'] == 2
        assert data[2]['title'] == 'Pink'
        assert data[2]['duration'] == 30

        assert len(mock_get()) == 3

    @pytest.fixture(autouse=True)
    def test_configuration(self):
        self.__setup()
        yield

    def __send_post(self, url, json_dict):
        return self.app.post(url, data=json_dict)

    def __send_delete(self, url):
        return self.app.delete(url)

    def __send_get(self, url):
        return self.app.get(url)

    def __setup(self):
        src.web.app.testing = True
        self.app = src.web.app.test_client()
예제 #19
0
    def test_when_a_talk_is_added_in_an_empty_track(self):
        track = Track(datetime.now())
        talk = Talk("qualquer bosta", 60)
        track.schedule_talk(talk)

        assert len(track.get_timeline()) == 3
예제 #20
0
    def test_when_need_to_create_a_track_with_lightnings_talks(self):
        talks = [Talk('Writing Fast Tests Against Enterprise Rails', 60),
                 Talk('Overdoing it in Python', 45),
                 Talk('Lua for the Masses', 30),
                 Talk('Ruby Errors from Mismatched Gem Versions', 45),
                 Talk('Common Ruby Errors', 45),
                 Talk('Rails for Python Developers', 5),
                 Talk('Communicating Over Distance', 60),
                 Talk('Accounting-Driven Development', 45),
                 Talk('Woah', 30),
                 Talk('Sit Down and Write', 30),
                 Talk('Pair Programming vs Noise', 45),
                 Talk('Rails Magic', 60),
                 Talk('Ruby on Rails: Why We Should Move On', 60),
                 Talk('Clojure Ate Scala (on my project)', 45),
                 Talk('Programming in the Boondocks of Seattle', 30),
                 Talk('Ruby vs. Clojure for Back-End Development', 30),
                 Talk('Ruby on Rails Legacy App Maintenance', 60),
                 Talk('A World Without HackerNews', 30),
                 Talk('User Interface CSS in Rails Apps', 30)
                 ]

        tracks = TrackManagement(talks)
        tracks = tracks.generate_tracks_to_talks()

        for track in tracks:
            for talk in track.get_timeline():
                if talk.title == 'Network' and talk.date.hour == 17:
                    assert talk.date.minute == 0
                    assert talk.date.second == 0