def test_scholarship_can_be_partially_created(self):
        name = 'foo'
        partial_request = CreateScholarshipRequest()
        partial_request.name = name

        command = CreateScholarship(partial_request)
        command.execute()
    def test_expired_scholarship_cannot_be_created(self):
        payload = DATA.copy()
        payload['deadline'] = '2020-01-01'
        request = CreateScholarshipRequest(**payload)
        command = CreateScholarship(request)

        with pytest.raises(ExpiredError):
            command.execute()
    def test_event_should_have_an_is_complete_field(self):
        request = CreateScholarshipRequest(**DATA)
        command = CreateScholarship(request)
        stub = MagicMock()
        ScholarshipCreated.fire = stub

        command.execute()

        is_complete = stub.call_args[0][1]
        assert isinstance(is_complete, bool)
    def test_scholarship_id_is_included_in_event(self):
        request = CreateScholarshipRequest(**DATA)
        command = CreateScholarship(request)
        stub = MagicMock()
        ScholarshipCreated.fire = stub

        command.execute()

        data = stub.call_args[0][0]
        assert 'id' in data
    def test_scholarship_should_have_a_pending_state(self):
        request = CreateScholarshipRequest(**DATA)
        command = CreateScholarship(request)
        stub = MagicMock()
        ScholarshipCreated.fire = stub

        command.execute()

        data = stub.call_args[0][0]
        assert 'state' in data
        assert data['state'] == 'PENDING'
    def test_scholarship_is_created_with_given_data(self):
        request = CreateScholarshipRequest(**DATA)
        command = CreateScholarship(request)
        stub = MagicMock()
        ScholarshipCreated.fire = stub

        command.execute()

        data = stub.call_args[0][0]
        for field in DATA.keys():
            assert field in data
 def test_create_should_fire_an_event(self):
     data = CreateScholarshipRequest(**{'name': 'foo'})
     command = CreateScholarship(data)
     event = command.execute()
     assert isinstance(event, ScholarshipCreated)
 def test_fields_are_stored(self, field, value):
     request = CreateScholarshipRequest(**{field: value})
     assert request.dict()[field] == value
 def test_fields_are_null_by_default(self, field):
     request = CreateScholarshipRequest()
     assert request.dict()[field] is None