def test_invitationsiterole_delete(self):
        data = {
            "site_id": self.site_model.id,
            "role_id": self.role_model.id,
            "invitation_id": self.invitation_model.id
        }
        invitation_site_role = db_actions.crud(model="InvitationSiteRole",
                                               api_model=InvitationSiteRole,
                                               data=data,
                                               action="create")

        with self.assertRaises(werkzeug.exceptions.NotFound):
            response = self.client.open(
                '/api/v1/invitationsiteroles/{invitation_id}/{site_id}/{role_id}'
                .format(
                    invitation_id=invitation_site_role.invitation_id,
                    site_id=invitation_site_role.site_id,
                    role_id=invitation_site_role.role_id,
                ),
                method='DELETE',
                headers=self.headers)

            db_actions.crud(model="InvitationSiteRole",
                            api_model=InvitationSiteRole,
                            action="read",
                            query={
                                "role_id": invitation_site_role.role_id,
                                "site_id": invitation_site_role.site_id,
                                "invitation_id":
                                invitation_site_role.invitation_id
                            })
    def test_adminnote_delete(self):
        """
        Test case for adminnote_delete

        """
        data = {
            "creator_id": "%s" % uuid.uuid1(),
            "note": "This is text",
            "user_id": "%s" % uuid.uuid1(),
        }
        model = db_actions.crud(model="AdminNote",
                                api_model=AdminNote,
                                data=data,
                                action="create")

        response = self.client.open(
            '/api/v1/adminnotes/{id}'.format(id=model.id),
            method='DELETE',
            headers=self.headers)

        with self.assertRaises(werkzeug.exceptions.NotFound):
            db_actions.crud(model="AdminNote",
                            api_model=AdminNote,
                            action="read",
                            query={"id": model.id})
 def test_domain_update(self):
     """Test case for domain_update
     """
     data = {
         "name": ("%s" % uuid.uuid1())[:30],
         "description": "Domain to update",
     }
     model = db_actions.crud(model="Domain",
                             api_model=Domain,
                             data=data,
                             action="create")
     data = {
         "name": ("%s" % uuid.uuid1())[:30],
         "description": "Domain updated",
     }
     data = DomainUpdate(**data)
     response = self.client.open(
         '/api/v1/domains/{domain_id}'.format(domain_id=model.id),
         method='PUT',
         data=json.dumps(data),
         content_type='application/json',
         headers=self.headers)
     r_data = json.loads(response.data)
     updated_entry = db_actions.crud(model="Domain",
                                     api_model=Domain,
                                     action="read",
                                     query={"id": model.id})
     self.assertEqual(r_data["name"], updated_entry.name)
     self.assertEqual(r_data["description"], updated_entry.description)
Exemplo n.º 4
0
    def setUp(self):
        super().setUp()
        self.domain_model = db_actions.crud(
            model="Domain",
            api_model=Domain,
            data={
                "name": "TestDomain",
                "description": "A test domain"
            },
            action="create"
        )
        self.site_model = db_create_entry(
            model="Site",
            data={
                "name": "TestSite",
                "domain_id": self.domain_model.id,
                "description": "A test site",
            },
        )
        self.credentials_data = {
            "site_id": self.site_model.id,
            "account_id": "accountid".rjust(32, "0"),
            "account_secret": "accountsecret".rjust(32, "0"),
            "description": "Super cool test credentials",
        }
        self.credentials_model = db_actions.crud(
            model="Credentials",
            api_model=Credentials,
            data=self.credentials_data,
            action="create"
        )

        self.headers = {API_KEY_HEADER: "test-api-key"}
Exemplo n.º 5
0
    def test_delete_user_data_adminnote(self):
        user_id = "%s" % uuid.uuid1()
        for index in range(1, 30):
            adminnote_data = {
                "creator_id": "%s" % uuid.uuid1(),
                "note": "This is text %s" % index,
                "user_id": user_id,
            }
            db_actions.crud(model="AdminNote",
                            api_model=AdminNoteCreate,
                            data=adminnote_data,
                            action="create")

        response = self.client.open('/api/v1/users/{user_id}/delete'.format(
            user_id=user_id, ),
                                    method='GET',
                                    headers=self.headers)

        with self.assertRaises(werkzeug.exceptions.NotFound):
            db_actions.crud(model="AdminNote",
                            api_model=AdminNote,
                            action="read",
                            query={
                                "user_id": user_id,
                            })
        response_data = json.loads(response.data)
        self.assertEqual(response_data["amount"], 29)
