Example #1
0
 def fixture():
     return [
         User(_id="666f6f2d6261722d71757578",
              email="*****@*****.**",
              password="******",
              nickname="nickname1",
              role=User.ROLE_MASTER,
              score=23),
         User(_id="4d128b6ea794fc13a8000001",
              email="*****@*****.**",
              password="******",
              nickname="nickname2",
              role=User.ROLE_STUDENT,
              score=500),
         User(_id="4d128b6ea794fc13a8000002",
              email="*****@*****.**",
              password="******",
              nickname="nickname3",
              role=User.ROLE_STUDENT,
              score=340),
         User(_id="4d128b6ea794fc13a8000003",
              email="*****@*****.**",
              password="******",
              nickname="nickname4",
              role=User.ROLE_STUDENT,
              authtoken='authtoken4',
              score=341),
     ]
 def test_updateUserAuthToken_calledWithValidAuthToken_authTokenCorrectlyUpdated(
         self):
     test_id = ObjectId("5aae93045b488007cb4af590")
     self.db.users.insert_one({
         "email": "*****@*****.**",
         "password": "******",
         "nickname": "jimmy",
         "role": "student",
         "_id": test_id
     })
     self.sut.update_user_auth_token(test_id, "testauthtoken")
     actual = User.from_json(self.db.users.find_one({"_id": test_id
                                                     })).get_authtoken()
     expected = "testauthtoken"
     self.assertEqual(actual, expected)
 def test_incrementUserScore_calledWithExistentUserId_userScoreCorrectlyIncremented(
         self):
     test_id = ObjectId("5aae93045b488007cb4af590")
     self.db.users.insert_one({
         "email": "*****@*****.**",
         "password": "******",
         "nickname": "jimmy",
         "role": "student",
         "_id": test_id,
         "score": 400
     })
     self.sut.increment_user_score(test_id, 30)
     expected = 430
     actual = User.from_json(self.db.users.find_one({"_id":
                                                     test_id})).get_score()
     self.assertEqual(actual, expected)
Example #4
0
 def create(self, request):
     nickname = request.data.get('nickname', None)
     email = request.data.get('email', None)
     password = request.data.get('password', None)
     role = request.data.get('role', None)
     if email is None or password is None or nickname is None or role is None:
         return self._create_generic_response(
             response_type=ResponseType.missing_request_field)
     try:
         user = User.from_json(request.data)
     except Exception as e:
         return self._create_generic_response(
             response_type=ResponseType.server_error, exception=e)
     if UserFormatService().has_valid_fields(user):
         return self._create_response_by_inner_service_call(
             self.__user_service.create_user, user, message='user created')
     else:
         return self._create_generic_response(
             response_type=ResponseType.invalid_field_format)
class UserFormatServiceUnitTest(unittest.TestCase):
    def setUp(self):
        self.sut = UserFormatService()

    @data(
        {
            'user':
            User(email="*****@*****.**",
                 password="******",
                 role="master",
                 nickname="jackietest")
        }, {
            'user':
            User(email="O'*****@*****.**",
                 password="******",
                 role="master",
                 nickname="jackietest")
        }, {
            'user':
            User(email="*****@*****.**",
                 password="******",
                 role="master",
                 nickname="jac")
        })
    def test_hasValidFields_calledWithValidUser_returnTrue(self, input):
        self.assertTrue(self.sut.has_valid_fields(input['user']))

    @data(
        {
            'user':
            User(email="[email protected]",
                 password="******",
                 role="master",
                 nickname="jackietest")
        },
        {
            'user':
            User(email="assdsddad",
                 password="******",
                 role="master",
                 nickname="jackietest")
        },
        {
            'user':
            User(email="[email protected]",
                 password="******",
                 role="master",
                 nickname="jac")
        },
        {
            'user':
            User(email="*****@*****.**",
                 password="******",
                 role="master",
                 nickname="jackietest")
        },
        {
            'user':
            User(email="*****@*****.**",
                 password="******",
                 role="master",
                 nickname="ja")
        },
        {'user': User(email="", password="", role="master", nickname="")},
    )
    def test_hasValidFields_calledWithInvalidUser_returnFalse(self, input):
        self.assertFalse(self.sut.has_valid_fields(input['user']))
 def __get_user_test_instance(self):
     return User(_id=ObjectId("666f6f2d6261722d71757578"),
                 email="*****@*****.**",
                 password="******",
                 role="master",
                 nickname="testnickname")
Example #7
0
 def __get_user_test_instance(self):
     return User("*****@*****.**", "pwdpwdpwd", "master", "testnickname")
Example #8
0
 def _configure_sut_request(self, json_raw):
     request = mock.Mock(spec=Request)
     request.data = json.loads(json_raw)
     request.pdbuser = User("*****@*****.**", "testpwd", "master", "testnickname")
     return request
Example #9
0
 def __from_json_to_domain_model(self, result):
     if result is not None:
         result = User.from_json(result)
     return result