Esempio n. 1
0
 def test_new_role(self):
     role_id = Role.get_max_id()
     self.login()
     url = url_for('auth.new_role', _external=True)
     data = {
         'name': 'test_role',
         'description': 'Test Role',
         'role_group_id': 1,
         'role_group_name':
         RoleGroup.get_by(id=RoleGroup.get_max_id()).name,
     }
     response = self.client.post(
         url,
         content_type=self.JSON,
         headers=self.set_api_headers(token=self.auth_token),
         data=json.dumps(data),
     )
     response.json = self.get_json_response(response)
     new_item = Role.get_by(name=data['name'])
     item_url = url_for('auth.get_role',
                        item_id=new_item.id,
                        _external=True)
     self.assertEqual(response.status_code, 201)
     self.assertTrue(response.json['data']['url'] == item_url)
     self.assertEqual(new_item.role_group.id, 1)
     Role.set_sequence_value(value=role_id)
     db.session.delete(new_item)
     db.session.commit()
Esempio n. 2
0
 def test_edit_role_groups(self):
     self.login()
     role_group = RoleGroup.get_by(name='admin')
     url = url_for('auth.edit_role_group',
                   item_id=role_group.id,
                   _external=True)
     data = {
         'name': "".join([role_group.name, '_edited']),
         'description': "".join([role_group.description, '_edited']),
     }
     response = self.client.put(
         url,
         content_type=self.JSON,
         headers=self.set_api_headers(token=self.auth_token),
         data=json.dumps(data),
     )
     response.json = self.get_json_response(response)
     self.assertEqual(response.status_code, 200)
     item_url = url_for('auth.get_role_group',
                        item_id=role_group.id,
                        _external=True)
     self.assertTrue(response.json['data']['url'] == item_url)
     role_group.name, _ = role_group.name.split('_')
     role_group.description, _ = role_group.description.split('_')
     db.session.commit()
Esempio n. 3
0
 def test_edit_role_exiting_role_groups(self):
     self.login()
     role_group = RoleGroup.get_by(name='admin')
     another_role_group = RoleGroup.get_by(name='user')
     url = url_for('auth.edit_role_group',
                   item_id=role_group.id,
                   _external=True)
     data = {
         'name': another_role_group.name,
         'description': another_role_group.description,
     }
     response = self.client.put(
         url,
         content_type=self.JSON,
         headers=self.set_api_headers(token=self.auth_token),
         data=json.dumps(data),
     )
     response.json = self.get_json_response(response)
     self.assertEqual(response.status_code, 400)
     self.assertTrue(response.json['error'] == 'bad request')
Esempio n. 4
0
 def test_delete_role_group(self):
     self.login()
     role_group = RoleGroup.get_by(name='user')
     url = url_for('auth.delete_role_group',
                   item_id=role_group.id,
                   _external=True)
     response = self.client.delete(
         url,
         content_type=self.JSON,
         headers=self.set_api_headers(token=self.auth_token),
     )
     self.assertEqual(response.status_code, 204)
     role_group.set_not_erased()