def testFunction(domain_url, session):

	(status, briefing, message, api_location) = findAPILocation(domain_url)
	if status != 0:
		return (status, briefing, message, None)

	username = "******"

	if create_user_channel(session, domain_url, api_location, username):

		if ( close_this_user_channel(session, domain_url, api_location, username) ):

			status = 0
			briefing = "Could successfully create test user channel: <strong>%s@%s</strong>" % (username, domain_url)
			message = "We could successfully assert creation of test user channel <strong>%s@%s</strong>." % (username, domain_url)
			message += "<br/>That test user channel will be used for testing purposes."

		else:
			
			status = 1
			briefing = "Could successfully create test user channel <strong>%s@%s</strong> " % (username, domain_url)
			briefing += "but could not change privacy setting to <em>authorized</em>!"
			message = "We could successfully assert creation of test user channel <strong>%s@%s</strong>." % (username, domain_url)
			message += "<br/>The problem is we could not have its privacy setting set to <em>authorized</em>."
			message += "<br/>That test user channel is intended to be closed (authorized) and will be used for testing purposes."

	else:

		if user_channel_exists(session, domain_url, api_location, username):			

			status = 2
			briefing = "The test user channel <strong>%s@%s</strong> wasn't " % (username, domain_url)
			briefing += "expected to exist but it did, so it could not be created again."
			message = briefing

			if ( delete_user_channel(session, domain_url, api_location, username)
			and create_user_channel(session, domain_url, api_location, username) ):

				status = 0
				additional_info = "<br/>But we could assert that <em>open</em> user channel creation is being "
				additional_info += "properly implemented by your API server."
				briefing += additional_info
				message += additional_info
				message += "<br/>We deleted the existing test user channel and then were successful in creating it again."
			else:
				message += "<br/>The problem is we cannot assert that <em>open</em> user channel creation is working."

		else:

			status = 1
			briefing = "The test user channel <strong>%s@%s</strong> could not be created." % (username, domain_url)
			message = briefing
			message += "<br/>It seems like your HTTP API server is problematic. It had trouble creating an "
			message += "<em>open</em> user channel - that operation must work."
			
	return (status, briefing, message, None)
def testFunction(domain_url, session):

    (status, briefing, message, api_location) = findAPILocation(domain_url)
    if status != 0:
        return (status, briefing, message, None)

    username = "******"

    if delete_user_channel(session, domain_url, api_location, username):

        status = 0
        briefing = "Could successfully delete test user channel: <strong>%s@%s</strong>" % (
            username, domain_url)
        message = "We could successfully assert deletion of test user channel <strong>%s@%s</strong>." % (
            username, domain_url)
        message += "<br/>That test user channel was being used for testing purposes."

    else:

        if not user_channel_exists(session, domain_url, api_location,
                                   username):

            status = 2
            briefing = "The test user channel <strong>%s@%s</strong> was " % (
                username, domain_url)
            briefing += "expected to exist but it didn't, so it could not be deleted again."
            message = briefing

            if (create_user_channel(session, domain_url, api_location,
                                    username)
                    and open_this_user_channel(session, domain_url,
                                               api_location, username)
                    and delete_user_channel(session, domain_url, api_location,
                                            username)):

                status = 0
                additional_info = "<br/>But we could assert that <em>open</em> user channel deletion is being "
                additional_info += "properly implemented by your API server."
                briefing += additional_info
                message += additional_info
                message += "<br/>We created the expected test user channel and then were successful in deleting it again."
            else:
                message += "<br/>The problem is we cannot assert that <em>open</em> user channel deletion is working."

        else:

            status = 1
            briefing = "The test user channel <strong>%s@%s</strong> could not be deleted." % (
                username, domain_url)
            message = briefing
            message += "<br/>It seems like your HTTP API server is problematic. It had trouble deleting an "
            message += "<em>open</em> user channel - that operation must work."

    return (status, briefing, message, None)
