-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If a List field has been declared with content_type as a Value Object and the value object class was supplied as a string, we should resolve reference on domain initialization.
- Loading branch information
Showing
6 changed files
with
95 additions
and
4 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
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
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
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
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,44 @@ | ||
import pytest | ||
|
||
from protean import BaseView | ||
from protean.fields import Identifier, Integer, String | ||
|
||
|
||
class Person(BaseView): | ||
person_id = Identifier(identifier=True) | ||
first_name = String(max_length=50, required=True) | ||
last_name = String(max_length=50) | ||
age = Integer(default=21) | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def register_elements(test_domain): | ||
test_domain.register(Person) | ||
test_domain.init(traverse=False) | ||
|
||
|
||
class TestViewPersistence: | ||
def test_view_can_be_persisted(self, test_domain): | ||
person = Person(person_id="1", first_name="John", last_name="Doe", age=25) | ||
test_domain.repository_for(Person).add(person) | ||
|
||
refreshed_person = test_domain.repository_for(Person).get(person.person_id) | ||
|
||
assert refreshed_person.person_id == "1" | ||
assert refreshed_person.first_name == "John" | ||
assert refreshed_person.last_name == "Doe" | ||
assert refreshed_person.age == 25 | ||
|
||
def test_view_can_be_updated(self, test_domain): | ||
person = Person(person_id="1", first_name="John", last_name="Doe", age=25) | ||
test_domain.repository_for(Person).add(person) | ||
|
||
person.first_name = "Jane" | ||
test_domain.repository_for(Person).add(person) | ||
|
||
refreshed_person = test_domain.repository_for(Person).get(person.person_id) | ||
|
||
assert refreshed_person.person_id == "1" | ||
assert refreshed_person.first_name == "Jane" | ||
assert refreshed_person.last_name == "Doe" | ||
assert refreshed_person.age == 25 |
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