Beispiel #1
0
 def test_if_sync_is_called_and_valueerror_raised_when_db_empty(self):
     with mock.patch(
             'lizard_auth_client.client.'
             'sso_sync_user_organisation_roles') as patched:
         self.assertRaises(
             ValueError,
             lambda: client.get_billable_organisation(self.user))
         self.assertTrue(patched.called)
Beispiel #2
0
    def test_function_actually_works_and_doesnt_sync(self):
        org1 = models.Organisation.objects.create(unique_id='A')
        models.UserOrganisationRole.objects.create(
            user=self.user, role=self.role, organisation=org1)
        with mock.patch(
                'lizard_auth_client.client.'
                'sso_sync_user_organisation_roles') as patched:
            org = client.get_billable_organisation(self.user)
            self.assertFalse(patched.called)

        self.assertEquals(org.pk, org1.pk)
Beispiel #3
0
 def handle(self, *args, **options):
     """
     """
     sso_user = options.get('sso_user')
     if not sso_user:
         raise CommandError('\n[E] Please provide a username')
     else:
         try:
             user_model = get_user_model()
             user = user_model.objects.get(username=sso_user)
         except Exception as err:
             raise CommandError("\n[E] unexpected exception: '%s'" % str(err))
         billable_org = client.get_billable_organisation(user)
         print(billable_org)
Beispiel #4
0
    def test_raises_value_error_if_two_organisations(self):
        org1 = models.Organisation.objects.create(unique_id='A')
        org2 = models.Organisation.objects.create(unique_id='B')

        models.UserOrganisationRole.objects.create(
            user=self.user, role=self.role, organisation=org1)
        models.UserOrganisationRole.objects.create(
            user=self.user, role=self.role, organisation=org2)

        with mock.patch(
                'lizard_auth_client.client.'
                'sso_sync_user_organisation_roles') as patched:
            self.assertRaises(
                ValueError,
                lambda: client.get_billable_organisation(self.user))
            self.assertTrue(patched.called)