コード例 #1
0
async def test_get_users_by_id_returns_user(users):
    u1 = User(id="1",
              email="email1",
              username="******",
              password="******")
    u2 = User(id="2",
              email="email2",
              username="******",
              password="******")
    await users.add(u1)
    await users.add(u2)
    result = await users.find_by_id(u1.id)
    assert result == u1
コード例 #2
0
async def test_find_user_by_email(users):
    email = "email"
    password = "******"
    u1 = User(id="1", email=email, username="******", password=password)
    await users.add(u1)
    assert await users.find_by_credentials(email, password) == u1
コード例 #3
0
async def test_email_exists_should_return_true(users):
    email = "email"
    u1 = User(id="1", email=email, username="******", password="******")
    assert await users.email_exists(email) is False
    await users.add(u1)
    assert await users.email_exists(email) is True
コード例 #4
0
async def test_username_exists_should_return_true(users):
    username = "******"
    u1 = User(id="1", email="email", username=username, password="******")
    assert await users.username_exists(username) is False
    await users.add(u1)
    assert await users.username_exists(username) is True
コード例 #5
0
import pytest
from asynctest import Mock

from learning_hub.domain.users import UserValidator, User, Users

EMPTY_USER = User(id="1", email="", username="", password="")
DUPLICATE_USER = User(id="1",
                      email="*****@*****.**",
                      username="******",
                      password="******")
VALIDATION_ERROR = ValueError


@pytest.fixture
def users():
    users = Mock(Users)
    users.username_exists.return_value = False
    users.email_exists.return_value = False
    return users


@pytest.fixture
def validator(users):
    return UserValidator(users)


async def test_user_validator_does_not_accept_empty_username_password_or_email(
        validator):
    with pytest.raises(VALIDATION_ERROR) as e:
        await validator.validate(EMPTY_USER)
    assert all([
コード例 #6
0
from uuid import uuid4

import pytest
from asynctest import Mock

from learning_hub.domain.users import Users, User, UserValidator
from learning_hub.usecases.create_user import CreateUser, CreateUserRequest

USER_ID = str(uuid4())
CREATE_USER_REQUEST = CreateUserRequest(email="*****@*****.**",
                                        username="******",
                                        password="******")
USER = User(id=USER_ID,
            email=CREATE_USER_REQUEST.email,
            username=CREATE_USER_REQUEST.username,
            password=CREATE_USER_REQUEST.password)


@pytest.fixture
def users():
    return Mock(Users)


@pytest.fixture
def user_validator():
    return Mock(UserValidator)


@pytest.fixture
def create_user(users, id_generator, user_validator):
    create_user = CreateUser(users)
コード例 #7
0
 def user_from_request(self, request) -> User:
     return User(id=self.id_generator.generate(),
                 email=request.email,
                 username=request.username,
                 password=request.password)
コード例 #8
0
import pytest
from asynctest import Mock

from learning_hub.apis.paths_api import PathsAPI
from learning_hub.domain.paths import Paths
from learning_hub.domain.users import Users, User
from learning_hub.usecases.create_path import *
from learning_hub.usecases.update_path import *
from tests.unit.apis.builders import CreatePathRequestBuilder, CreateAssignmentRequestBuilder
from tests.unit.apis.conftest import create_mock_request
from tests.unit.builders import PathBuilder, ParticipationBuilder, AssignmentBuilder

TODAY = datetime.now()
USER_ID = str(uuid4())
USER = User(id=USER_ID, email="email", password="******", username="******")
TOKEN = "xxxxx.yyyyy.zzzzz"
CREATE_PATH_REQUEST = CreatePathRequestBuilder(
    author=USER_ID,
    assignments=[CreateAssignmentRequestBuilder().build()],
    categories=["Categories"]).build()
CREATE_PATH_REQUEST_DATA = dict(
    token=TOKEN,
    title=CREATE_PATH_REQUEST.title,
    description=CREATE_PATH_REQUEST.description,
    categories=CREATE_PATH_REQUEST.categories,
    assignments=[dict(
        name=a.name, resource=a.resource, instructions=a.instructions
    ) for a in CREATE_PATH_REQUEST.assignments])
PATH_ID = str(uuid4())
PATH = PathBuilder(id=PATH_ID, author=USER_ID, assignments=[