Esempio n. 1
0
    def test_insert_success(self):
        account = AccountFactory.build()
        db.session.add(account)
        db.session.commit()

        obj = Account.query.first()
        self.assertIsNotNone(obj)
Esempio n. 2
0
    def test_account_create_success(self):
        account_exist = AccountFactory.create(id=10)
        access_token = create_access_token(account_exist.email)

        account = AccountFactory.build()
        al = account_schema.dump(account)
        data = al.data
        data.pop('id')
        data['password'] = '******'
        response = self.client.post('/api/v1/accounts',
                                    data=json.dumps(al.data),
                                    headers={
                                        'Content-Type': 'application/json',
                                        'Authorization':
                                        'Bearer ' + access_token
                                    })

        self.assertEqual(response.status_code, http.HTTPStatus.CREATED.value)
Esempio n. 3
0
    def test_accounts_list(self):
        accounts = [AccountFactory.create() for _ in range(3)]
        access_token = create_access_token(accounts[0].email)
        response = self.client.get(
            '/api/v1/accounts',
            headers={'Authorization': 'Bearer ' + access_token})

        self.assert200(response)
        self.assertEqual(len(response.json), 3)
Esempio n. 4
0
    def test_account_delete_success(self):
        account = AccountFactory.create()
        access_token = create_access_token(account.email)
        response = self.client.delete(
            '/api/v1/accounts/{}'.format(account.id),
            headers={'Authorization': 'Bearer ' + access_token})

        self.assertEqual(response.status_code, 204)
        al = Account.query.get(account.id)
        self.assertIsNone(al)
Esempio n. 5
0
    def test_account_get_success(self):
        account = AccountFactory.create()
        access_token = create_access_token(account.email)
        response = self.client.get(
            '/api/v1/accounts/{}'.format(account.id),
            headers={'Authorization': 'Bearer ' + access_token})

        self.assert200(response)
        self.assertIn('id', response.json)
        self.assertIn('email', response.json)
Esempio n. 6
0
    def test_login_success(self):
        account = AccountFactory.create()
        refresh_token = create_refresh_token(account.email)

        response = self.client.post(
            '/api/v1/refresh', data=json.dumps({}),
            headers={'Content-Type': 'application/json',
                     'Authorization': 'Bearer ' + refresh_token})

        self.assertEqual(response.status_code, http.HTTPStatus.CREATED.value)
        self.assertIn('access_token', response.json)
Esempio n. 7
0
    def test_account_update_success(self):
        account = AccountFactory.create()
        access_token = create_access_token(account.email)

        account_new = AccountFactory.build()
        al = account_schema.dump(account_new)
        data = al.data
        data.pop('id')
        data['password'] = '******'

        response = self.client.put('/api/v1/accounts/{}'.format(account.id),
                                   data=json.dumps(data),
                                   headers={
                                       'Content-Type': 'application/json',
                                       'Authorization':
                                       'Bearer ' + access_token
                                   })

        self.assert200(response)
        self.assertEqual(response.json['name'], data['name'])
    def test_login_success(self):
        account = AccountFactory.create(password='******')
        response = self.client.post(
            '/api/v1/login',
            data=json.dumps({
                'email': account.email,
                'password': '******'
            }),
            headers={'Content-Type': 'application/json'})

        self.assertEqual(response.status_code, http.HTTPStatus.CREATED.value)
        self.assertIn('access_token', response.json)
        self.assertIn('refresh_token', response.json)
Esempio n. 9
0
    def test_login_success(self):
        account = AccountFactory.create()

        access_token = create_access_token(account.email)
        refresh_token = create_refresh_token(account.email)

        response = self.client.post(
            '/api/v1/logout',
            data=json.dumps({'refresh_token': refresh_token}),
            headers={
                'Content-Type': 'application/json',
                'Authorization': 'Bearer ' + access_token
            })

        self.assert200(response)