def test_validate_does_not_copy(): instance = PersonModel(first_name="Jean", last_name="Pierre") assert PersonModel.validate(instance) is instance
def test_fields_modified_on_construction(): instance = PersonModel(first_name="Jean", last_name="Pierre") assert instance.__fields_modified__ == set( ["first_name", "last_name", "id"])
def instance_to_update(): return PersonModel(first_name=INITIAL_FIRST_NAME, last_name=INITIAL_LAST_NAME)
def test_model_copy_with_update_primary_key(): instance = PersonModel(first_name="Jean", last_name="Valjean") copied = instance.copy(update={"id": ObjectId()}) assert instance.first_name == copied.first_name assert copied.last_name == copied.last_name assert instance.id != copied.id
def test_model_copy_with_update(): instance = PersonModel(first_name="Jean", last_name="Valjean") copied = instance.copy(update={"last_name": "Pierre"}) assert instance.id == copied.id assert instance.first_name == copied.first_name assert copied.last_name == "Pierre"
def test_model_copy_without_update(): instance = PersonModel(first_name="Jean", last_name="Valjean") copied = instance.copy() assert instance == copied
class M(Model): ... id_ = ObjectId() assert json.loads(M(id=id_).json()) == {"id": str(id_)} TWITTER_USERS = [TwitterUser(), TwitterUser(), TwitterUser()] MAIN_TWITTER_USER = TwitterUser(following=[e.id for e in TWITTER_USERS]) @pytest.mark.parametrize( "instance, expected_parsed_json", ( ( PersonModel(first_name="Johnny", last_name="Cash"), dict(first_name="Johnny", last_name="Cash"), ), ( TreeModel( name="Secoya", average_size=100.3, discovery_year=1253, kind=TreeKind.BIG, genesis_continents=["Asia"], per_continent_density={"Asia": 20.3}, ), dict( name="Secoya", average_size=100.3, discovery_year=1253,