def testFunction(domain_url, session):

	(status, briefing, message, api_location) = findAPILocation(domain_url)
	if status != 0:
		return (status, briefing, message, None)

	username = "******"

	if delete_user_channel(session, domain_url, api_location, username):

		status = 0
		briefing = "Could successfully delete test user channel: <strong>%s@%s</strong>" % (username, domain_url)
		message = "We could successfully assert deletion of test user channel <strong>%s@%s</strong>." % (username, domain_url)
		message += "<br/>That test user channel was being used for testing purposes."
	
	else:

		if not user_channel_exists(session, domain_url, api_location, username):			

			status = 2
			briefing = "The test user channel <strong>%s@%s</strong> was " % (username, domain_url)
			briefing += "expected to exist but it didn't, so it could not be deleted again."
			message = briefing

			if ( create_user_channel(session, domain_url, api_location, username)
			and open_this_user_channel(session, domain_url, api_location, username)
			and delete_user_channel(session, domain_url, api_location, username) ):

				status = 0
				additional_info = "<br/>But we could assert that <em>open</em> user channel deletion is being "
				additional_info += "properly implemented by your API server."
				briefing += additional_info
				message += additional_info
				message += "<br/>We created the expected test user channel and then were successful in deleting it again."
			else:
				message += "<br/>The problem is we cannot assert that <em>open</em> user channel deletion is working."

		else:

			status = 1
			briefing = "The test user channel <strong>%s@%s</strong> could not be deleted." % (username, domain_url)
			message = briefing
			message += "<br/>It seems like your HTTP API server is problematic. It had trouble deleting an "
			message += "<em>open</em> user channel - that operation must work."
			
	return (status, briefing, message, None)
def testFunction(domain_url, session):

	CLASSIFIED = { 'CREATED' : [], 'UNEXPECTED' : [], 'UNEXPECTED_BUT_WORKED' : [], 'NOT_CREATED' : [] }

	(status, briefing, message, api_location) = findAPILocation(domain_url)
	if status != 0:
		return (status, briefing, message, None)

	prefix = "test_user_channel_follower"

	for i in range(1, 5):

		username = prefix + str(i)

		if create_user_channel(session, domain_url, api_location, username):
			CLASSIFIED['CREATED'].append("%s@%s" % (username, domain_url))
		else:
			if user_channel_exists(session, domain_url, api_location, username):

				if ( delete_user_channel(session, domain_url, api_location, username)
				and create_user_channel(session, domain_url, api_location, username) ):
					CLASSIFIED['UNEXPECTED_BUT_WORKED'].append("%s@%s" % (username, domain_url))
				else:
					CLASSIFIED['UNEXPECTED'].append("%s@%s" % (username, domain_url))
			else:
				CLASSIFIED['NOT_CREATED'].append("%s@%s" % (username, domain_url))

	status = 0
	briefing = ""
	message = ""

	if ( len(CLASSIFIED.get('NOT_CREATED', [])) > 0 ):
	
		status = 1
		briefing = "The following test user channels could not be created:"
		message = briefing
		briefing += " <strong>%s</strong>" % string.join(CLASSIFIED['NOT_CREATED'], " | ")
		message += "<br/><br/><strong>%s</strong>" % string.join(CLASSIFIED['NOT_CREATED'], "<br/>")
		message += "<br/>It seems like your HTTP API server is problematic. It had trouble creating "
		message += "user channels - these operations must work."
	
	if ( len(CLASSIFIED.get('UNEXPECTED', [])) > 0 ):

		if status == 0:
			status = 2

		info = "The following test user channels weren't expected to exist but they did, so they could not be created again: "

		if not briefing:
			briefing = info
			briefing += "<strong>%s</strong>" % string.join(CLASSIFIED['UNEXPECTED'], " | ")
			message = info
		else:
			message += "<br/>" + info

		message += "<br/><br/><strong>%s</strong>" % string.join(CLASSIFIED['UNEXPECTED'], "<br/>")
		message += "<br/>The problem is we cannot assert that user channel creation is working."

	if ( len(CLASSIFIED.get('UNEXPECTED_BUT_WORKED', [])) > 0 ):

		info = "The test following user channels weren't expected to exist but they did, so they could not be created again: "

		if not briefing:
			briefing = info
			briefing += "<strong>%s</strong>" % string.join(CLASSIFIED['UNEXPECTED_BUT_WORKED'], " | ")
			message = info
		else:
			message += "<br/>" + info

		message += "<br/><br/><strong>%s</strong>" % string.join(CLASSIFIED['UNEXPECTED_BUT_WORKED'], "<br/>")
		info = "<br/>But we could assert that user channel creation worked for some test user channels."
		briefing += info
		message += info
		message += "<br/>We deleted the existing test user channels and then were successful in creating them again."

	if ( len(CLASSIFIED.get('CREATED', [])) > 0 ):

		info = "We could successfully assert creation of the following test user channels: "
		info += "<br/><br/><strong>%s</strong>" % string.join(CLASSIFIED['CREATED'], "<br/>")
		info += "<br/>These test user channels will be used for testing purposes."

		if not briefing:
			briefing = "Could successfully create the following test user channels: "
			briefing += "<strong>%s</strong>" % string.join(CLASSIFIED['CREATED'], " | ")
			message = info
		else:
			message += "<br/>" + info

	return (status, briefing, message, None)