Exemplo n.º 6
0
    def setUp(self):
        super().setUp()
        self.role_data = {
            "label": ("%s" % uuid.uuid1())[:30],
            "description": "domain_role to create",
        }
        self.role_model = db_actions.crud(
            model="Role",
            api_model=Role,
            data=self.role_data,
            action="create"
        )
        self.domain_data = {
            "name": ("%s" % uuid.uuid1())[:30],
            "description": "domain to create",
        }
        self.domain_model = db_actions.crud(
            model="Domain",
            api_model=Domain,
            data=self.domain_data,
            action="create"
        )

        self.domain_role_data = {
            "role_id": self.role_model.id,
            "domain_id": self.domain_model.id,
        }
        self.domain_role_model = db_actions.crud(
            model="DomainRole",
            api_model=DomainRole,
            data=self.domain_role_data,
            action="create"
        )
        self.headers = {API_KEY_HEADER: "test-api-key"}
Exemplo n.º 7
0
    def test_credentials_delete(self):
        """Test case for credentials_delete
        """
        data = {
            "site_id": self.site_model.id,
            "account_id": "accountid2".rjust(32, "0"),
            "account_secret": "accountsecret2".rjust(32, "0"),
            "description": "Super cool test credentials 2",
        }
        model = db_actions.crud(
            model="Credentials",
            api_model=Credentials,
            data=data,
            action="create"
        )
        response = self.client.open(
            '/api/v1/credentials/{credentials_id}'.format(credentials_id=model.id),
            method='DELETE', headers=self.headers)

        with self.assertRaises(werkzeug.exceptions.NotFound):
            db_actions.crud(
                model="Credentials",
                api_model=Credentials,
                action="read",
                query={"id": model.id}
            )
    def test_invitation_delete(self):
        """Test case for invitation_delete
        """
        data = {
            "first_name": "first",
            "last_name": "last",
            "email": "*****@*****.**",
            "organisation_id": 1,
            "invitor_id": "%s" % uuid.uuid1(),
            "expires_at": datetime.now()
        }
        model = db_actions.crud(model="Invitation",
                                api_model=Invitation,
                                data=data,
                                action="create")
        response = self.client.open(
            '/api/v1/invitations/{invitation_id}'.format(
                invitation_id=model.id),
            method='DELETE',
            headers=self.headers)

        with self.assertRaises(werkzeug.exceptions.NotFound):
            db_actions.crud(model="Invitation",
                            api_model=Invitation,
                            action="read",
                            query={"id": model.id})
Exemplo n.º 9
0
    def test_delete_user_update(self):
        original_data = {
            "id": "%s" % uuid.uuid1(),
            "username": "******",
            "email": "*****@*****.**",
            "msisdn": "0865456321",
            "reason": "Like I need a reason",
            "deleter_id": "%s" % uuid.uuid1()
        }
        model = db_actions.crud(model="DeletedUser",
                                api_model=DeletedUserCreate,
                                data=original_data,
                                action="create")
        data = {
            "reason": "This is updated text",
            "username": "******" % uuid.uuid1()
        }

        updated_data = DeletedUserUpdate(**data)

        response = self.client.open(
            '/api/v1/deletedusers/{user_id}'.format(user_id=model.id),
            method='PUT',
            data=json.dumps(updated_data),
            content_type='application/json',
            headers=self.headers)
        response_data = json.loads(response.data)

        updated_entry = db_actions.crud(model="DeletedUser",
                                        api_model=DeletedUser,
                                        action="read",
                                        query={"id": model.id})

        for key, val in data.items():
            self.assertEqual(response_data[key], getattr(updated_entry, key))
