Ejemplo n.º 1
0
 def create(self, email, password, display_name):
     new_user = User(email=email,
                     password=password,
                     display_name=display_name)
     with self.db.get_session() as session:
         session.add(new_user)
     return new_user.id
Ejemplo n.º 2
0
def test_verify_token_multiple_tokens(db, service_container):
    token = "im a token"

    user = User(email="*****@*****.**",
                password="******",
                display_name="Test Account")

    user_token_1 = UserToken(
        user=user,
        token=token,
        created_datetime_utc=datetime.datetime.utcnow() -
        datetime.timedelta(days=1),
    )

    user_token_2 = UserToken(user=user,
                             token=token + "123",
                             created_datetime_utc=datetime.datetime.utcnow())

    db.session.add(user)
    db.session.add(user_token_1)
    db.session.add(user_token_2)

    db.session.commit()

    with entrypoint_hook(service_container, "verify_token") as verify_token:
        verify_token(user.id, token + "123")
Ejemplo n.º 3
0
def test_create_user_unsuccessful(db, service_container):

    email = "*****@*****.**"
    password = "******"
    display_name = "Test Account"

    db.session.add(
        User(email=email, password=password, display_name=display_name))
    db.session.commit()

    with entrypoint_hook(service_container, "create") as create:
        with pytest.raises(exc.IntegrityError):
            create(email, password, display_name)
Ejemplo n.º 4
0
def test_get_all_verified_none(db, service_container):
    user = User(email="*****@*****.**",
                password="******",
                display_name="Test Account")
    db.session.add(user)
    db.session.commit()

    with entrypoint_hook(service_container,
                         "get_all_verified") as get_all_verified:

        projects = get_all_verified(user.id)

    assert projects == []
Ejemplo n.º 5
0
def test_verify_token_true(db, service_container):
    token = "im a token"

    user = User(email="*****@*****.**",
                password="******",
                display_name="Test Account")

    user_token = UserToken(user=user, token=token)

    db.session.add(user)
    db.session.add(user_token)
    db.session.commit()

    with entrypoint_hook(service_container, "verify_token") as verify_token:
        verify_token(user.id, token)
Ejemplo n.º 6
0
def test_create_user_token(db, service_container):
    user = User(email="*****@*****.**",
                password="******",
                display_name="Test Account")
    db.session.add(user)
    db.session.commit()

    token = "im a token"

    with entrypoint_hook(service_container, "create") as create:
        create(user.id, token)

    assert db.session.query(UserToken).count() == 1

    db.session.query(UserToken).filter_by(user_id=user.id).one()
Ejemplo n.º 7
0
def test_is_correct_password_false_with_deleted_user(db, service_container):
    user = User(
        email="*****@*****.**",
        password="******",
        display_name="Test Account",
        deleted_datetime_utc=datetime.datetime.utcnow(),
    )
    db.session.add(user)
    db.session.commit()

    with entrypoint_hook(service_container,
                         "is_correct_password") as is_correct_password:
        result = is_correct_password("*****@*****.**", "password")

        assert result is False
Ejemplo n.º 8
0
def test_is_correct_password_false(db, service_container):
    user = User(
        email="*****@*****.**",
        password="******",
        display_name="Test Account",
        verified=True,
    )
    db.session.add(user)
    db.session.commit()

    with entrypoint_hook(service_container,
                         "is_correct_password") as is_correct_password:
        result = is_correct_password(user.email, "not_the_password")

        assert result is False
def test_create_audit_log(db, service_container):
    user = User(email="test", display_name="test", password="******")
    db.session.add(user)
    db.session.commit()

    with entrypoint_hook(service_container,
                         "create_notification") as create_notification:
        create_notification(user.id, "TEST", {"data": "test"})

    db.session.commit()

    notification_result = (db.session.query(UserNotification).filter_by(
        user_id=user.id).all())

    assert len(notification_result) == 1

    assert notification_result[0].notification_type == "TEST"
    assert notification_result[0].meta_data == {"data": "test"}
Ejemplo n.º 10
0
def test_get_user_successful(db, service_container):
    user = User(email="*****@*****.**",
                password="******",
                display_name="Test Account")
    db.session.add(user)
    db.session.commit()

    with entrypoint_hook(service_container, "get") as get:
        user_details = get(user.id)

    assert user_details == {
        "id": user.id,
        "email": user.email,
        "display_name": user.display_name,
        "created_datetime_utc": user.created_datetime_utc,
        "deleted_datetime_utc": user.deleted_datetime_utc,  # None,
        "verified": False,
    }
