Exemplo n.º 1
0
    def test_get_custom_properties_disabled_field(self):
        """It should not return a disable field,.
        """
        workspace = factories.WorkspaceFactory()

        attributes = {
            'content_type': self.model_class.get_content_type(),
            'workspace': workspace,
        }

        customfield = factories.CustomFieldFactory(
            field_name='Steward',
            **attributes,
        )

        custom_properties = {
            customfield.pk: "Sam Crust",
        }

        resource = self.factory(
            workspace=workspace,
            disabled_datastore_properties=[customfield.pk],
            custom_properties=custom_properties,
        )

        self.assertEqual(resource.custom_properties, custom_properties)
        self.assertEqual(resource.get_custom_properties(), {})
Exemplo n.º 2
0
 def setUpTestData(cls):
     cls.current_user = factories.UserFactory()
     cls.workspace = factories.WorkspaceFactory(creator=cls.current_user)
     cls.workspace.grant_membership(cls.current_user,
                                    models.Membership.OWNER)
     cls.user = factories.UserFactory()
     cls.membership, _ = cls.workspace.grant_membership(
         cls.user, models.Membership.READONLY)
     cls.request = collections.namedtuple('Request',
                                          ['user'])(user=cls.current_user)
Exemplo n.º 3
0
    def test_encode_uuid_model(self):
        """It should partially encode a Django model.
        """
        workspace = factories.WorkspaceFactory()

        resource = json.dumps(
            workspace,
            cls=DjangoPartialModelJsonEncoder,
        )

        self.assertEqual(
            resource,
            "{\"pk\": \"%s\", \"type\": \"Workspace\"}" % str(workspace.id),
        )
Exemplo n.º 4
0
    def test_remove_revoked_user_from_groups(self):
        """It should remove a User from all workspace groups when membership is revoked.
        """
        user = factories.UserFactory()

        workspace = factories.WorkspaceFactory(name='Metameta')
        workspace.grant_membership(user, models.Membership.READONLY)

        group = factories.GroupFactory(workspace_id=workspace.id)
        group.user_set.add(user)

        self.assertTrue(user.groups.filter(name=group.name).exists())

        workspace.revoke_membership(user)

        self.assertFalse(user.groups.filter(name=group.name).exists())
Exemplo n.º 5
0
    def test_membership_revoked(self, mock_deliver):
        """It should call the Mailer.deliver method with the proper template.
        """
        email = '*****@*****.**'
        workspace = factories.WorkspaceFactory(name='Metameta')

        emails.membership_revoked(email, workspace)

        mock_deliver.assert_called_with(
            email,
            'You have been removed from the Metameta workspace',
            {
                'to_address': email,
                'workspace_name': workspace.name,
            },
        )
Exemplo n.º 6
0
    def test_get_custom_properties(self):
        """It should return NULL for non-existent fields.
        """
        user = factories.UserFactory()
        workspace = factories.WorkspaceFactory()
        workspace.grant_membership(user, 'OWNER')

        attributes = {
            'content_type': self.model_class.get_content_type(),
            'workspace': workspace,
        }

        customfields = [
            factories.CustomFieldFactory(field_name='Steward',
                                         field_type=models.CustomField.USER,
                                         **attributes),
            factories.CustomFieldFactory(field_name='Product Area',
                                         field_type=models.CustomField.TEXT,
                                         **attributes),
            factories.CustomFieldFactory(field_name='Team',
                                         field_type=models.CustomField.TEXT,
                                         **attributes),
        ]

        resource = self.factory(
            workspace=workspace,
            custom_properties={
                customfields[0].pk: user.pk,
                customfields[2].pk: 'Data Engineering',
            },
        )

        custom_properties = resource.get_custom_properties()
        for customfield in customfields:
            self.assertTrue(customfield.pk in custom_properties)

        self.assertEqual(custom_properties[customfields[0].pk], {
            'label': 'Steward',
            'value': user
        })

        self.assertEqual(custom_properties[customfields[2].pk], {
            'label': 'Team',
            'value': 'Data Engineering'
        })
Exemplo n.º 7
0
    def test_ownership_membership_granted_when_exists(self, mock_deliver):
        """It should call the Mailer.deliver method with the proper template.
        """
        email = '*****@*****.**'
        workspace = factories.WorkspaceFactory(name='Metameta')

        emails.membership_granted(email, workspace, models.Membership.OWNER)

        mock_deliver.assert_called_with(
            email,
            'You have granted the Owner role to the Metameta workspace',
            {
                'to_address': email,
                'workspace_name': workspace.name,
                'user_exists': False,
                'permissions': 'Owner',
            },
        )
Exemplo n.º 8
0
    def test_membership_granted_when_exists(self, mock_deliver):
        """It should call the Mailer.deliver method with the proper template.
        """
        user = factories.UserFactory()
        workspace = factories.WorkspaceFactory(name='Metameta')

        emails.membership_granted(user.email, workspace,
                                  models.Membership.READONLY)

        mock_deliver.assert_called_with(
            user.email,
            'You have granted the Readonly role to the Metameta workspace',
            {
                'to_address': user.email,
                'workspace_name': workspace.name,
                'user_exists': True,
                'permissions': 'Readonly',
            },
        )