Exemplo n.º 10
0
 def test_resource_update(self):
     """Test case for resource_update
     """
     data = {
         "urn": ("urn:%s" % uuid.uuid1())[:30],
         "description": "resource to update",
     }
     model = db_actions.crud(model="Resource",
                             api_model=Resource,
                             data=data,
                             action="create")
     data = {
         "urn": ("urn:%s" % uuid.uuid1())[:30],
         "description": "resource updated",
     }
     data = ResourceUpdate(**data)
     response = self.client.open(
         '/api/v1/resources/{resource_id}'.format(resource_id=model.id),
         method='PUT',
         data=json.dumps(data),
         content_type='application/json',
         headers=self.headers)
     r_data = json.loads(response.data)
     updated_entry = db_actions.crud(model="Resource",
                                     api_model=Resource,
                                     action="read",
                                     query={"id": model.id})
     self.assertEqual(r_data["urn"], updated_entry.urn)
     self.assertEqual(r_data["description"], updated_entry.description)
    def test_invitationredirecturl_delete(self):
        """Test case for invitationredirecturl_delete
        """
        data = {
            "url": "http://example.com/another/test",
            "description": "The deletion test URL",
        }
        model = db_actions.crud(
            model="InvitationRedirectUrl",
            api_model=InvitationRedirectUrl,
            data=data,
            action="create"
        )
        response = self.client.open(
            '/api/v1/invitationredirecturls/{invitationredirecturl_id}'.format(
                invitationredirecturl_id=model.id),
            method='DELETE', headers=self.headers)

        with self.assertRaises(werkzeug.exceptions.NotFound):
            db_actions.crud(
                model="InvitationRedirectUrl",
                api_model=InvitationRedirectUrl,
                action="read",
                query={"id": model.id}
            )
    def test_usersitedata_delete(self):
        """
        Test case for usersitedata_delete

        """
        data = {
            "site_id": random.randint(2, 2000000),
            "user_id": "%s" % uuid.uuid1(),
            "data": {
                "test": "delete this data"
            },
        }
        model = db_actions.crud(model="UserSiteData",
                                api_model=UserSiteData,
                                data=data,
                                action="create")

        response = self.client.open(
            '/api/v1/usersitedata/{user_id}/{site_id}'.format(
                user_id=model.user_id, site_id=model.site_id),
            method='DELETE',
            headers=self.headers)

        with self.assertRaises(werkzeug.exceptions.NotFound):
            db_actions.crud(model="UserSiteData",
                            api_model=UserSiteData,
                            action="read",
                            query={
                                "user_id": model.user_id,
                                "site_id": model.site_id
                            })
    def setUp(self):
        super().setUp()
        self.headers = {API_KEY_HEADER: "test-api-key"}

        for i in range(0, self.NUM_PERMISSIONS):
            data = {
                "name": f"permission_{i}",
                "description": f"Permission {i}",
            }
            model = db_actions.crud(
                model="Permission",
                api_model=Permission,
                data=data,
                action="create"
            )

        for j in range(0, self.NUM_RESOURCES):
            data = {
                "urn": f"resource_{j}",
                "description": f"Resource {j}",
            }
            model = db_actions.crud(
                model="Resource",
                api_model=Resource,
                data=data,
                action="create"
            )
    def test_sitedataschema_list(self):
        """
        Test case for sitedataschema_list
        """
        sitedataschema_data = {
            "site_id": random.randint(2, 2000000),
            "schema": {
                "type": "object",
                "properties": {
                    "item_1": {
                        "type": "number"
                    },
                    "item_2": {
                        "type": "string"
                    }
                },
                "additionalProperties": False
            }
        }
        db_actions.crud(model="SiteDataSchema",
                        api_model=SiteDataSchema,
                        data=sitedataschema_data,
                        action="create")
        query_string = [("limit", 5)]
        response = self.client.open('/api/v1/sitedataschemas',
                                    method='GET',
                                    query_string=query_string,
                                    headers=self.headers)
        response_data = json.loads(response.data)

        self.assertEqual(len(response_data), 2)
        self.assertIn("X-Total-Count", response.headers)
    def test_sitedataschema_delete(self):
        """
        Test case for sitedataschema_delete

        """
        data = {
            "site_id": random.randint(2, 2000000),
            "schema": {
                "test": "data"
            }
        }
        model = db_actions.crud(model="SiteDataSchema",
                                api_model=SiteDataSchema,
                                data=data,
                                action="create")

        response = self.client.open(
            '/api/v1/sitedataschemas/{site_id}'.format(site_id=model.site_id),
            method='DELETE',
            headers=self.headers)

        with self.assertRaises(werkzeug.exceptions.NotFound):
            db_actions.crud(model="SiteDataSchema",
                            api_model=SiteDataSchema,
                            action="read",
                            query={"site_id": model.site_id})
 def test_deletion_method_data_validation(self):
     site_data = {
         "name": ("%s" % uuid.uuid1())[:30],
         "domain_id": self.domain_model.id,
         "description": "a super cool test site",
         "deletion_method_id": self.method_one.id,
         "deletion_method_data": {
             "en": "a"
         },
         "client_id": 9994,
         "is_active": True,
     }
     with self.assertRaises(jsonschema.exceptions.ValidationError):
         crud(model="Site", api_model=Site, data=site_data, action="create")
     site_data = {
         "name": ("%s" % uuid.uuid1())[:30],
         "domain_id": self.domain_model.id,
         "description": "a super cool test site",
         "deletion_method_id": self.method_one.id,
         "deletion_method_data": {
             "recipients": ['*****@*****.**', '*****@*****.**']
         },
         "client_id": 9995,
         "is_active": True,
     }
     crud(model="Site",
          api_model=SiteCreate,
          data=site_data,
          action="create")
    def test_userdomainrole_delete(self):
        data = {
            "domain_id": self.domain_model.id,
            "role_id": self.role_model.id,
            "user_id": "%s" % uuid.uuid1()
        }
        user_domain_role = db_actions.crud(model="UserDomainRole",
                                           api_model=UserDomainRole,
                                           data=data,
                                           action="create")

        with self.assertRaises(werkzeug.exceptions.NotFound):
            response = self.client.open(
                '/api/v1/userdomainroles/{user_id}/{domain_id}/{role_id}'.
                format(
                    user_id=user_domain_role.user_id,
                    domain_id=user_domain_role.domain_id,
                    role_id=user_domain_role.role_id,
                ),
                method='DELETE',
                headers=self.headers)

            db_actions.crud(model="UserDomainRole",
                            api_model=UserDomainRole,
                            action="read",
                            query={
                                "role_id": user_domain_role.role_id,
                                "domain_id": user_domain_role.domain_id,
                            })
