Repository: fossasia/open-event-server

Issue:
Adding dredd tests for custom system roles
**Is your feature request related to a problem? Please describe.**
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
add dredd tests for custom system roles

**Describe the solution you'd like**
<!-- A clear and concise description of what you want to happen. -->

**Describe alternatives you've considered**
<!-- A clear and concise description of any alternative solutions or features you've considered. -->

**Additional context**
<!-- Add any other context or screenshots about the feature request here. -->
I'm working on it!


Discussion:

Resolving patch:
diff --git a/app/factories/custom_system_role.py b/app/factories/custom_system_role.py
new file mode 100644
--- /dev/null
+++ b/app/factories/custom_system_role.py
@@ -0,0 +1,12 @@
+import factory
+
+import app.factories.common as common
+from app.models.custom_system_role import db, CustomSysRole
+
+
+class CustomSysRoleFactory(factory.alchemy.SQLAlchemyModelFactory):
+    class Meta:
+        model = CustomSysRole
+        sqlalchemy_session = db.session
+
+    name = common.string_
diff --git a/app/factories/panel_permission.py b/app/factories/panel_permission.py
new file mode 100644
--- /dev/null
+++ b/app/factories/panel_permission.py
@@ -0,0 +1,14 @@
+import factory
+
+import app.factories.common as common
+from app.models.panel_permission import db, PanelPermission
+
+
+class PanelPermissionFactory(factory.alchemy.SQLAlchemyModelFactory):
+    class Meta:
+        model = PanelPermission
+        sqlalchemy_session = db.session
+
+    panel_name = common.string_
+    custom_system_role = common.string_
+    can_access = True


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -14,6 +14,9 @@
 from populate_db import populate_without_print
 
 # imports from factories
+
+from app.factories.custom_system_role import CustomSysRoleFactory
+from app.factories.panel_permission import PanelPermissionFactory
 from app.factories.user import UserFactory
 from app.factories.notification_action import NotificationActionFactory
 from app.factories.notification import NotificationFactory
@@ -4157,3 +4160,84 @@ def reset_password_patch(transaction):
         user.reset_password = 'token'
         db.session.add(user)
         db.session.commit()
+
+
+# ------------------------- Custom System Role -------------------------
+
+@hooks.before("Custom System Roles > Custom System Roles Collection > List All Custom System Roles")
+def custom_system_roles_get_list(transaction):
+    """
+    GET /custom-system-roles
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        custom_system_role = CustomSysRoleFactory()
+        db.session.add(custom_system_role)
+        db.session.commit()
+
+
+@hooks.before("Custom System Roles > Custom System Roles Collection > Create Custom System Role")
+def custom_system_roles_post(transaction):
+    """
+    POST /custom-system-roles
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        custom_system_role = CustomSysRoleFactory()
+        db.session.add(custom_system_role)
+        db.session.commit()
+
+
+@hooks.before("Custom System Roles > Custom System Roles Details > Get Details")
+def custom_system_role_get_detail(transaction):
+    """
+    GET /custom-system-roles/2
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        custom_system_role = CustomSysRoleFactory()
+        db.session.add(custom_system_role)
+        db.session.commit()
+
+
+@hooks.before("Custom System Roles > Custom System Roles Details > Update Custom System Role")
+def custom_system_role_patch(transaction):
+    """
+    PATCH /custom-system-roles/2
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        custom_system_role = CustomSysRoleFactory()
+        db.session.add(custom_system_role)
+        db.session.commit()
+
+
+@hooks.before("Custom System Roles > Custom System Roles Details > Delete Custom System Role")
+def custom_system_role_delete(transaction):
+    """
+    DELETE /custom-system-roles/2
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        custom_system_role = CustomSysRoleFactory()
+        db.session.add(custom_system_role)
+        db.session.commit()
+
+
+@hooks.before("Custom System Roles > Custom System Role Details for a Panel Permission >"
+                " Custom System Role Details for a Panel Permission")
+def custom_system_roles_panel_permission(transaction):
+    """
+    GET /panel-permissions/1/custom-system-roles
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        panel_permission = PanelPermissionFactory()
+        db.session.add(panel_permission)
+        db.session.commit()