Exemplo n.º 1
0
    def test__get_default_org(self):
        """test seed.views.main._get_default_org"""
        org_id, org_name, org_role = _get_default_org(self.user)

        # check standard case
        self.assertEqual(org_id, self.org.id)
        self.assertEqual(org_name, self.org.name)
        self.assertEqual(org_role, 'owner')

        # check that the default org was set
        u = User.objects.get(pk=self.user.pk)
        self.assertEqual(u.default_organization, self.org)

        # check that '' is returned for a user without an org
        other_user = User.objects.create(
            username='******',
            email='*****@*****.**',
        )
        org_id, org_name, org_role = _get_default_org(other_user)
        self.assertEqual(org_id, '')
        self.assertEqual(org_name, '')
        self.assertEqual(org_role, '')

        # check that the user is still in the default org, or update
        other_user.default_organization = self.org
        other_user.save()
        other_user = User.objects.get(pk=other_user.pk)
        self.assertEqual(other_user.default_organization, self.org)
        # _get_default_org should remove the user from the org and set the
        # next available org as default or set to ''
        org_id, org_name, org_role = _get_default_org(other_user)
        self.assertEqual(org_id, '')
        self.assertEqual(org_name, '')
        self.assertEqual(org_role, '')
Exemplo n.º 2
0
    def test__get_default_org(self):
        """test seed.views.main._get_default_org"""
        org_id, org_name, org_role = _get_default_org(self.user)

        # check standard case
        self.assertEqual(org_id, self.org.id)
        self.assertEqual(org_name, self.org.name)
        self.assertEqual(org_role, "owner")

        # check that the default org was set
        u = User.objects.get(pk=self.user.pk)
        self.assertEqual(u.default_organization, self.org)

        # check that "" is returned for a user without an org
        other_user = User.objects.create(
            username="******",
            email="*****@*****.**",
        )
        org_id, org_name, org_role = _get_default_org(other_user)
        self.assertEqual(org_id, "")
        self.assertEqual(org_name, "")
        self.assertEqual(org_role, "")

        # check that the user is still in the default org, or update
        other_user.default_organization = self.org
        other_user.save()
        other_user = User.objects.get(pk=other_user.pk)
        self.assertEqual(other_user.default_organization, self.org)
        # _get_default_org should remove the user from the org and set the
        # next available org as default or set to ""
        org_id, org_name, org_role = _get_default_org(other_user)
        self.assertEqual(org_id, "")
        self.assertEqual(org_name, "")
        self.assertEqual(org_role, "")