Exemplo n.º 18
0
    def test_domain_role_list(self):
        """Test case for domain_role_list
        """
        objects = []
        role_data = {
            "label": ("%s" % uuid.uuid1())[:30],
            "description": "domain_role to create",
        }
        role_model = db_actions.crud(
            model="Role",
            api_model=Role,
            data=role_data,
            action="create"
        )
        for index in range(1, random.randint(5, 20)):
            domain_data = {
                "name": ("%s" % uuid.uuid1())[:30],
                "description": "domain_role to create",
            }
            domain_model = db_actions.crud(
                model="Domain",
                api_model=Domain,
                data=domain_data,
                action="create"
            )

            domain_role_data = {
                "role_id": role_model.id,
                "domain_id": domain_model.id,
            }
            objects.append(db_actions.crud(
                model="DomainRole",
                api_model=DomainRole,
                data=domain_role_data,
                action="create"
            ))
        query_string = [#('offset', 0),
                        ('role_id', role_model.id),
        ]
        response = self.client.open(
            '/api/v1/domainroles',
            method='GET',
            query_string=query_string,
            headers=self.headers)
        r_data = json.loads(response.data)
        self.assertEqual(len(r_data), len(objects))
        self.assertEqual(int(response.headers["X-Total-Count"]), len(objects))
        query_string = [#('offset', 0),
                        ('limit', 2),
                        ('role_id', role_model.id),
        ]
        response = self.client.open(
            '/api/v1/domainroles',
            method='GET',
            query_string=query_string,
            headers=self.headers)
        r_data = json.loads(response.data)
        self.assertEqual(len(r_data), 2)
        self.assertEqual(int(response.headers["X-Total-Count"]), len(objects))
    def setUp(self):
        super().setUp()
        self.domain_data = {
            "name": ("%s" % uuid.uuid1())[:30],
            "description": "a super cool test domain",
        }
        self.domain_model = db_actions.crud(model="Domain",
                                            api_model=Domain,
                                            data=self.domain_data,
                                            action="create")
        site_data = {
            "name": ("%s" % uuid.uuid1())[:30],
            "domain_id": self.domain_model.id,
            "description": "a super cool test site",
            "client_id": 0,
            "is_active": True,
        }
        self.site_model = db_create_entry(
            model="Site",
            data=site_data,
        )
        self.roles = []

        # create a bunch of roles.
        for index in range(1, random.randint(5, 20)):
            role_data = {
                "label": ("%s" % uuid.uuid1())[:30],
                "description": "user_site_role to create",
            }
            role_model = db_actions.crud(model="Role",
                                         api_model=Role,
                                         data=role_data,
                                         action="create")
            self.roles.append(role_model)

        self.user_id = "%s" % uuid.uuid1()
        for role in self.roles:
            site_role_data = {
                "role_id": role.id,
                "site_id": self.site_model.id,
            }
            site_role_model = db_actions.crud(model="SiteRole",
                                              api_model=SiteRole,
                                              data=site_role_data,
                                              action="create")

            user_site_role_data = {
                "role_id": role.id,
                "site_id": self.site_model.id,
                "user_id": self.user_id,
            }
            user_site_role_model = db_actions.crud(model="UserSiteRole",
                                                   api_model=UserSiteRole,
                                                   data=user_site_role_data,
                                                   action="create")

        self.headers = {API_KEY_HEADER: "test-api-key"}
    def setUp(self):
        super().setUp()
        self.headers = {API_KEY_HEADER: "test-api-key"}
        self.role_ids = []

        for i in range(0, self.NUM_TESTS):
            # Create permission
            data = {
                "name": f"permission_{i}",
                "description": f"Permission {i}",
            }
            permission = db_actions.crud(
                model="Permission",
                api_model=Permission,
                data=data,
                action="create"
            )

            # Create resource
            data = {
                "urn": f"resource_{i}",
                "description": f"Resource {i}",
            }
            resource = db_actions.crud(
                model="Resource",
                api_model=Resource,
                data=data,
                action="create"
            )

            # Create role
            data = {
                "label": f"role_{i}",
                "description": f"Role {i}",
            }
            role = db_actions.crud(
                model="Role",
                api_model=Role,
                data=data,
                action="create"
            )
            self.role_ids.append(role.id)

            # Create role resource permission
            data = {
                "role_id": role.id,
                "resource_id": resource.id,
                "permission_id": permission.id
            }
            role_resource_permission = db_actions.crud(
                model="RoleResourcePermission",
                api_model=RoleResourcePermission,
                data=data,
                action="create"
            )
