示例#1
0
def create_users_and_roles():
    role_customer = Role(name="CUSTOMER").save()
    role_admin = Role(name="ADMIN").save()

    user = User(first_name='First',
                last_name='Last',
                birth_date=datetime.date.today(),
                email='*****@*****.**',
                password='******',
                phone='4988888').save()

    user.roles.append(role_customer);
    user.save()

    admin = User(first_name='User',
                 last_name='Theuser',
                 birth_date=datetime.date.today(),
                 email='*****@*****.**',
                 password='******',
                 phone='4988888').save()
    admin.roles.append(role_admin)
    admin.save()

    second_user = User(first_name='My User',
                       last_name='Van Gogh',
                       birth_date=datetime.date.today(),
                       email='*****@*****.**',
                       password='******',
                       phone='4988888').save()
    second_user.roles.append(role_customer)
示例#2
0
def create_users_and_roles():
    role_customer = Role(name="CUSTOMER").save()
    role_admin = Role(name="ADMIN").save()

    user = User(first_name='First',
                last_name='Last',
                birth_date=datetime.date.today(),
                email='*****@*****.**',
                password='******',
                phone='4988888').save()

    user.roles.append(role_customer)
    user.save()

    admin = User(first_name='User',
                 last_name='Theuser',
                 birth_date=datetime.date.today(),
                 email='*****@*****.**',
                 password='******',
                 phone='4988888').save()
    admin.roles.append(role_admin)
    admin.save()

    second_user = User(first_name='My User',
                       last_name='Van Gogh',
                       birth_date=datetime.date.today(),
                       email='*****@*****.**',
                       password='******',
                       phone='4988888').save()
    second_user.roles.append(role_customer)
示例#3
0
 def test_delete_user(self):
     user = User(first_name='First',
                 last_name='Last',
                 birth_date=datetime.date.today(),
                 email='*****@*****.**',
                 password='******',
                 phone='4988888')
     user.save()
     response = self.client.delete('/api/users/'+str(user.id))
     self.assertStatus(response, 204)
示例#4
0
 def test_delete_user(self):
     user = User(first_name='First',
                 last_name='Last',
                 birth_date=datetime.date.today(),
                 email='*****@*****.**',
                 password='******',
                 phone='4988888')
     user.save()
     response = self.client.delete('/api/users/' + str(user.id))
     self.assertStatus(response, 204)
示例#5
0
 def test_get_user(self):
     user = User(first_name='First',
                 last_name='Last',
                 birth_date=datetime.date.today(),
                 email='*****@*****.**',
                 password='******',
                 phone='4988888')
     user.save()
     response = self.client.get('/api/users/'+str(user.id))
     self.assertStatus(response, 200)
     self.assertEqual(response.json['first_name'], 'First')
示例#6
0
 def test_get_user(self):
     user = User(first_name='First',
                 last_name='Last',
                 birth_date=datetime.date.today(),
                 email='*****@*****.**',
                 password='******',
                 phone='4988888')
     user.save()
     response = self.client.get('/api/users/' + str(user.id))
     self.assertStatus(response, 200)
     self.assertEqual(response.json['first_name'], 'First')
示例#7
0
 def test_put_user(self):
     user = User(first_name='First',
                 last_name='Last',
                 birth_date=datetime.date.today(),
                 email='*****@*****.**',
                 password='******',
                 phone='4988888')
     user.save()
     user.first_name = 'UpdateFirstName'
     response = self.client.put('/api/users/'+str(user.id), data=json.dumps(user.to_dict()), content_type='application/json')
     self.assertStatus(response, 200)
     self.assertEqual(response.json['first_name'], 'UpdateFirstName')
示例#8
0
 def test_put_user(self):
     user = User(first_name='First',
                 last_name='Last',
                 birth_date=datetime.date.today(),
                 email='*****@*****.**',
                 password='******',
                 phone='4988888')
     user.save()
     user.first_name = 'UpdateFirstName'
     response = self.client.put('/api/users/' + str(user.id),
                                data=json.dumps(user.to_dict()),
                                content_type='application/json')
     self.assertStatus(response, 200)
     self.assertEqual(response.json['first_name'], 'UpdateFirstName')
示例#9
0
    def test_post_user_integrity_check(self):
        user = User(first_name='First',
                    last_name='Last',
                    birth_date=datetime.date.today(),
                    email='*****@*****.**',
                    password='******',
                    phone='4988888')
        user.save()
        user_ = {'first_name': 'First',
                 'last_name': 'Last',
                 'birth_date': datetime.date.today().isoformat(),
                 'email': '*****@*****.**',
                 'password': '******',
                 'phone': '4988888'}

        json_user = json.dumps(user_)
        response = self.client.post('/api/users', data=json_user, content_type='application/json')
        self.assert400(response)
示例#10
0
    def test_login_logout_user(self):
        user = User(first_name='First',
                    last_name='Last',
                    birth_date=datetime.date.today(),
                    email='*****@*****.**',
                    password='******',
                    phone='4988888')
        user.save()
        user_ = {'email': '*****@*****.**',
                 'password': '******'}

        json_user = json.dumps(user_)
        response = self.client.post('/api/users/login', data=json_user, content_type='application/json')
        self.assertStatus(response, 200)
        self.assertEqual(1, response.json['login_count'])

        response = self.client.post('/api/users/logout', data=json.dumps({'user_id': response.json['id']}),
                                    content_type='application/json')
        self.assertStatus(response, 200)
        self.assertEqual('OK', response.json['status'])
示例#11
0
    def test_post_user_integrity_check(self):
        user = User(first_name='First',
                    last_name='Last',
                    birth_date=datetime.date.today(),
                    email='*****@*****.**',
                    password='******',
                    phone='4988888')
        user.save()
        user_ = {
            'first_name': 'First',
            'last_name': 'Last',
            'birth_date': datetime.date.today().isoformat(),
            'email': '*****@*****.**',
            'password': '******',
            'phone': '4988888'
        }

        json_user = json.dumps(user_)
        response = self.client.post('/api/users',
                                    data=json_user,
                                    content_type='application/json')
        self.assert400(response)
示例#12
0
    def test_login_logout_user(self):
        user = User(first_name='First',
                    last_name='Last',
                    birth_date=datetime.date.today(),
                    email='*****@*****.**',
                    password='******',
                    phone='4988888')
        user.save()
        user_ = {'email': '*****@*****.**', 'password': '******'}

        json_user = json.dumps(user_)
        response = self.client.post('/api/users/login',
                                    data=json_user,
                                    content_type='application/json')
        self.assertStatus(response, 200)
        self.assertEqual(1, response.json['login_count'])

        response = self.client.post('/api/users/logout',
                                    data=json.dumps(
                                        {'user_id': response.json['id']}),
                                    content_type='application/json')
        self.assertStatus(response, 200)
        self.assertEqual('OK', response.json['status'])