def testFunction(domain_url, session):

    CLASSIFIED = {
        'DELETED': [],
        'UNEXPECTED': [],
        'UNEXPECTED_BUT_WORKED': [],
        'NOT_DELETED': []
    }

    (status, briefing, message, api_location) = findAPILocation(domain_url)
    if status != 0:
        return (status, briefing, message, None)

    prefix = "test_user_channel_follower"

    for i in range(1, 5):

        username = prefix + str(i)

        if delete_user_channel(session, domain_url, api_location, username):
            CLASSIFIED['DELETED'].append("%s@%s" % (username, domain_url))
        else:
            if not user_channel_exists(session, domain_url, api_location,
                                       username):

                if (create_user_channel(session, domain_url, api_location,
                                        username)
                        and delete_user_channel(session, domain_url,
                                                api_location, username)):
                    CLASSIFIED['UNEXPECTED_BUT_WORKED'].append(
                        "%s@%s" % (username, domain_url))
                else:
                    CLASSIFIED['UNEXPECTED'].append("%s@%s" %
                                                    (username, domain_url))
            else:
                CLASSIFIED['NOT_DELETED'].append("%s@%s" %
                                                 (username, domain_url))

    status = 0
    briefing = ""
    message = ""

    if (len(CLASSIFIED.get('NOT_DELETED', [])) > 0):

        status = 1
        briefing = "The following test user channels could not be deleted:"
        message = briefing
        briefing += " <strong>%s</strong>" % string.join(
            CLASSIFIED['NOT_DELETED'], " | ")
        message += "<br/><br/><strong>%s</strong>" % string.join(
            CLASSIFIED['NOT_DELETED'], "<br/>")
        message += "<br/>It seems like your HTTP API server is problematic. It had trouble deleting "
        message += "user channels - these operations must work."

    if (len(CLASSIFIED.get('UNEXPECTED', [])) > 0):

        if status == 0:
            status = 2

        info = "The following test user channels were expected to exist but they didn't, so they could not be deleted again: "

        if not briefing:
            briefing = info
            briefing += "<strong>%s</strong>" % string.join(
                CLASSIFIED['UNEXPECTED'], " | ")
            message = info
        else:
            message += "<br/>" + info

        message += "<br/><br/><strong>%s</strong>" % string.join(
            CLASSIFIED['UNEXPECTED'], "<br/>")
        message += "<br/>The problem is we cannot assert that user channel deletion is working."

    if (len(CLASSIFIED.get('UNEXPECTED_BUT_WORKED', [])) > 0):

        info = "The test following user channels were expected to exist but they didn't, so they could not be deleted again: "

        if not briefing:
            briefing = info
            briefing += "<strong>%s</strong>" % string.join(
                CLASSIFIED['UNEXPECTED_BUT_WORKED'], " | ")
            message = info
        else:
            message += "<br/>" + info

        message += "<br/><br/><strong>%s</strong>" % string.join(
            CLASSIFIED['UNEXPECTED_BUT_WORKED'], "<br/>")
        info = "<br/>But we could assert that user channel deletion worked for some test user channels."
        briefing += info
        message += info
        message += "<br/>We created the expected test user channels and then were successful in deleting them again."

    if (len(CLASSIFIED.get('DELETED', [])) > 0):

        info = "We could successfully assert deletion of the following test user channels: "
        info += "<br/><br/><strong>%s</strong>" % string.join(
            CLASSIFIED['DELETED'], "<br/>")
        info += "<br/>These test user channels were being used for testing purposes."

        if not briefing:
            briefing = "Could successfully delete the following test user channels: "
            briefing += "<strong>%s</strong>" % string.join(
                CLASSIFIED['DELETED'], " | ")
            message = info
        else:
            message += "<br/>" + info

    return (status, briefing, message, None)
