예제 #1
0
def test_archive_scholarship_when_is_archived_should_not_be_possible(api):
    id = Id.generate()
    Scholarship.create({
        'id': id.value,
        'name': 'foo',
        'createdAt': '2020-01-01',
        'state': State.ARCHIVED.value,
    })
    response = api.post(f'/api/publishing/scholarships/{id.value}/archive/')
    assert response.status_code == 403
예제 #2
0
def test_archive_scholarship(api):
    id = Id.generate()
    Scholarship.create({
        'id': id.value,
        'name': 'foo',
        'createdAt': '2020-01-01',
        'state': State.PUBLISHED.value,
    })
    response = api.post(f'/api/publishing/scholarships/{id.value}/archive/')
    assert response.status_code == 204
예제 #3
0
def test_archive_only_expired_scholarships():
    Scholarship.create({
        'id': 'foo',
        'name': 'foo',
        'createdAt': '2020-01-01',
        'state': State.PUBLISHED.value,
        'deadline': YESTERDAY,
    })

    Scholarship.create({
        'id': 'bar',
        'name': 'bar',
        'createdAt': '2020-01-01',
        'state': State.PUBLISHED.value,
        'deadline': YESTERDAY,
    })

    Scholarship.create({
        'id': 'available',
        'name': 'bar',
        'createdAt': '2020-01-01',
        'state': State.PUBLISHED.value,
        'deadline': TOMORROW,
    })

    run_archive_scholarships()

    expired_scholarship = Scholarship.get('foo')
    expired_scholarship2 = Scholarship.get('bar')
    available_scholarship = Scholarship.get('available')

    assert expired_scholarship.state == State.ARCHIVED.value
    assert expired_scholarship2.state == State.ARCHIVED.value
    assert available_scholarship.state == State.PUBLISHED.value
예제 #4
0
    def handle(event: ScholarshipCreated):
        fields = event.fields.copy()

        if 'entity' in fields:
            fields['entity'] = UpdateDraft._entity(fields['entity'])

        fields['country'] = UpdateDraft._country(fields.pop('country'))
        fields['fillStatus'] = UpdateDraft._fill_status(event.is_complete)
        fields['createdAt'] = event.timestamp
        Scholarship.create(fields)
        return fields['id']
예제 #5
0
def test_archive_scholarship():
    Scholarship.create({
        'id': 'foo',
        'name': 'foo',
        'createdAt': '2020-01-01',
        'state': State.PUBLISHED.value,
        'deadline': YESTERDAY,
    })

    run_archive_scholarships()
    scholarship = Scholarship.get('foo')

    assert scholarship.state == State.ARCHIVED.value
예제 #6
0
def test_today_scholarship_deadline_is_available():
    Scholarship.create({
        'id': 'foo',
        'name': 'foo',
        'createdAt': '2020-01-01',
        'state': State.PUBLISHED.value,
        'deadline': TODAY,
    })

    run_archive_scholarships()

    scholarship = Scholarship.get('foo')

    assert scholarship.state == State.PUBLISHED.value
예제 #7
0
def test_entity_cant_be_edited(api):
    edited_entity = {
        'name': 'newfoo',
        'website': 'http://new_foo.com',
    }

    foo_scholarship = Scholarship.get('foo')
    assert foo_scholarship.entity.name == 'Foo'

    response = api.put('/api/entities/foo/', json=edited_entity)
    assert response.status_code == 200

    assert Scholarship.get('foo').entity.name == 'newfoo'

    # Other entities should not change
    assert Scholarship.get('bar').entity.name == 'Bar'
예제 #8
0
def pending_detail(scholarship_id):
    scholarship = Scholarship.get(
        id=scholarship_id,
        ignore=NotFound.code,
        _source=[
            'name',
            'description',
            'deadline',
            'fundingType',
            'state',
            'academicLevel',
            'entity.name',
            'entity.code',
            'country.name',
            'country.code',
            'sourceDetails.url',
            'sourceDetails.id',
            'sourceDetails.steps',
            'fillStatus',
            'language',
            'approval.approvedAt',
            'denial.deniedAt',
            'denial.reason',
            'archive.archivedAt',
        ],
    )

    if not scholarship:
        raise NotFound

    return scholarship.serialize()
예제 #9
0
def show(scholarship_id):
    scholarship = Scholarship.get(
        id=scholarship_id,
        ignore=NotFound.code,
        _source=[
            'name',
            'description',
            'deadline',
            'fundingType',
            'state',
            'academicLevel',
            'entity.code',
            'entity.name',
            'country.name',
            'country.code',
            'sourceDetails.url',
            'sourceDetails.steps',
        ],
    )

    if not scholarship:
        raise NotFound

    if scholarship['state'] != State.PUBLISHED.value:
        raise Forbidden
    else:
        del scholarship['state']

    return scholarship.serialize()
