-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ValueQuotaValidator and add tests
- Loading branch information
1 parent
a5c916f
commit e31c155
Showing
2 changed files
with
71 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import pytest | ||
|
||
from rest_framework.exceptions import ValidationError as RestFameworkValidationError | ||
|
||
from ..serializers.v1 import ValueSerializer | ||
from ..validators import ValueQuotaValidator | ||
|
||
project_id = 1 | ||
attribute_path = attribute__path='individual/single/text' | ||
|
||
|
||
def test_serializer_create_file(db): | ||
class MockedProject: | ||
file_size = 1 | ||
|
||
class MockedView: | ||
action = 'create' | ||
project = MockedProject() | ||
|
||
validator = ValueQuotaValidator() | ||
serializer = ValueSerializer() | ||
serializer.context['view'] = MockedView() | ||
|
||
validator({ | ||
'value_type': 'file' | ||
}, serializer) | ||
|
||
|
||
def test_serializer_create_file_error(db, settings): | ||
class MockedProject: | ||
file_size = 1 | ||
|
||
class MockedView: | ||
action = 'create' | ||
project = MockedProject() | ||
|
||
settings.PROJECT_FILE_QUOTA = '0' | ||
|
||
validator = ValueQuotaValidator() | ||
serializer = ValueSerializer() | ||
serializer.context['view'] = MockedView() | ||
|
||
with pytest.raises(RestFameworkValidationError): | ||
validator({ | ||
'value_type': 'file' | ||
}, serializer) | ||
|
||
|
||
def test_serializer_create_text(db, settings): | ||
class MockedProject: | ||
file_size = 1 | ||
|
||
class MockedView: | ||
action = 'create' | ||
project = MockedProject() | ||
|
||
settings.PROJECT_FILE_QUOTA = '0' | ||
|
||
validator = ValueQuotaValidator() | ||
serializer = ValueSerializer() | ||
serializer.context['view'] = MockedView() | ||
|
||
validator({ | ||
'value_type': 'text' | ||
}, serializer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters