Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 101 lines (81 sloc) 2.867 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
import string
import random
import os
import sys
import nose.tools
import boto
from boto.ec2.connection import EC2Connection
import boto.ec2
import sys
from ConfigParser import SafeConfigParser
import time
import unittest
import tempfile
import filecmp
import pycb
import pynimbusauthz
from pynimbusauthz.db import *
from pynimbusauthz.user import *
import pycb.test_common
from boto.s3.connection import OrdinaryCallingFormat
from boto.s3.connection import S3Connection
import random
import nimbus_remove_user
import nimbus_new_user
import nimbus_list_users
import nimbus_edit_user

class TestUsersFailures(unittest.TestCase):


    def setUp(self):
        self.users = []
        self.nh = os.environ['NIMBUS_HOME']
        os.environ['NIMBUS_HOME'] = "/not/such place"

    def tearDown(self):
        os.environ['NIMBUS_HOME'] = self.nh
        for f in self.users:
            nimbus_remove_user.main([f])

    def get_user_name(self, friendly_name=None):
        if friendly_name == None:
            friendly_name = str(uuid.uuid1())
        self.users.append(friendly_name)
        return friendly_name

    def find_in_file(self, fname, needle):
        found = False
        f = open(fname)
        l = f.readline()
        while l:
            print "#### " + l
            x = l.find(needle)
            if x >= 0:
                found = True
            l = f.readline()
        f.close()
        return found


    def test_new_user(self):
        friendly_name = self.get_user_name()

        (tmpFD, outFileName) = tempfile.mkstemp("cumulustests")
        os.close(tmpFD)

        rc = nimbus_new_user.main([friendly_name])
        self.assertNotEqual(rc, 0, "should not be 0 %d" % (rc))

        # make sure the user was not added
        os.environ['NIMBUS_HOME'] = self.nh
        rc = nimbus_list_users.main(["-b", "-r", "display_name", "-O", outFileName, friendly_name])
        rc = self.find_in_file(outFileName, friendly_name)
        self.assertFalse(rc)

    def test_remove_user(self):
        friendly_name = self.get_user_name()

        (tmpFD, outFileName) = tempfile.mkstemp("cumulustests")
        os.close(tmpFD)

        # add a good user
        os.environ['NIMBUS_HOME'] = self.nh
        rc = nimbus_new_user.main([friendly_name])
        self.assertEqual(rc, 0, "should be 0 %d" % (rc))

        os.environ['NIMBUS_HOME'] = "/nope"
        # remove with an error
        rc = nimbus_remove_user.main([friendly_name])
        self.assertNotEqual(rc, 0, "should not be 0 %d" % (rc))

        # relist to see user is still there
        os.environ['NIMBUS_HOME'] = self.nh
        rc = nimbus_list_users.main(["-b", "-r", "display_name", "-O", outFileName, friendly_name])
        self.assertEqual(rc, 0, "should not be 0 %d" % (rc))
        rc = self.find_in_file(outFileName, friendly_name)
        self.assertTrue(rc)



Something went wrong with that request. Please try again.