Exemplo n.º 1
0
    def test(self):

        user_id = ""
        email = "*****@*****.**"
        first_name = "first_name"
        last_name = "last_name"
        full_name = "full_name"
        authority = "02"
        status = "01"
        comment = "comment"
        login_user_id = "U0000"

        ApplicationUserService().save_user(user_id, email, first_name,
                                           last_name, full_name, authority,
                                           status, comment, login_user_id)

        user_list = ApplicationUserQuery().get_active_users()
        user = user_list[0]

        self.assertEqual(user.email, "*****@*****.**")
        self.assertEqual(user.first_name, "first_name")
        self.assertEqual(user.last_name, "last_name")
        self.assertEqual(user.full_name, "full_name")
        self.assertEqual(user.authority, "02")
        self.assertEqual(user.status, "01")
        self.assertEqual(user.comment, "comment")
        self.assertEqual(user.create_user_id, "U0000")
        self.assertEqual(user.update_user_id, "U0000")

        user_id = user.user_id
        email = "*****@*****.**"
        first_name = "first_name3"
        last_name = "last_name3"
        full_name = "full_name3"
        authority = "03"
        status = "02"
        comment = "comment3"
        login_user_id = "U0003"

        ApplicationUserService().save_user(user_id, email, first_name,
                                           last_name, full_name, authority,
                                           status, comment, login_user_id)

        result = ApplicationUserQuery().get_user(user_id)

        self.assertEqual(result.email, "*****@*****.**")
        self.assertEqual(result.first_name, "first_name3")
        self.assertEqual(result.last_name, "last_name3")
        self.assertEqual(result.full_name, "full_name3")
        self.assertEqual(result.authority, "03")
        self.assertEqual(result.status, "02")
        self.assertEqual(result.comment, "comment3")
        self.assertEqual(result.create_user_id, "U0000")
        self.assertEqual(result.update_user_id, "U0003")

        ApplicationUserService().delete_user(user_id)

        deleted = ApplicationUserQuery().get_user(user_id)

        self.assertEqual(deleted, None)
Exemplo n.º 2
0
    def test_get_active_users_case1(self):

        result_list = ApplicationUserQuery().get_active_users()

        self.assertEqual(result_list[0].user_id, 'U0001')
        self.assertEqual(result_list[0].email, 'example1.com')
        self.assertEqual(result_list[0].first_name, 'first_name1')
        self.assertEqual(result_list[0].last_name, 'last_name1')
        self.assertEqual(result_list[0].full_name, 'first_name1 last_name1')
        self.assertEqual(result_list[0].authority, '01')
        self.assertEqual(result_list[0].status, '03')
        self.assertEqual(result_list[0].login_count, 1)
        self.assertEqual(result_list[0].comment, 'comment1')
        self.assertEqual(result_list[0].create_user_id, 'S0001')
        self.assertEqual(result_list[0].update_user_id, 'S0001')

        self.assertEqual(result_list[1].user_id, 'U0003')
        self.assertEqual(result_list[1].email, 'example3.com')
        self.assertEqual(result_list[1].first_name, 'first_name3')
        self.assertEqual(result_list[1].last_name, 'last_name3')
        self.assertEqual(result_list[1].full_name, 'first_name3 last_name3')
        self.assertEqual(result_list[1].authority, '01')
        self.assertEqual(result_list[1].status, '03')
        self.assertEqual(result_list[1].login_count, 1)
        self.assertEqual(result_list[1].comment, 'comment3')
        self.assertEqual(result_list[1].create_user_id, 'S0001')
        self.assertEqual(result_list[1].update_user_id, 'S0001')
    def test_custom_query_case4(self):

        result_list = ApplicationUserQuery().custom_query(
            '', '_name1', 0, 10, 'user-id-sort', 'False')
        self.assertEqual(result_list[0].user_id, 'U0001')
        self.assertEqual(result_list[0].email, 'example1.com')
        self.assertEqual(result_list[0].full_name, 'first_name1 last_name1')
        self.assertEqual(result_list[0].authority, '01')
        self.assertEqual(result_list[0].status, '03')
        self.assertEqual(result_list[0].login_count, 1)
 def __new__(cls, *args, **kwargs):
     cls.__new_lock.acquire()
     if cls.__singleton is None:
         cls.__singleton = super(ApplicationUserService, cls).__new__(cls)
         cls.__master_query = MasterQuery()
         cls.__application_user_query = ApplicationUserQuery()
         cls.__application_user_repository = ApplicationUserRepository()
         cls.__numberingmasterquery = NumberingMasterQuery()
     cls.__new_lock.release()
     return cls.__singleton