Exemplo n.º 9
0
    def setUpTestData(cls):
        cls.current_user = factories.UserFactory()
        cls.workspace = factories.WorkspaceFactory(creator=cls.current_user)
        cls.workspace.grant_membership(cls.current_user, auth.Membership.OWNER)
        cls.group = factories.GroupFactory(workspace_id=cls.workspace.id)
        cls.datastore = factories.DatastoreFactory(workspace=cls.workspace)
        cls.attributes = {
            'content_type': cls.datastore.content_type,
            'workspace': cls.workspace,
        }

        cls.customfields = [
            factories.CustomFieldFactory(
                field_name='Steward',
                field_type=models.CustomField.USER,
                validators={},
                **cls.attributes,
            ),
            factories.CustomFieldFactory(
                field_name='Product Area',
                field_type=models.CustomField.TEXT,
                validators={},
                **cls.attributes,
            ),
            factories.CustomFieldFactory(
                field_name='Department',
                field_type=models.CustomField.ENUM,
                validators={
                    'choices': ['Data Engineering', 'Product', 'Design']
                },
                **cls.attributes,
            ),
            factories.CustomFieldFactory(
                field_name='Team',
                field_type=models.CustomField.GROUP,
                **cls.attributes,
            ),
        ]
        cls.request = collections.namedtuple(
            'Request',
            ['user', 'workspace'],
        )(user=cls.current_user, workspace=cls.workspace)
Exemplo n.º 10
0
    def test_create_duplicate_slug(self):
        """It should NOT create a new Workspace.
        """
        variables = self._get_attributes()

        factories.WorkspaceFactory(**variables)

        response = self.execute(variables=variables)
        response = response['data'][self.operation]

        self.assertEqual(response, {
            'workspace': None,
            'errors': [
                {
                    'resource': 'Workspace',
                    'field': 'slug',
                    'code': 'exists',
                }
            ],
        })
Exemplo n.º 11
0
    def test_get_custom_properties_deleted_user(self):
        """It should return NULL for a deleted choice.
        """
        user = factories.UserFactory()
        workspace = factories.WorkspaceFactory()
        workspace.grant_membership(user, 'OWNER')

        attributes = {
            'content_type': self.model_class.get_content_type(),
            'workspace': workspace,
        }

        customfield = factories.CustomFieldFactory(
            field_name='Steward',
            field_type=models.CustomField.USER,
            **attributes,
        )

        resource = self.factory(
            workspace=workspace,
            custom_properties={
                customfield.pk: user.pk,
            },
        )

        self.assertEqual(resource.get_custom_properties()[customfield.pk], {
            'label': 'Steward',
            'value': user
        })

        workspace.revoke_membership(user)
        resource.refresh_from_db()

        self.assertEqual(resource.get_custom_properties()[customfield.pk], {
            'label': 'Steward',
            'value': None
        })
Exemplo n.º 12
0
    def test_query(self):
        """It should return only the workspaces that the current User belongs to.
        """
        restricted_workspace = factories.WorkspaceFactory()
        restricted_workspace.grant_membership(self.users['OUTSIDER'], 'MEMBER')

        results = self.execute(self.statement)
        results = results['data'][self.operation]

        self.assertEqual(
            first=len(results['edges']),
            second=self.user.workspaces.count(),
            msg=
            "Node count should equal number of workspaces that the current user belongs to."
        )

        self.assertEqual(first=results['totalCount'],
                         second=len(results['edges']),
                         msg="Node count should equal totalCount field.")

        self.assertNotIn(
            str(restricted_workspace.pk),
            list(map(lambda m: m['node']['pk'], results['edges'])),
            msg="Workspace that the User is not a part of should be excluded.")
Exemplo n.º 13
0
    def test_get_custom_properties_deleted_choice(self):
        """It should return NULL for a deleted choice.
        """
        workspace = factories.WorkspaceFactory()

        attributes = {
            'content_type': self.model_class.get_content_type(),
            'workspace': workspace,
        }

        customfield = factories.CustomFieldFactory(
            field_name='Steward',
            field_type=models.CustomField.ENUM,
            validators={'choices': ['red', 'yellow', 'blue']},
            **attributes,
        )

        resource = self.factory(
            workspace=workspace,
            custom_properties={
                customfield.pk: 'blue',
            },
        )

        self.assertEqual(resource.get_custom_properties()[customfield.pk], {
            'label': 'Steward',
            'value': 'blue'
        })

        customfield.validators = {'choices': ['red', 'yellow', 'green']}
        customfield.save()

        self.assertEqual(resource.get_custom_properties()[customfield.pk], {
            'label': 'Steward',
            'value': None
        })
Exemplo n.º 14
0
 def setUp(self):
     self.client = Client(HTTP_HOST='example.com')
     self.user = factories.UserFactory()
     self.workspace = factories.WorkspaceFactory()
     self.workspace.grant_membership(self.user, 'READONLY')
Exemplo n.º 15
0
 def setUpTestData(cls):
     cls.workspace = factories.WorkspaceFactory()
     cls.instance = cls.factory(name='Everyone', workspace=cls.workspace)
Exemplo n.º 16
0
 def setUpTestData(cls):
     cls.workspace = factories.WorkspaceFactory()
Exemplo n.º 17
0
 def setUpTestData(cls):
     cls.workspace = factories.WorkspaceFactory()
     cls.resource = cls.factory(workspace=cls.workspace)
Exemplo n.º 18
0
 def setUpTestData(cls):
     cls.workspace = factories.WorkspaceFactory()
     cls.resource = cls.factory(provider=models.SSOConnection.GENERIC,
                                workspace=cls.workspace)
Exemplo n.º 19
0
 def setUpTestData(cls):
     cls.count = 4
     cls.workspace = factories.WorkspaceFactory()
     cls.domains = cls.factory.create_batch(cls.count, workspace=cls.workspace)
Exemplo n.º 20
0
 def setUpTestData(cls):
     cls.workspace = factories.WorkspaceFactory()
     cls.instance = cls.factory(
         field_type=models.CustomField.TEXT,
         workspace=cls.workspace,
     )