Example #1
0
def test_should_declare_a_valid_name():

    value = "Rosalia"
    name = Name(value)

    assert isinstance(name, Name)
    assert name.value == value
Example #2
0
def test_should_play_with_player_aggregate_root():

    user = User.create(Name("Petisco"))

    assert isinstance(user.pull_first_domain_event(), UserCreated)
    assert isinstance(user.pull_last_domain_event(), UserCreated)
    assert len(user.pull_domain_events()) == 1

    user.clear_domain_events()

    assert user.pull_first_domain_event() is None
    assert user.pull_last_domain_event() is None
    assert len(user.pull_domain_events()) == 0
Example #3
0
    def retrieve(self, client_id: ClientId,
                 user_id: UserId) -> Result[User, Error]:

        with self.session_scope() as session:
            user_model = (session.query(self.UserModel).filter(
                self.UserModel.client_id == client_id.value).filter(
                    self.UserModel.user_id == user_id.value).first())
            if not user_model:
                return Failure(UserNotFoundError(user_id))

            return Success(
                User(
                    name=Name(user_model.name),
                    client_id=ClientId(user_model.client_id),
                    user_id=UserId(user_model.user_id),
                ))
Example #4
0
 def retrieve(self, client_id: ClientId,
              user_id: UserId) -> Result[User, Error]:
     with self.collection_context() as collection:
         user_doc = collection.find_one({
             "user_id": user_id.value,
             "client_id": client_id.value
         })
         if user_doc:
             return Success(
                 User(
                     name=Name(user_doc.name),
                     client_id=ClientId(user_doc.client_id),
                     user_id=UserId(user_doc.user_id),
                 ))
         else:
             return Failure(UserNotFoundError(user_id))
Example #5
0
 def controller():
     name = Name(
         "Rosalia de Castro. Adios rios adios fontes, adios, regatos pequenos, adios, vista dos meus ollos, non sei cando nos veremos."
     )
     return Success(name)
Example #6
0
def test_should_declare_a_valid_name_parametrizable(input_name):
    name = Name(input_name)

    assert isinstance(name.value, str)
    assert name.value == input_name
Example #7
0
def test_should_raise_given_name_is_not_valid_when_value_is_a_string_with_4_byte_utf_chars():

    with pytest.raises(GivenNameIsNotValidError):
        Name("π˜Όπ™‘π™šπ™­")
Example #8
0
def test_should_raise_given_name_is_not_valid_when_value_is_not_a_string():

    with pytest.raises(GivenNameIsNotValidError):
        Name([0, 0])
Example #9
0
def test_should_declare_a_name_with_empty_string():
    value = ""
    name = Name(value)

    assert isinstance(name, Name)
    assert name.value == value
Example #10
0
def test_should_declare_a_name_with_js_injection():

    with pytest.raises(GivenNameIsNotValidError):
        Name("<script>evil()</script>")
Example #11
0
def test_should_declare_a_name_that_exceeds_default_length_limits():

    with pytest.raises(ExceedLengthLimitValueObjectError):
        Name(
            "Rosalia de Castro. Adios rios adios fontes, adios, regatos pequenos, adios, vista dos meus ollos, non sei cando nos veremos."
        )
Example #12
0
 def controller():
     name = Name("<script>evil()</script>")
     return Success(name)
Example #13
0
def given_any_name() -> Name:
    return Name("Petisco")
def create_user(info_id: InfoId, body: dict):
    info_id.user_id = UserId.generate()
    name = Name(body.get("name"))
    return UserCreator.build().execute(info_id=info_id, name=name)