Exemplo n.º 5
0
def __search(
        request,
        email,
        full_name,
        target_sort_item,
        target_descending_order):

    offset = 0

    result_list_count = ApplicationUserQuery().custom_count(email, full_name)
    result_list = ApplicationUserQuery().custom_query(
        email,
        full_name,
        offset,
        __limit,
        target_sort_item,
        target_descending_order)

    authority_dictionary = MasterQuery().get_authority_dictionary()
    user_status_dictionary = MasterQuery().get_user_status_dictionary()

    request.session['email'] = email
    request.session['full_name'] = full_name
    request.session['current_sort_item'] = target_sort_item
    request.session['current_descending_order'] = target_descending_order

    context = {
        'result_list': result_list,
        'result_list_count': result_list_count,
        'authority_dictionary': authority_dictionary,
        'user_status_dictionary': user_status_dictionary,
        'current_sort_item': target_sort_item,
        'current_descending_order': target_descending_order,
        'current_page': offset + 1,
        'limit': __limit
    }

    html = render_to_string(
        'student/userm/search_result.html',
        context,
        request=request)
    return HttpResponse(html)
Exemplo n.º 6
0
 def __new__(cls, *args, **kwargs):
     cls.__new_lock.acquire()
     if cls.__singleton is None:
         cls.__singleton = super(LoginService, cls).__new__(cls)
         cls.__master_query = MasterQuery()
         cls.__application_user_query = ApplicationUserQuery()
         cls.__application_user_repository = ApplicationUserRepository()
         cls.__temporarily_login_url_query = TemporarilyLoginUrlQuery()
         cls.__temporarily_login_url_repository = TemporarilyLoginUrlRepository(
         )
     cls.__new_lock.release()
     return cls.__singleton
Exemplo n.º 7
0
def __paging(request, current_page, previous, next, target_page):

    offset, target_page = function.get_offset(
        previous, next, target_page, current_page, __limit)

    email = request.session['email']
    full_name = request.session['full_name']
    current_sort_item = request.session['current_sort_item']
    current_descending_order = request.session['current_descending_order']

    result_list_count = ApplicationUserQuery().custom_count(email, full_name)
    result_list = ApplicationUserQuery().custom_query(
        email,
        full_name,
        offset,
        __limit,
        current_sort_item,
        current_descending_order)

    authority_dictionary = MasterQuery().get_authority_dictionary()
    user_status_dictionary = MasterQuery().get_user_status_dictionary()

    context = {
        'result_list': result_list,
        'result_list_count': result_list_count,
        'authority_dictionary': authority_dictionary,
        'user_status_dictionary': user_status_dictionary,
        'current_page': target_page,
        'limit': __limit,
        'current_sort_item': current_sort_item,
        'current_descending_order': current_descending_order,
        'authority_name': request.session['authority']
    }

    html = render_to_string(
        'student/userm/search_result.html',
        context,
        request=request)
    return HttpResponse(html)
    def test_update_login_information(self):

        user_id = "U0002"
        email = "*****@*****.**"
        first_name = "first_name"
        last_name = "last_name"
        full_name = "full_name"
        authority = "01"
        status = "02"
        comment = "comment"
        login_user_id = "U0001"

        ApplicationUserRepository().insert(user_id, email, first_name,
                                           last_name, full_name, authority,
                                           status, comment, login_user_id)

        user = ApplicationUserQuery().get_user(user_id)

        LoginService().update_login_information(user)

        user = ApplicationUserQuery().get_user(user_id)
        self.assertEqual(user.login_count, 1)