Exemplo n.º 21
0
    def test_domain_role_delete(self):
        """Test case for domain_role_delete
        """
        role_data = {
            "label": ("%s" % uuid.uuid1())[:30],
            "description": "domain_role to create",
        }
        role_model = db_actions.crud(
            model="Role",
            api_model=Role,
            data=role_data,
            action="create"
        )
        domain_data = {
            "name": ("%s" % uuid.uuid1())[:30],
            "description": "domain_role to create",
        }
        domain_model = db_actions.crud(
            model="Domain",
            api_model=Domain,
            data=domain_data,
            action="create"
        )

        domain_role_data = {
            "role_id": role_model.id,
            "domain_id": domain_model.id,
        }
        model = db_actions.crud(
            model="DomainRole",
            api_model=DomainRole,
            data=domain_role_data,
            action="create"
        )
        response = self.client.open(
            '/api/v1/domainroles/{domain_id}/{role_id}'.format(
                domain_id=model.domain_id,
                role_id=model.role_id,
            ),
            method='DELETE',
            headers=self.headers)

        # Little crude. Raise an error if the object actually still exists else
        # pass after the 404 error.
        with self.assertRaises(werkzeug.exceptions.NotFound):
            db_actions.crud(
                model="DomainRole",
                api_model=DomainRole,
                action="read",
                query={
                    "role_id": model.role_id,
                    "domain_id": model.domain_id,
                }
            )