Exemple #6
0
def performApproveSubscriptionRequestsPermissionChecks(domain_url, session, tested_username, expected_results):

	(sts, bri, mes, api_location) = findAPILocation(domain_url)
	if ( sts != 0 ):
		return (sts, bri, mes, None)

	if ( tested_username != None ):
		new_follower_username = tested_username + "_new_follower"
	else:
		new_follower_username = "******"

	target_user_channels = [ "test_user_channel_open", "test_user_channel_authorized" ]
	target_topic_channels = [ "test_topic_channel_open" ]

	classified = { 'SUCCESS' : [], 'FAIL' : [], 'PROBLEM_SUBSCRIBING' : [], 'PROBLEM_CREATING' : [] }

	if ( create_user_channel(session, domain_url, api_location, new_follower_username)
			or user_channel_exists(session, domain_url, api_location, new_follower_username) ):

		for channel in target_user_channels:

			if subscribe_to_user_channel(session, domain_url, api_location, new_follower_username, channel, "member"):

				if approve_another_user_channel_subscription_request(session,
						domain_url, api_location, channel, tested_username, [new_follower_username]):
					
					if ("%s@%s" % (channel, domain_url)) in expected_results.get(True,[]):
						classified['SUCCESS'].append("%s@%s" % (channel, domain_url))
					else:
						classified['FAIL'].append("%s@%s" % (channel, domain_url))
				else:

					if ("%s@%s" % (channel, domain_url)) in expected_results.get(False,[]):
						classified['SUCCESS'].append("%s@%s" % (channel, domain_url))
					else:
						classified['FAIL'].append("%s@%s" % (channel, domain_url))

					approve_user_channel_subscription_request(session, domain_url, api_location, channel, [new_follower_username])

			else:
				classified['PROBLEM_SUBSCRIBING'].append("%s@%s" % (channel, domain_url))

		for channel in target_topic_channels:

			if subscribe_to_topic_channel(session, domain_url, api_location, new_follower_username, channel, "member"):

				if approve_another_topic_channel_subscription_request(session,
						domain_url, api_location, channel, target_user_channels[0], tested_username, [new_follower_username]):

					if ("%s@topics.%s" % (channel, domain_url)) in expected_results.get(True,[]):
						classified['SUCCESS'].append("%s@topics.%s" % (channel, domain_url))
					else:
						classified['FAIL'].append("%s@topics.%s" % (channel, domain_url))

				else:	
					if ("%s@topics.%s" % (channel, domain_url)) in expected_results.get(False,[]):
						classified['SUCCESS'].append("%s@topics.%s" % (channel, domain_url))
					else:
						classified['FAIL'].append("%s@topics.%s" % (channel, domain_url))

					approve_topic_channel_subscription_request(session, domain_url, api_location, channel, target_user_channels[0], [new_follower_username])
			else:
				classified['PROBLEM_SUBSCRIBING'].append("%s@topics.%s" % (channel, domain_url))

	else:
		classified['PROBLEM_CREATING'].append("%s@%s" % (new_follower_username, domain_url))


	if ( tested_username != None ):
		tested_username = "******" % (tested_username, domain_url)
	else:
		tested_username = "******"

	if ( len(classified.get('PROBLEM_CREATING', [])) > 0 ):

		status = 2
		briefing = "This test failed because we could not create test user channel <strong>%s</strong>." % classified['PROBLEM_CREATING'][0]
		message = briefing + "<br/>We need that user for testing purposes.<br/><br/>It seems like your HTTP API is problematic."
		return (status, briefing, message, None)

	if ( len(classified.get('PROBLEM_SUBSCRIBING', [])) > 0 ):

		status = 2
		briefing = "Could not have test user channel <strong>%s</strong> "
		briefing += "subscribe to the following channels: "
		new_follower_username = "******" % (new_follower_username, domain_url)
		briefing = briefing % new_follower_username
		message = briefing
		briefing += "<strong>%s</strong>" % string.join(classified['PROBLEM_SUBSCRIBING'], " | ")
		message += "<br/><br/><strong>%s</strong>" % string.join(classified['PROBLEM_SUBSCRIBING'], "<br/>")
		message += "<br/><br/>Thus, we could not test if %s can approve new followers." % tested_username
		return (status, briefing, message, None)

	status = 0
	briefing = ""
	message = ""

	if ( len(classified.get('FAIL', [])) > 0 ):

		status = 1
		briefing = "Approve new followers permission tests for <strong>%s</strong> were not entirely successful!" % tested_username
		message = briefing + "<br/>"

		should_have_permission = sets.Set(expected_results.get(True,[]))
		should_not_have_permission = sets.Set(expected_results.get(False,[]))
		had_problems = sets.Set(classified['FAIL'])

		should_have_permission_but_didnt = should_have_permission.intersection(had_problems)
		should_not_have_permission_but_did = should_not_have_permission.intersection(had_problems)

		if ( len(should_have_permission_but_didnt) > 0 ):

			message = "User %s could not approve subscription requests to the "
			message += "following channels (<strong>and it should be able to!</strong>): "
			message = message % (tested_username)
			message += "<br/><br/><strong>%s</strong><br/>" % string.join(should_have_permission_but_didnt, "<br/>")


		if ( len(should_not_have_permission_but_did) > 0 ):

			if ( message != "" ):
				message += "<br/>"

			message += "User %s could approve subscription requests to the "
			message += "following channels (<strong>and it should not be able to!</strong>): "
			message = message % (tested_username)
			message += "<br/><br/><strong>%s</strong><br/>" % string.join(should_not_have_permission_but_did, "<br/>")

	if ( len(classified.get('SUCCESS', [])) > 0 ):

		if ( briefing == "" ):
			briefing += "User %s has correct approve subscription permissions!" % tested_username

		should_have_permission = sets.Set(expected_results.get(True,[]))
		should_not_have_permission = sets.Set(expected_results.get(False,[]))
		had_no_problems = sets.Set(classified['SUCCESS'])

		should_have_permission_and_did = should_have_permission.intersection(had_no_problems)
		should_not_have_permission_and_didnt = should_not_have_permission.intersection(had_no_problems)

		if ( message != "" ):
			message += "<br/>"

		message += "<span class='muted'>The following approve new followers permission tests were successful: <br/>"

		if ( len(should_have_permission_and_did) > 0 ):

			if ( message != "" ):
				message += "<br/>"

			message += "User %s could approve subscription requests to the "
			message += "following channels (<em>as expected!</em>): "
			message = message % (tested_username)
			message += "<br/><br/><strong>%s</strong><br/>" % string.join(should_have_permission_and_did, "<br/>")

		if ( len(should_not_have_permission_and_didnt) > 0 ):

			if ( message != "" ):
				message += "<br/>"

			message += "User %s could not approve subscription requests to the "
			message += "following channels (<em>as expected!</em>): "
			message = message % (tested_username)
			message += "<br/><br/><strong>%s</strong><br/>" % string.join(should_not_have_permission_and_didnt, "<br/>")

		message += "</span>"

	return (status, briefing, message, None)