Exemplo n.º 9
0
 def __new__(cls, *args, **kwargs):
     cls.__new_lock.acquire()
     if cls.__singleton is None:
         cls.__singleton = super(ReportService, cls).__new__(cls)
         cls.__applicationuserrquery = ApplicationUserQuery()
         cls.__numberingmasterquery = NumberingMasterQuery()
         cls.__googleapiservice = GoogleApiService()
         cls.__reportrepository = ReportRepository()
         cls.__reportquery = ReportQuery()
         cls.__downloadinformationrepository = DownloadInformationRepository()
         cls.__downloadinformationquery = DownloadInformationQuery()
     cls.__new_lock.release()
     return cls.__singleton
Exemplo n.º 10
0
    def test_get_user_case1(self):

        result = ApplicationUserQuery().get_user('U0001')
        self.assertEqual(result.user_id, 'U0001')
        self.assertEqual(result.email, 'example1.com')
        self.assertEqual(result.first_name, 'first_name1')
        self.assertEqual(result.last_name, 'last_name1')
        self.assertEqual(result.full_name, 'first_name1 last_name1')
        self.assertEqual(result.authority, '01')
        self.assertEqual(result.status, '03')
        self.assertEqual(result.login_count, 1)
        self.assertEqual(result.comment, 'comment1')
        self.assertEqual(result.create_user_id, 'S0001')
        self.assertEqual(result.update_user_id, 'S0001')
Exemplo n.º 11
0
def update(request):

    form = UserIdForm(data=request.POST)

    if form.is_valid():
        user_id = form.cleaned_data['user_id']

        user = ApplicationUserQuery().get_user(user_id)

        context = {
            'user': user,
            'authority_taples': MasterQuery().get_authority_taples(),
            'user_status_taples': MasterQuery().get_user_status_taples()
        }

        html = render_to_string('student/userm/update.html',
                                context=context,
                                request=request)
        return HttpResponse(html)
    else:
        return None
Exemplo n.º 12
0
    def test_is_active_user_case2(self):

        result = ApplicationUserQuery().is_active_user('example2.com')
        self.assertEqual(result, False)
    def test_custom_count_case1(self):

        result = ApplicationUserQuery().custom_count('xample', 'name')
        self.assertEqual(result, 3)
Exemplo n.º 14
0
    def test_get_user_case2(self):

        result = ApplicationUserQuery().get_user('example999.com')
        self.assertEqual(result, None)
    def test_custom_count_case4(self):

        result = ApplicationUserQuery().custom_count('aaa', 'aaa')
        self.assertEqual(result, 0)
Exemplo n.º 16
0
    def test_is_exist_same_full_name_case2(self):

        result = ApplicationUserQuery().is_exist_same_full_name(
            'first_name9 last_name9')
        self.assertEqual(result, False)
Exemplo n.º 17
0
    def test_is_exist_same_full_name_case1(self):

        result = ApplicationUserQuery().is_exist_same_full_name(
            'first_name1 last_name1')
        self.assertEqual(result, True)
Exemplo n.º 18
0
    def test_is_exist_same_email_case2(self):

        result = ApplicationUserQuery().is_exist_same_email('example999.com')
        self.assertEqual(result, False)
    def test_custom_count_case5(self):

        result = ApplicationUserQuery().custom_count('xample1', '')
        self.assertEqual(result, 1)
Exemplo n.º 20
0
def __is_exist_same_email(user, email):

    if (user is None or user.email != email):
        return ApplicationUserQuery().is_exist_same_email(email)
Exemplo n.º 21
0
    def test_is_active_user_case1(self):

        result = ApplicationUserQuery().is_active_user('example1.com')
        self.assertEqual(result, True)
    def test_custom_query_case7(self):

        result_list = ApplicationUserQuery().custom_query(
            'aaa', 'aaa', 0, 10, 'user-id-sort', 'False')
        self.assertEqual(result_list, [])
    def test_custom_count_case7(self):

        result = ApplicationUserQuery().custom_count('', '')
        self.assertEqual(result, 3)
Exemplo n.º 24
0
    def test_is_exist_user_case1(self):

        result = ApplicationUserQuery().is_exist_user('U0001')
        self.assertEqual(result, True)
