def test_backlog_controller_submit_new_user_story_form_with_errors():
    project = factories.project()
    project_view = views.projects.ProjectDetailView(project)
    project_view.backlog.notifier = mock.Mock()
    executor = factories.patched_executor()
    _ = mock.Mock()
    project_detail_controller = controllers.projects.ProjectDetailController(project_view, executor, _)
    project_detail_controller.handle(config.ProjectBacklogKeys.CREATE_USER_STORY)
    form = project_detail_controller.view.backlog.user_story_form

    signals.emit(form.save_button, "click")
    assert project_view.backlog.notifier.error_msg.call_count == 1
def test_backlog_controller_cancel_the_new_user_story_form():
    project = factories.project()
    project_view = views.projects.ProjectDetailView(project)
    executor = factories.patched_executor()
    _ = mock.Mock()
    project_detail_controller = controllers.projects.ProjectDetailController(project_view, executor, _)
    project_detail_controller.handle(config.ProjectBacklogKeys.CREATE_USER_STORY)

    assert hasattr(project_detail_controller.view.backlog, "user_story_form")
    form = project_detail_controller.view.backlog.user_story_form
    signals.emit(form.cancel_button, "click")
    assert not hasattr(project_detail_controller.view.backlog, "user_story_form")
def test_backlog_controller_close_the_milestone_selector_popup():
    project = factories.project()
    project_view = views.projects.ProjectDetailView(project)
    executor = factories.patched_executor()
    _ = mock.Mock()
    project_detail_controller = controllers.projects.ProjectDetailController(project_view, executor, _)
    project_detail_controller.handle(config.ProjectBacklogKeys.MOVE_US_TO_MILESTONE)

    assert hasattr(project_detail_controller.view.backlog, "milestone_selector_popup")
    milestone_selector_popup = project_detail_controller.view.backlog.milestone_selector_popup
    signals.emit(milestone_selector_popup.cancel_button, "click")
    assert not hasattr(project_detail_controller.view.backlog, "milestone_selector_popup")
def test_backlog_controller_close_the_help_popup():
    project = factories.project()
    project_view = views.projects.ProjectDetailView(project)
    executor = factories.patched_executor()
    _ = mock.Mock()
    project_detail_controller = controllers.projects.ProjectDetailController(project_view, executor, _)
    project_detail_controller.handle(config.ProjectBacklogKeys.HELP)

    assert hasattr(project_detail_controller.view.backlog, "help_popup")
    help_popup = project_detail_controller.view.backlog.help_popup
    signals.emit(help_popup.close_button, "click")
    assert not hasattr(project_detail_controller.view.backlog, "help_popup")
def test_backlog_controller_move_a_user_story_to_a_milestone():
    project = factories.project()
    project_view = views.projects.ProjectDetailView(project)
    project_view.backlog.notifier = mock.Mock()
    executor = factories.patched_executor()
    _ = mock.Mock()
    project_detail_controller = controllers.projects.ProjectDetailController(project_view, executor, _)
    project_detail_controller.handle(config.ProjectBacklogKeys.MOVE_US_TO_MILESTONE)
    milestone_selector_popup = project_detail_controller.view.backlog.milestone_selector_popup
    project_view.backlog.notifier.reset_mock()

    assert project_view.backlog.notifier.info_msg.call_count == 0
    assert executor.update_user_story.call_count == 0
    signals.emit(milestone_selector_popup.options[2], "click")
    assert project_view.backlog.notifier.info_msg.call_count == 1
    assert executor.update_user_story.call_count == 1
    assert (executor.update_user_story.call_args.call_list()[0][0][1]["milestone"] ==
            milestone_selector_popup.project["list_of_milestones"][-3]["id"])
def test_backlog_controller_submit_new_user_story_form_successfully():
    us_subject = "Create a new user story"
    project = factories.project()
    project_view = views.projects.ProjectDetailView(project)
    project_view.backlog.notifier = mock.Mock()
    executor = factories.patched_executor(create_user_story_response=factories.future(
                           factories.successful_create_user_story_response(us_subject)))
    _ = mock.Mock()
    project_detail_controller = controllers.projects.ProjectDetailController(project_view, executor, _)
    project_detail_controller.handle(config.ProjectBacklogKeys.CREATE_USER_STORY)
    form = project_detail_controller.view.backlog.user_story_form
    project_view.backlog.notifier.reset_mock()

    form._subject_edit.set_edit_text(us_subject)
    signals.emit(form.save_button, "click")
    assert project_view.backlog.notifier.info_msg.call_count == 1
    assert executor.create_user_story.call_args.call_list()[0][0][0]["subject"] == us_subject
    assert executor.create_user_story.call_count == 1
    assert executor.create_user_story.return_value.result()["subject"] == us_subject