def test_patch_not_found(self, sqla_session): from testscaffold.views.api.users import UserAPIView import pyramid.httpexceptions with tmp_session_context(sqla_session) as session: request = dummy_request(session) request.matchdict['object_id'] = 1 with pytest.raises(pyramid.httpexceptions.HTTPNotFound): UserAPIView(request).patch()
def test_wrong_post(self, sqla_session): from testscaffold.views.api.users import UserAPIView import marshmallow with tmp_session_context(sqla_session) as session: request = dummy_request(session) request.json_body = {} with pytest.raises(marshmallow.ValidationError): UserAPIView(request).post()
def test_patch_not_found(self, sqla_session): from testscaffold.views.api.users import UserAPIView import pyramid.httpexceptions with tmp_session_context(sqla_session) as session: request = dummy_request(session) request.matchdict["object_id"] = 1 with pytest.raises(pyramid.httpexceptions.HTTPNotFound): UserAPIView(request).patch()
def test_get_found(self, sqla_session): from testscaffold.views.api.users import UserAPIView from testscaffold.models.user import User with tmp_session_context(sqla_session) as session: request = dummy_request(session) user = User(id=5, email='foo', user_name='bar') user.persist(flush=True, db_session=request.dbsession) request.matchdict['object_id'] = 5 result = UserAPIView(request).get() assert result['id'] == 5
def test_get_found(self, sqla_session): from testscaffold.views.api.users import UserAPIView from testscaffold.models.user import User with tmp_session_context(sqla_session) as session: request = dummy_request(session) user = User(id=5, email="foo", user_name="bar") user.persist(flush=True, db_session=request.dbsession) request.matchdict["object_id"] = 5 result = UserAPIView(request).get() assert result["id"] == 5
def test_proper_post(self, sqla_session): from testscaffold.views.api.users import UserAPIView with tmp_session_context(sqla_session) as session: request = dummy_request(session) request.json_body = { 'user_name': 'new_user', 'email': '*****@*****.**', 'password': '******' } result_dict = UserAPIView(request).post() assert result_dict['id'] > 0 assert result_dict['user_name'] == 'new_user' assert result_dict['email'] == '*****@*****.**' assert 'password' not in result_dict
def test_patch_found_valid(self, sqla_session): from testscaffold.views.api.users import UserAPIView from testscaffold.models.user import User with tmp_session_context(sqla_session) as session: request = dummy_request(session) request.json_body = {"user_name": "changed", "email": "*****@*****.**"} user = User(id=1, email="foo", user_name="bar") user.persist(flush=True, db_session=request.dbsession) request.matchdict["object_id"] = 1 result = UserAPIView(request).patch() assert result["user_name"] == "changed" assert result["email"] == "*****@*****.**"
def test_proper_post(self, sqla_session): from testscaffold.views.api.users import UserAPIView with tmp_session_context(sqla_session) as session: request = dummy_request(session) request.json_body = { "user_name": "new_user", "email": "*****@*****.**", "password": "******", } result_dict = UserAPIView(request).post() assert result_dict["id"] > 0 assert result_dict["user_name"] == "new_user" assert result_dict["email"] == "*****@*****.**" assert "password" not in result_dict
def test_patch_found_valid(self, sqla_session): from testscaffold.views.api.users import UserAPIView from testscaffold.models.user import User with tmp_session_context(sqla_session) as session: request = dummy_request(session) request.json_body = { 'user_name': 'changed', 'email': '*****@*****.**', } user = User(id=1, email='foo', user_name='bar') user.persist(flush=True, db_session=request.dbsession) request.matchdict['object_id'] = 1 result = UserAPIView(request).patch() assert result['user_name'] == 'changed' assert result['email'] == '*****@*****.**'