Exemplo n.º 22
0
 def test_resource_list(self):
     """Test case for resource_list
     """
     objects = []
     for index in range(1, random.randint(5, 20)):
         data = {
             "urn": ("urn:%s" % uuid.uuid1())[:30],
             "description": "resource list %s" % index,
         }
         objects.append(
             db_actions.crud(model="Resource",
                             api_model=Resource,
                             data=data,
                             action="create"))
     query_string = [  #('offset', 0),
         ('resource_ids',
          ",".join(map(str, [resource.id for resource in objects])))
     ]
     response = self.client.open('/api/v1/resources',
                                 method='GET',
                                 query_string=query_string,
                                 headers=self.headers)
     r_data = json.loads(response.data)
     self.assertEqual(len(r_data), len(objects))
     self.assertEqual(int(response.headers["X-Total-Count"]), len(objects))
     query_string = [
         ('limit', 2),
         ('resource_ids',
          ",".join(map(str, [resource.id for resource in objects])))
     ]
     response = self.client.open('/api/v1/resources',
                                 method='GET',
                                 query_string=query_string,
                                 headers=self.headers)
     r_data = json.loads(response.data)
     self.assertEqual(len(r_data), 2)
     self.assertEqual(int(response.headers["X-Total-Count"]), len(objects))
     # Test Prefix filter
     data = {
         "urn": ("custom:%s" % uuid.uuid1())[:24],
         "description": "custom resource",
     }
     db_actions.crud(model="Resource",
                     api_model=Resource,
                     data=data,
                     action="create")
     query_string = [('prefix', "custom:")]
     response = self.client.open('/api/v1/resources',
                                 method='GET',
                                 query_string=query_string,
                                 headers=self.headers)
     r_data = json.loads(response.data)
     self.assertEqual(len(r_data), 1)
     self.assertEqual(int(response.headers["X-Total-Count"]), 1)
Exemplo n.º 23
0
 def test_purge_invitations_today(self):
     response = self.client.open("/api/v1/ops/purge_expired_invitations",
                                 method='GET',
                                 headers=self.headers)
     r_data = json.loads(response.data)
     self.assertEqual(r_data["amount"], 1)
     with self.assertRaises(werkzeug.exceptions.NotFound):
         db_actions.crud(model="Invitation",
                         api_model=Invitation,
                         action="read",
                         query={"id": self.expired_invitation_model.id})