예제 #10
0
    def handle(event: ScholarshipApproved):
        scholarship = Scholarship.get(event.scholarship_id)

        scholarship.update(
            refresh=True,
            state=State.PUBLISHED.value,
            approval={'approvedAt': event.timestamp},
        )
예제 #11
0
    def handle(event: ScholarshipArchived):
        scholarship = Scholarship.get(event.scholarship_id)

        scholarship.update(
            refresh=True,
            state=State.ARCHIVED.value,
            archive={'archivedAt': event.timestamp},
        )
예제 #12
0
def get_expired_scholarship_ids():
    expired_scholarship = Scholarship.search().filter(
        'range',
        **{'deadline': {
            'lt': 'now/d',
            'format': 'strict_date_optional_time'
        }})
    return [item.meta.id for item in expired_scholarship]
예제 #13
0
    def test_pending_scholarships_are_not_listed(self, api):
        pending_state = 'PENDING'
        Scholarship.create({
            'id': 'id-test',
            'name': 'name-test',
            'description': 'description-test',
            'deadline': '2099-01-01',
            'state': pending_state,
            'entity': {
                'code': 'entity-code-test',
                'name': 'entity-name-test',
            },
            'createdAt': '2020-01-01',
        })

        response = api.get('/api/search/scholarships/')
        result = response.json()
        assert result['results'] == []
예제 #14
0
    def handle(event: ScholarshipDenied):
        scholarship = Scholarship.get(event.scholarship_id)

        scholarship.update(
            refresh=True,
            state=State.DENIED.value,
            denial={
                'reason': event.reason,
                'deniedAt': event.timestamp,
            },
        )
예제 #15
0
    def handle(event: ScholarshipRestored):
        scholarship = Scholarship.get(event.scholarship_id)

        scholarship.update(
            refresh=True,
            state=State.PENDING.value,
            archive={'archivedAt': None},
            denial={
                'reason': None,
                'deniedAt': None,
            },
        )
예제 #16
0
    def test_scholarship_response(self, api):
        Scholarship.create({
            'id': 'id-test',
            'name': 'name-test',
            'description': 'description-test',
            'deadline': '2099-01-01',
            'state': 'PUBLISHED',
            'entity': {
                'code': 'entity-code-test',
                'name': 'entity-name-test',
            },
            'createdAt': '2020-01-01',
        })
        response = api.get('/api/search/scholarships/')
        result = response.json()
        scholarship = result['results'][0]

        assert isinstance(scholarship, dict)

        assert 'id' in scholarship
        assert scholarship['id'] == 'id-test'

        assert 'name' in scholarship
        assert scholarship['name'] == 'name-test'

        assert 'description' in scholarship
        assert scholarship['description'] == 'description-test'

        assert 'deadline' in scholarship
        assert scholarship['deadline'] == '2099-01-01T00:00:00'

        assert isinstance(scholarship.get('entity'), dict)
        assert {
            'code': 'entity-code-test',
            'name': 'entity-name-test',
        }.items() <= scholarship['entity'].items()
예제 #17
0
    def handle(event: PendingEdited):
        scholarship = Scholarship.get(event.scholarship_id)

        fields = event.fields.copy()
        fields['fillStatus'] = UpdateDraft._fill_status(event.is_complete)
        fields['country'] = UpdateDraft._country(fields.pop('country'))

        if 'steps' in fields:
            if 'sourceDetails' in fields:
                fields['sourceDetails']['steps'] = fields.pop('steps')
            else:
                fields['sourceDetails'] = {'steps': fields.pop('steps')}

        if 'entity' in fields:
            fields['entity'] = UpdateDraft._entity(fields.pop('entity'))

        scholarship.update(refresh=True, **fields)
예제 #18
0
def prepare_data(api):
    Entity.init()
    Scholarship.init()

    api.post('/api/entities/', json={
        'name': 'Foo',
        'code': 'foo',
        'website': 'http://foo.com',
    })

    api.post('/api/entities/', json={
        'name': 'Bar',
        'code': 'bar',
        'website': 'http://bar.com',
    })

    Scholarship.create({
        'id': 'foo',
        'name': 'foo',
        'createdAt': '2020-01-01',
        'state': State.ARCHIVED.value,
        'entity': {
            'code': 'foo',
            'name': 'Foo',
        },
    })

    Scholarship.create({
        'id': 'bar',
        'name': 'bar',
        'createdAt': '2020-01-01',
        'state': State.ARCHIVED.value,
        'entity': {
            'code': 'bar',
            'name': 'Bar',
        },
    })
예제 #19
0
def save_scholarship(item: dict):
    Scholarship.create(item)
예제 #20
0
def scholarships_index():
    Scholarship.init()