Ejemplo n.º 11
0
def test_delete_user_successful(db, service_container):
    user = User(email="*****@*****.**",
                password="******",
                display_name="Test Account")
    db.session.add(user)
    db.session.commit()

    with entrypoint_hook(service_container, "delete") as delete:
        delete(user.id)

    db.session.commit(
    )  # not sure why this is needed but it seems to fix the test?
    # its definitely commit in production but weird its not here.

    assert db.session.query(User).count() == 1

    deleted_user = db.session.query(User).filter_by(id=user.id).one()

    assert deleted_user.deleted_datetime_utc is not None
Ejemplo n.º 12
0
def test_get_total_projects(db, service_container):

    user = User(email="*****@*****.**",
                password="******",
                display_name="Test Account")
    db.session.add(user)
    db.session.commit()

    with entrypoint_hook(service_container,
                         "get_total_projects") as get_total_projects:
        with mock.patch(
                "accounts.dependencies.database.collections.projects.Projects.get_all_verified",
                return_value=[{}, {}],
        ) as get_all_verified:
            total_projects = get_total_projects(user.id)

        assert get_all_verified.call_args == call(user.id)

    assert total_projects == 2
Ejemplo n.º 13
0
def test_update_verified_true(db, service_container):
    user = User(
        email="*****@*****.**",
        password="******",
        display_name="Test Account",
        deleted_datetime_utc=datetime.datetime.utcnow(),
    )
    db.session.add(user)
    db.session.commit()

    assert user.verified is False

    with entrypoint_hook(service_container,
                         "update_verified") as update_verified:
        update_verified(user.id, True)
    db.session.commit()

    user_from_db = db.session.query(User).get(user.id)

    assert user_from_db.verified is True
Ejemplo n.º 14
0
def test_get_all_verified(db, service_container):

    user = User(email="*****@*****.**",
                password="******",
                display_name="Test Account")
    project_one = Project(
        name="Project One",
        created_datetime_utc=datetime.datetime.utcnow(),
        checkout_session_id="1",
    )
    project_two = Project(
        name="Project Two",
        created_datetime_utc=datetime.datetime.utcnow() +
        datetime.timedelta(days=1),
        checkout_session_id="2",
    )
    project_three = Project(
        name="Project Three",
        created_datetime_utc=datetime.datetime.utcnow() +
        datetime.timedelta(days=2),
        checkout_session_id="3",
    )
    project_four = Project(
        name="Project Four",
        created_datetime_utc=datetime.datetime.utcnow() +
        datetime.timedelta(days=2),
        checkout_session_id="4",
    )
    """
    event_id = Column(Text, index=True, nullable=False)
    session_id = Column(Text, index=True, nullable=False)
    status = Column(Enum(StripeSessionCompletedStatusEnum), nullable=False)
    event_data = Column(JSON, nullable=False)
    """
    stripe_session_completed_1 = StripeSessionCompleted(
        event_id=1,
        session_id="1",
        status=StripeSessionCompletedStatusEnum.finished,
        event_data={},
    )
    stripe_session_completed_3 = StripeSessionCompleted(
        event_id=3,
        session_id="3",
        status=StripeSessionCompletedStatusEnum.finished,
        event_data={},
    )
    stripe_session_completed_4 = StripeSessionCompleted(
        event_id=4,
        session_id="4",
        status=StripeSessionCompletedStatusEnum.processing,
        event_data={},
    )

    user_project_1 = UserProject(user=user, project=project_one, verified=True)
    user_project_2 = UserProject(user=user,
                                 project=project_two,
                                 verified=False)
    user_project_3 = UserProject(user=user,
                                 project=project_three,
                                 verified=True)
    user_project_4 = UserProject(user=user,
                                 project=project_four,
                                 verified=True)

    db.session.add_all([
        user,
        project_one,
        project_two,
        project_three,
        user_project_1,
        user_project_2,
        user_project_3,
        stripe_session_completed_1,
        stripe_session_completed_3,
        stripe_session_completed_4,
    ])
    db.session.commit()

    with entrypoint_hook(service_container,
                         "get_all_verified") as get_all_verified:
        projects = get_all_verified(user.id)

    assert projects == [
        {
            "id": project_one.id,
            "name": project_one.name,
            "created_datetime_utc": project_one.created_datetime_utc,
            "deleted_datetime_utc": None,
            "checkout_session_id": "1",
        },
        {
            "id": project_three.id,
            "name": project_three.name,
            "created_datetime_utc": project_three.created_datetime_utc,
            "deleted_datetime_utc": None,
            "checkout_session_id": "3",
        },
    ]