Exemplo n.º 24
0
    def setUp(self):
        super().setUp()
        self.domain_data = {
            "name": ("%s" % uuid.uuid1())[:30],
            "description": "a super cool test domain",
        }
        self.domain_model = db_actions.crud(
            model="Domain",
            api_model=Domain,
            data=self.domain_data,
            action="create"
        )
        self.headers = {API_KEY_HEADER: "test-api-key"}

        self.roles = []
        # create a bunch of roles.
        for index in range(1, random.randint(5, 20)):
            role_data = {
                "label": ("%s" % uuid.uuid1())[:30],
                "description": "user_site_role to create",
            }
            role_model = db_actions.crud(
                model="Role",
                api_model=Role,
                data=role_data,
                action="create"
            )
            self.roles.append(role_model)

        # Set domain roles as well.
        self.domain_data = {
            "name": ("%s" % uuid.uuid4())[:30],
            "description": "a super cool test domain",
        }
        self.domain_model = db_actions.crud(
            model="Domain",
            api_model=Domain,
            data=self.domain_data,
            action="create"
        )

        self.domain_role_objs = []
        for role in self.roles:
            domain_role_data = {
                "role_id": role.id,
                "domain_id": self.domain_model.id
            }
            self.domain_role_objs.append(db_actions.crud(
                model="DomainRole",
                api_model=DomainRole,
                data=domain_role_data,
                action="create"
            ))
    def test_invitationredirecturl_update(self):
        """Test case for invitationredirecturl_update
        """
        data = {
            "url": "http://example.com/redirect/1",
            "description": "Description goes here",
        }
        model = db_actions.crud(
            model="InvitationRedirectUrl",
            api_model=InvitationRedirectUrl,
            data=data,
            action="create"
        )
        data = {
            "url": "http://example.com/redirect/2",
            "description": "Updated description goes here",
        }
        data = InvitationRedirectUrlUpdate(
            **data
        )
        response = self.client.open(
            '/api/v1/invitationredirecturls/{invitationredirecturl_id}'.format(
                invitationredirecturl_id=model.id),
            method='PUT',
            data=json.dumps(data),
            content_type='application/json',
            headers=self.headers)
        r_data = json.loads(response.data)
        updated_entry = db_actions.crud(
            model="InvitationRedirectUrl",
            api_model=InvitationRedirectUrl,
            action="read",
            query={"id": model.id}
        )
        self.assertEqual(r_data["url"], updated_entry.url)
        self.assertEqual(r_data["description"], updated_entry.description)

        # Attempt to update with bad URL
        data = {
            "url": "bad url",
            "description": "Updated description goes here",
        }
        data = InvitationRedirectUrlUpdate(
            **data
        )
        response = self.client.open(
            '/api/v1/invitationredirecturls/{invitationredirecturl_id}'.format(
                invitationredirecturl_id=model.id),
            method='PUT',
            data=json.dumps(data),
            content_type='application/json',
            headers=self.headers)
        self.assertEqual(response.status_code, 400)
    def test_user_site_role_create(self):
        """Test case for user_site_role_create
        """
        role_data = {
            "label": ("%s" % uuid.uuid1())[:30],
            "description": "user_site_role to create",
        }
        role_model = db_actions.crud(model="Role",
                                     api_model=Role,
                                     data=role_data,
                                     action="create")
        domain_data = {
            "name": ("%s" % uuid.uuid1())[:30],
            "description": "a super cool test domain",
        }
        domain_model = db_actions.crud(model="Domain",
                                       api_model=Domain,
                                       data=domain_data,
                                       action="create")
        site_data = {
            "name": ("%s" % uuid.uuid1())[:30],
            "domain_id": domain_model.id,
            "description": "a super cool test site",
            "client_id": uuid.uuid1().int >> 97,
            "is_active": True,
        }
        site_model = db_create_entry(
            model="Site",
            data=site_data,
        )
        site_role_data = {
            "role_id": role_model.id,
            "site_id": site_model.id,
        }
        site_role_model = db_actions.crud(model="SiteRole",
                                          api_model=SiteRole,
                                          data=site_role_data,
                                          action="create")

        data = UserSiteRoleCreate(
            **{
                "role_id": role_model.id,
                "site_id": site_model.id,
                "user_id": "%s" % uuid.uuid1(),
            })
        response = self.client.open('/api/v1/usersiteroles',
                                    method='POST',
                                    data=json.dumps(data),
                                    content_type='application/json',
                                    headers=self.headers)
        r_data = json.loads(response.data)
        self.assertEqual(r_data["role_id"], data.role_id)
        self.assertEqual(r_data["site_id"], data.site_id)
    def setUp(self):
        super().setUp()
        self.role_data = {
            "label": ("%s" % uuid.uuid4())[:30],
            "description": "invitation_site_role to create",
        }
        self.role_model = db_actions.crud(model="Role",
                                          api_model=Role,
                                          data=self.role_data,
                                          action="create")
        self.domain_data = {
            "name": ("%s" % uuid.uuid4())[:30],
            "description": "a super cool test domain",
        }
        self.domain_model = db_actions.crud(model="Domain",
                                            api_model=Domain,
                                            data=self.domain_data,
                                            action="create")
        self.site_data = {
            "name": ("%s" % uuid.uuid4())[:30],
            "description": "a super cool test site",
            "domain_id": self.domain_model.id
        }
        self.site_model = db_create_entry(
            model="Site",
            data=self.site_data,
        )

        self.site_role_data = {
            "role_id": self.role_model.id,
            "site_id": self.site_model.id
        }
        self.site_role_model = db_actions.crud(model="SiteRole",
                                               api_model=SiteRole,
                                               data=self.site_role_data,
                                               action="create")
        self.invitation_data = {
            "first_name": "first",
            "last_name": "last",
            "email": "*****@*****.**",
            "organisation_id": 1,
            "invitor_id": "%s" % uuid.uuid1(),
            "expires_at": datetime.now()
        }
        self.invitation_model = db_actions.crud(model="Invitation",
                                                api_model=Invitation,
                                                data=self.invitation_data,
                                                action="create")

        self.headers = {API_KEY_HEADER: "test-api-key"}
