示例#1
0
    def test_get_user_not_found(self):
        """GETの異常系(not found)"""
        User.objects.all().delete()

        request = factory.get('/users')
        get_users = UserView.as_view()
        response = get_users(request)

        self.assertEqual(response.status_code, 404)
示例#2
0
    def test_get_user_bad_request(self):
        """GETの異常系(bad request)"""

        User.objects.all().delete()

        request = factory.get('/users/{}'.format("1" * 29))
        get_users = UserView.as_view()
        response = get_users(request)

        self.assertEqual(response.status_code, 404)
示例#3
0
    def test_get_user_not_found(self):
        """GETの異常系(not found)"""

        obj = User.objects.get(user_name='ユーザ3')
        User.objects.all().delete()

        request = factory.get('/users/{}'.format(obj.user_id))
        get_users = UserView.as_view()
        response = get_users(request)

        self.assertEqual(response.status_code, 404)
示例#4
0
    def test_post_user_mail_address_not_exist(self):
        """POST異常系(bodyにmail_addressが存在しない)"""
        body = {
            'user_name': 'ユーザ4',
        }

        request = factory.post('/users', data=body, format='json')
        post_user = UserView.as_view()
        response = post_user(request)

        self.assertEqual(response.status_code, 400)
示例#5
0
    def test_post_user_duplicate(self):
        """POST異常系(ユーザ名重複、メールアドレス重複)"""
        body = {
            'user_name': 'ユーザ1',
            'mail_address': '*****@*****.**'
        }

        request = factory.post('/users', data=body, format='json')
        post_user = UserView.as_view()
        response = post_user(request)

        self.assertEqual(response.status_code, 400)

        body = {
            'user_name': 'ユーザ5',
            'mail_address': '*****@*****.**'
        }

        request = factory.post('/users', data=body, format='json')
        post_user = UserView.as_view()
        response = post_user(request)

        self.assertEqual(response.status_code, 400)
示例#6
0
    def test_get_user_success(self):
        """GETの正常系"""
        request = factory.get('/users')
        get_users = UserView.as_view()
        response = get_users(request)
        data = response.data.values()

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(data), 2)
        record1 = data.get(user_name='ユーザ1')
        self.assertTrue("1"*28, str(record1['user_id']))
        self.assertEqual('ユーザ1', record1['user_name'])
        self.assertEqual(False, record1['authority'])
        self.assertEqual(None, record1['correct_answer_rate'])
        self.assertEqual(False, record1['is_deleted'])
        self.assertEqual(type(datetime.datetime.today()), type(record1['create_date']))
        self.assertEqual(type(datetime.datetime.today()), type(record1['update_date']))
示例#7
0
    def test_get_user_success(self):
        """GETの正常系"""

        obj = User.objects.get(user_name='ユーザ3')

        request = factory.get('/users/{}'.format(obj.user_id))
        get_users = UserView.as_view()
        response = get_users(request)
        data = response.data.values()

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(data), 2)
        record = data.get(user_name='ユーザ3')
        self.assertTrue("1" * 28, str(record['user_id']))
        self.assertEqual('ユーザ3', record['user_name'])
        self.assertEqual('*****@*****.**', record['mail_address'])
        self.assertEqual(False, record['authority'])
        self.assertEqual(0, record['challenge_count'])
        self.assertEqual(False, record['is_deleted'])
        self.assertEqual(type(datetime.datetime.today()), type(record['create_date']))
        self.assertEqual(type(datetime.datetime.today()), type(record['update_date']))
示例#8
0
    def test_post_user_success(self):
        """POST正常系"""
        body = {
            'user_id': "4" * 28,
            'user_name': 'ユーザ4',
            'mail_address': '*****@*****.**'
        }

        request = factory.post('/users', data=body, format='json')
        post_user = UserView.as_view()
        response = post_user(request)

        obj = User.objects.get(user_name='ユーザ4')
        self.assertEqual(response.status_code, 204)
        self.assertTrue("4" * 28, str(obj.user_id))
        self.assertEqual('ユーザ4', obj.user_name)
        self.assertEqual('*****@*****.**', obj.mail_address)
        self.assertEqual(False, obj.authority)
        self.assertEqual(None, obj.correct_answer_rate)
        self.assertEqual(False, obj.is_deleted)
        self.assertEqual(type(datetime.datetime.today()), type(obj.create_date))
        self.assertEqual(type(datetime.datetime.today()), type(obj.update_date))