test_scholarhip_validate.py 899 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.test import TestCase
2
from backend.models.abstract.scholarship import ScholarshipSerializer
Florent Chehab's avatar
Florent Chehab committed
3
4
import pytest
from rest_framework.validators import ValidationError
Florent Chehab's avatar
Florent Chehab committed
5
from backend.models.currency import Currency
Florent Chehab's avatar
Florent Chehab committed
6
7
8


class ScholarshipTestCase(TestCase):
Florent Chehab's avatar
Florent Chehab committed
9
10
11
12
13
14
15
    @classmethod
    def setUpTestData(cls):
        cls.EUR = Currency.objects.create(
            code="EUR",
            name="Euro",
            one_EUR_in_this_currency=1
        )
Florent Chehab's avatar
Florent Chehab committed
16
17
18

    def test_scholarhip_validation(self):
        ser = ScholarshipSerializer()
19
        attrs = {
Florent Chehab's avatar
Florent Chehab committed
20
            'useful_links': [],
Florent Chehab's avatar
Florent Chehab committed
21
22
            'comment': '',
            'currency': self.EUR
23
        }
Florent Chehab's avatar
Florent Chehab committed
24

Florent Chehab's avatar
Florent Chehab committed
25
        with pytest.raises(ValidationError):
26
27
            attrs['amount_min'] = 200
            attrs['amount_max'] = 100
Florent Chehab's avatar
Florent Chehab committed
28
29
            ser.my_validate(attrs)

30
31
        attrs['amount_min'] = 100
        attrs['amount_max'] = 200
Florent Chehab's avatar
Florent Chehab committed
32
        ser.my_validate(attrs)