Exemplo n.º 28
0
    def test_delete_user_data_usersiterole(self):
        user_id = "%s" % uuid.uuid1()
        role_model = db_actions.crud(model="Role",
                                     api_model=Role,
                                     data={
                                         "label": ("%s" % uuid.uuid1())[:30],
                                         "description":
                                         "user_site_role to create",
                                     },
                                     action="create")
        domain_model = db_actions.crud(model="Domain",
                                       api_model=Domain,
                                       data={
                                           "name": ("%s" % uuid.uuid1())[:30],
                                           "description":
                                           "user_site_role to create",
                                       },
                                       action="create")
        for index in range(1, 30):
            site_data = {
                "name": ("%s" % uuid.uuid1())[:30],
                "domain_id": domain_model.id,
                "description": "a super cool test site",
                "client_id": uuid.uuid1().int >> 97,
                "is_active": True,
            }
            site_model = db_create_entry(
                model="Site",
                data=site_data,
            )
            db_actions.crud(model="SiteRole",
                            api_model=SiteRole,
                            data={
                                "role_id": role_model.id,
                                "site_id": site_model.id,
                            },
                            action="create")
            db_actions.crud(model="UserSiteRole",
                            api_model=UserSiteRole,
                            data={
                                "role_id": role_model.id,
                                "site_id": site_model.id,
                                "user_id": user_id,
                            },
                            action="create")

        response = self.client.open(
            '/api/v1/ops/users/{user_id}/delete'.format(user_id=user_id, ),
            method='GET',
            headers=self.headers)
        response_data = json.loads(response.data)
        self.assertEqual(response_data["amount"], 29)

        with self.assertRaises(werkzeug.exceptions.NotFound):
            db_actions.crud(model="UserSiteRole",
                            api_model=UserSiteRole,
                            action="read",
                            query={
                                "user_id": user_id,
                            })
    def setUp(self):
        super().setUp()
        self.role_data = {
            "label": ("%s" % uuid.uuid1())[:30],
            "description": "user_site_role to create",
        }
        self.role_model = db_actions.crud(model="Role",
                                          api_model=Role,
                                          data=self.role_data,
                                          action="create")
        self.domain_data = {
            "name": ("%s" % uuid.uuid1())[:30],
            "description": "a super cool test domain",
        }
        self.domain_model = db_actions.crud(model="Domain",
                                            api_model=Domain,
                                            data=self.domain_data,
                                            action="create")
        self.site_data = {
            "name": ("%s" % uuid.uuid1())[:30],
            "domain_id": self.domain_model.id,
            "description": "a super cool test site",
            "client_id": uuid.uuid1().int >> 97,
            "is_active": True,
        }
        self.site_model = db_create_entry(
            model="Site",
            data=self.site_data,
        )
        self.site_role_data = {
            "role_id": self.role_model.id,
            "site_id": self.site_model.id,
        }
        self.site_role_model = db_actions.crud(model="SiteRole",
                                               api_model=SiteRole,
                                               data=self.site_role_data,
                                               action="create")

        self.user_site_role_data = {
            "role_id": self.role_model.id,
            "site_id": self.site_model.id,
            "user_id": "%s" % uuid.uuid1(),
        }
        self.user_site_role_model = db_actions.crud(
            model="UserSiteRole",
            api_model=UserSiteRole,
            data=self.user_site_role_data,
            action="create")

        self.headers = {API_KEY_HEADER: "test-api-key"}
 def setUpClass(cls):
     super().setUpClass()
     # Create the DeletionMethods.
     cls.method_one = models.DeletionMethod(
         **{
             "label": "email_test",
             "data_schema": {
                 "type": "object",
                 "additionalProperties": False,
                 "properties": {
                     "recipients": {
                         "type": "array",
                         "items": {
                             "type": "string",
                             "format": "email"
                         }
                     },
                 },
             },
             "description": "A description"
         })
     db.session.add(cls.method_one)
     db.session.commit()
     domain_data = {
         "name": ("%s" % uuid.uuid1())[:30],
         "description": "%s" % uuid.uuid1(),
     }
     cls.domain_model = crud(model="Domain",
                             api_model=Domain,
                             data=domain_data,
                             action="create")