def test_should_call_insert_with_correct_values_on_add(
        mock_insert_one: MagicMock, sut: SurveyMongoRepo):
    survey_data = dict(
        question="any_question",
        answers=[
            dict(answer="any_answer", image="any_image"),
            dict(answer="other_answer", image=None),
        ],
    )
    sut.add(AddSurveyModel(**survey_data))
    mock_insert_one.assert_called_with({
        "question":
        "any_question",
        "answers": [
            {
                "answer": "any_answer",
                "image": "any_image"
            },
            {
                "answer": "other_answer",
                "image": None
            },
        ],
        "date":
        datetime.utcnow(),
    })
def test_should_raise_exception_if_collection_insert_raise_on_add(
        mock_insert_one: MagicMock, sut: SurveyMongoRepo):
    mock_insert_one.side_effect = Exception()
    survey_data = dict(
        question="any_question",
        answers=[
            dict(answer="any_answer", image="any_image"),
            dict(answer="other_answer", image=None),
        ],
    )
    with pytest.raises(Exception) as excinfo:
        sut.add(AddSurveyModel(**survey_data))
    assert type(excinfo.value) is Exception
def test_should_create_a_survey_on_add(sut: SurveyMongoRepo):
    survey_data = dict(
        question="any_question",
        answers=[
            dict(answer="any_answer", image="any_image"),
            dict(answer="other_answer", image=None),
        ],
    )
    sut.add(AddSurveyModel(**survey_data))
    survey = MOCK_COLLECTION.find_one()
    assert survey
    assert survey["_id"]
    assert survey["question"] == survey_data["question"]
    assert survey["answers"] == survey_data["answers"]
    assert survey["date"] == datetime.utcnow()