Exemplo n.º 25
0
    def test_is_exist_user_case2(self):

        result = ApplicationUserQuery().is_exist_user('U9999')
        self.assertEqual(result, False)
Exemplo n.º 26
0
def __is_exist_same_full_name(user, full_name):

    if (user is None or user.full_name != full_name):
        return ApplicationUserQuery().is_exist_same_email(full_name)
Exemplo n.º 27
0
    def test_is_exist_same_email_case1(self):

        result = ApplicationUserQuery().is_exist_same_email('example1.com')
        self.assertEqual(result, True)
Exemplo n.º 28
0
def save_user(request):

    form = UserSaveForm(data=request.POST)
    json_data = None

    if form.is_valid():
        user_id = form.cleaned_data['user_id']
        email = form.cleaned_data['email']
        first_name = form.cleaned_data['first_name']
        last_name = form.cleaned_data['last_name']
        full_name = first_name + ' ' + last_name
        authority = form.cleaned_data['authority']
        status = form.cleaned_data['status']
        comment = form.cleaned_data['comment']
        login_user_id = request.session['user_id']

        user = None
        if (user_id != ''):
            user = ApplicationUserQuery().get_user(user_id)

        if (__is_exist_same_email(user, email)):
            json_data = {
                'data': {
                    'result': 'false',
                    'errorMessage': 'Already same email exist.',
                    'errorItem': 'email-area'
                }
            }
            return JsonResponse(json_data)

        if (__is_exist_same_full_name(user, full_name)):
            json_data = {
                'data': {
                    'result': 'false',
                    'errorMessage': 'Already same name user exist.',
                    'errorItem': 'fisrt_name'
                }
            }
            return JsonResponse(json_data)

        user_id = ApplicationUserService().save_user(user_id, email,
                                                     first_name, last_name,
                                                     full_name, authority,
                                                     status, comment,
                                                     login_user_id)

        if (user_id is not None):
            json_data = {'data': {'result': 'true', 'message': 'Success'}}
            return JsonResponse(json_data)

    else:

        error_message, error_item = __get_error_infomations(form)

        json_data = {
            'data': {
                'result': 'false',
                'errorMessage': error_message,
                'errorItem': error_item
            }
        }

    return JsonResponse(json_data)
    def test(self):

        user_id = "U0002"
        email = "*****@*****.**"
        first_name = "first_name"
        last_name = "last_name"
        full_name = "full_name"
        authority = "01"
        status = "02"
        comment = "comment"
        login_user_id = "U0001"

        ApplicationUserRepository().insert(user_id, email, first_name,
                                           last_name, full_name, authority,
                                           status, comment, login_user_id)

        user = ApplicationUserQuery().get_user(user_id)

        self.assertEqual(user.email, "*****@*****.**")
        self.assertEqual(user.first_name, "first_name")
        self.assertEqual(user.last_name, "last_name")
        self.assertEqual(user.full_name, "full_name")
        self.assertEqual(user.authority, "01")
        self.assertEqual(user.status, "02")
        self.assertEqual(user.comment, "comment")
        self.assertEqual(user.create_user_id, "U0001")
        self.assertEqual(user.update_user_id, "U0001")

        user.email = "*****@*****.**"
        user.first_name = "first_name3"
        user.last_name = "last_name3"
        user.full_name = "full_name3"
        user.authority = "03"
        user.status = "04"
        user.comment = "comment3"
        user.update_user_id = "U0003"

        ApplicationUserRepository().update(user)

        result = ApplicationUserQuery().get_user("U0002")

        self.assertEqual(result.email, "*****@*****.**")
        self.assertEqual(result.first_name, "first_name3")
        self.assertEqual(result.last_name, "last_name3")
        self.assertEqual(result.full_name, "full_name3")
        self.assertEqual(result.authority, "03")
        self.assertEqual(result.status, "04")
        self.assertEqual(result.comment, "comment3")
        self.assertEqual(result.create_user_id, "U0001")
        self.assertEqual(result.update_user_id, "U0003")

        ApplicationUserRepository().delete(result)

        deleted = ApplicationUserQuery().get_user("U0002")

        self.assertEqual(deleted, None)