예제 #1
0
 def test_new_role_groups(self):
     role_group_id = RoleGroup.get_max_id()
     self.login()
     url = url_for('auth.new_role_group', _external=True)
     data = {
         'name': 'test_role_group',
         'description': 'Test Role Group',
     }
     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 = RoleGroup.get_by(name=data['name'])
     item_url = url_for('auth.get_role_group',
                        item_id=new_item.id,
                        _external=True)
     RoleGroup.set_sequence_value(value=new_item.id - 1)
     self.assertEqual(response.status_code, 201)
     self.assertTrue(response.json['data']['url'] == item_url)
     db.session.delete(new_item)
     db.session.commit()
     RoleGroup.set_sequence_value(value=role_group_id)
예제 #2
0
 def test_new_role_groups_existing_role_groups(self):
     max_id = RoleGroup.get_max_id()
     self.login()
     url = url_for('auth.new_role_group', _external=True)
     data = {
         'name': 'admin',
         'description': 'System Administrators',
     }
     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)
     self.assertEqual(response.status_code, 400)
     self.assertTrue(response.json['error'] == 'bad request')
     RoleGroup.set_sequence_value(value=max_id)