def testFunction(domain_url):

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

	expected_results = {
		'ADD_NEW_STATUS_AND_CHECK' : {
			False : [
			"test_user_channel_open@" + domain_url,
			"test_topic_channel_authorized@" + domain_url
			]
		}
	}

	(status, partial_report) = performStatusManagementTests(domain_url, api_location, None, expected_results)

	if status == 0:
		briefing = "Status management tests for <strong>anonymous user</strong> were successful!"
	else:
		briefing = "Status management tests for <strong>anonymous user</strong> were not entirely successful!"

	message = briefing + "<br/>"
	message += partial_report

	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, api_location)

	expected_results = {
		'ADD_NEW_STATUS_AND_CHECK' : {
			True : [
			"test_user_channel_open@" + domain_url
			]
		}
	}

	(status, partial_report) = performStatusManagementTests(session, domain_url, api_location, "test_user_channel_open", expected_results)

	if status == 0:
		briefing = "Status management tests for <strong>test_user_channel_open@%s</strong> were successful!" % domain_url
	else:
		briefing = "Status management tests for <strong>test_user_channel_open@%s</strong> were not entirely successful!" % domain_url

	message = briefing + "<br/>"
	message += partial_report

	return (status, briefing, message, None)
Example #3
0
def testFunction(domain_url, session):

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

    expected_results = {
        'UPDATE_TITLE': {
            True: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url
            ]
        },
        'UPDATE_DESCRIPTION': {
            True: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url
            ]
        },
        'UPDATE_ACCESS_MODEL': {
            True: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url
            ]
        },
        'UPDATE_CREATION_DATE': {
            False: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url
            ]
        },
        'UPDATE_CHANNEL_TYPE': {
            False: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url
            ]
        },
        'UPDATE_DEFAULT_AFFILIATION': {
            True: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url
            ]
        }
    }

    (status, partial_report) = performMetadataModificationTests(
        session, domain_url, api_location, "test_user_channel_open",
        expected_results)

    if status == 0:
        briefing = "Metadata change tests for <strong>test_user_channel_open@%s</strong> were successful!" % domain_url
    else:
        briefing = "Metadata change tests for <strong>test_user_channel_open@%s</strong> were not entirely successful!" % domain_url

    message = briefing + "<br/>"
    message += partial_report

    return (status, briefing, message, None)
Example #4
0
def testFunction(domain_url, session):

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

    expected_results = {
        'ADD_NEW_POST_AND_GET_BY_ID_DIRECT_ACCESS': {
            True: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url,
                "test_user_channel_authorized@" + domain_url
            ]
        },
        'ADD_NEW_POST_AND_GET_BY_MATCHING_ID': {
            True: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url,
                "test_user_channel_authorized@" + domain_url
            ]
        },
        'REMOVE_OWN_POST': {
            True: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url,
                "test_user_channel_authorized@" + domain_url
            ]
        },
        'REMOVE_POST_CREATED_BY_OWNER': {
            True: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url,
                "test_user_channel_authorized@" + domain_url
            ]
        },
        'REMOVE_POST_CREATED_BY_MODERATOR': {
            True: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url,
                "test_user_channel_authorized@" + domain_url
            ]
        }
    }

    (status, partial_report) = performPostsManagementTests(
        session, domain_url, api_location, "test_user_channel_follower1",
        expected_results)

    if status == 0:
        briefing = "Posts management tests for <strong>test_user_channel_follower1@%s</strong> were successful!" % domain_url
    else:
        briefing = "Posts management tests for <strong>test_user_channel_follower1@%s</strong> were not entirely successful!" % domain_url

    message = briefing + "<br/>"
    message += partial_report

    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)

    test_topic_channel_name = "test_topic_channel_open"
    test_topic_channel_owner_username = "******"

    if create_topic_channel(session, domain_url, api_location,
                            test_topic_channel_owner_username,
                            test_topic_channel_name):

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

    else:

        if topic_channel_exists(session, domain_url, api_location,
                                test_topic_channel_name):

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

            if (delete_topic_channel(session, domain_url, api_location,
                                     test_topic_channel_owner_username,
                                     test_topic_channel_name)
                    and create_topic_channel(
                        session, domain_url, api_location,
                        test_topic_channel_owner_username,
                        test_topic_channel_name)):

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

        else:

            status = 1
            briefing = "The test topic channel <strong>%s@topics.%s</strong> could not be created." % (
                test_topic_channel_name, domain_url)
            message = briefing
            message += "<br/>It seems like your HTTP API server is problematic. It had trouble creating a topic 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 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):

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

	expected_results = {
		'UPDATE_TITLE'	: {
			True : [
			"test_user_channel_open@" + domain_url,
			"test_topic_channel_open@topics." + domain_url
			]
		},
		'UPDATE_DESCRIPTION'	: {
			True : [
			"test_user_channel_open@" + domain_url,
			"test_topic_channel_open@topics." + domain_url
			]
		},
		'UPDATE_ACCESS_MODEL'	: {
			True : [
			"test_user_channel_open@" + domain_url,
			"test_topic_channel_open@topics." + domain_url
			]
		},
		'UPDATE_CREATION_DATE'	: {
			False : [
			"test_user_channel_open@" + domain_url,
			"test_topic_channel_open@topics." + domain_url
			]
		},
		'UPDATE_CHANNEL_TYPE'	: {
			False : [
			"test_user_channel_open@" + domain_url,
			"test_topic_channel_open@topics." + domain_url
			]
		},
		'UPDATE_DEFAULT_AFFILIATION' : {
			True : [
			"test_user_channel_open@" + domain_url,
			"test_topic_channel_open@topics." + domain_url
			]
		}
	}

	(status, partial_report) = performMetadataModificationTests(domain_url, api_location, "test_user_channel_open", expected_results)

	if status == 0:
		briefing = "Metadata modification tests for <strong>test_user_channel_open@%s</strong> were successful!" % domain_url
	else:
		briefing = "Metadata modification tests for <strong>test_user_channel_open@%s</strong> were not entirely successful!" % domain_url

	message = briefing + "<br/>"
	message += partial_report

	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, api_location)

	expected_results = {
		'ADD_NEW_POST_AND_GET_BY_ID_DIRECT_ACCESS' : {
			True : [
			"test_user_channel_open@" + domain_url,
			"test_topic_channel_open@topics." + domain_url,
			"test_user_channel_authorized@" + domain_url
			]
		},
		'ADD_NEW_POST_AND_GET_BY_MATCHING_ID' : {
			True : [
			"test_user_channel_open@" + domain_url,
			"test_topic_channel_open@topics." + domain_url,
			"test_user_channel_authorized@" + domain_url
			]
		},
		'REMOVE_OWN_POST' : {
			True : [
			"test_user_channel_open@" + domain_url,
			"test_topic_channel_open@topics." + domain_url,
			"test_user_channel_authorized@" + domain_url
			]
		},
		'REMOVE_POST_CREATED_BY_OWNER' : {
			False : [
			"test_user_channel_open@" + domain_url,
			"test_topic_channel_open@topics." + domain_url,
			"test_user_channel_authorized@" + domain_url
			]
		},
		'REMOVE_POST_CREATED_BY_MODERATOR' : {
			False : [
			"test_user_channel_open@" + domain_url,
			"test_topic_channel_open@topics." + domain_url,
			"test_user_channel_authorized@" + domain_url
			]
		}
	}

	(status, partial_report) = performPostsManagementTests(session, domain_url, api_location, "test_user_channel_follower2", expected_results)

	if status == 0:
		briefing = "Posts management tests for <strong>test_user_channel_follower2@%s</strong> were successful!" % domain_url
	else:
		briefing = "Posts management tests for <strong>test_user_channel_follower2@%s</strong> were not entirely successful!" % domain_url

	message = briefing + "<br/>"
	message += partial_report

	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)

	test_topic_channel_name = "test_topic_channel_open"
	test_topic_channel_owner_username = "******"

	if delete_topic_channel(session, domain_url, api_location, test_topic_channel_owner_username, test_topic_channel_name):
	
		status = 0
		briefing = "Could successfully remove test topic channel: <strong>%s@topics.%s</strong>" % (test_topic_channel_name, domain_url)
		message = "We could successfully assert deletion of test topic channel <strong>%s@topics.%s</strong>." % (test_topic_channel_name, domain_url)
		message += "<br/>That test topic channel was being used for testing purposes."

	else:

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

			status = 1
			briefing = "Channel owner <strong>%s</strong> doesn't exist anymore, so we can't assert that " % test_topic_channel_owner_username
			briefing += "test topic channel deletion is working."
			message = briefing
			message += "<br/>The channel owner <strong>%s</strong> was deleted and " % test_topic_channel_owner_username
			message += " so was its topic channel <strong>%s</strong> along with him." % test_topic_channel_name

		elif not topic_channel_exists(session, domain_url, api_location, test_topic_channel_name):

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

			if ( create_topic_channel(session, domain_url, api_location, test_topic_channel_owner_username, test_topic_channel_name)
			and delete_topic_channel(session, domain_url, api_location, test_topic_channel_owner_username, test_topic_channel_name) ):

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

		else:

			status = 1
			briefing = "The test topic channel <strong>%s@topics.%s</strong> could not be deleted." % (test_topic_channel_name, domain_url)
			message = briefing
			message += "<br/>It seems like your HTTP API server is problematic. It had trouble deleting a topic 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)

	test_topic_channel_name = "test_topic_channel_open"
	test_topic_channel_owner_username = "******"

	if create_topic_channel(session, domain_url, api_location, test_topic_channel_owner_username, test_topic_channel_name):
	
		status = 0
		briefing = "Could successfully create test topic channel: <strong>%s@topics.%s</strong>" % (test_topic_channel_name, domain_url)
		message = "We could successfully assert creation of test topic channel <strong>%s@topics.%s</strong>." % (test_topic_channel_name, domain_url)
		message += "<br/>That topic channel will be used for testing purposes."

	else:

		if topic_channel_exists(session, domain_url, api_location, test_topic_channel_name):

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

			if ( delete_topic_channel(session, domain_url, api_location, test_topic_channel_owner_username, test_topic_channel_name)
			and create_topic_channel(session, domain_url, api_location, test_topic_channel_owner_username, test_topic_channel_name) ):

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

		else:

			status = 1
			briefing = "The test topic channel <strong>%s@topics.%s</strong> could not be created." % (test_topic_channel_name, domain_url)
			message = briefing
			message += "<br/>It seems like your HTTP API server is problematic. It had trouble creating a topic channel - that operation must work."
			
	return (status, briefing, message, None)
def performRoleChangePermissionChecks(domain_url, session, tested_username, expected_results):

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

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

	actual_results_match_expected_results = {}
	status = 0

	for test in expected_results.keys():

		if not test in ROLE_CHANGE_PERMISSION_TESTS:
			continue

		if not test in actual_results_match_expected_results:
			actual_results_match_expected_results[test] = { True : [], False : [] }

		for target_channel_name in expected_results[test].get(True, []):

			if ROLE_CHANGE_PERMISSION_TESTS[test][0](session, api_location, target_channel_name, tested_username, new_follower_username):
				veredict = "%s (%s)" % (target_channel_name, "had permission, as expected")
				actual_results_match_expected_results[test][True].append(veredict)
			else:
				veredict = "%s (%s)" % (target_channel_name, "should have permission")
				actual_results_match_expected_results[test][False].append(veredict)
				status = 1

		for target_channel_name in expected_results[test].get(False, []):

			if ROLE_CHANGE_PERMISSION_TESTS[test][0](session, api_location, target_channel_name, tested_username, new_follower_username):
				veredict = "%s (%s)" % (target_channel_name, "should not have permission")
				actual_results_match_expected_results[test][False].append(veredict)
				status = 1
			else:
				veredict = "%s (%s)" % (target_channel_name, "didn't have permission, as expected")
				actual_results_match_expected_results[test][True].append(veredict)

	if status == 0:
		partial_report = "<br/>Every role change permission test had the expected results!<br/>"
	else:
		partial_report = "<br/>Not all role change permission tests had the expected results!<br/>"

	for test in actual_results_match_expected_results.keys():

		if len(actual_results_match_expected_results[test][(status == 0)]) == 0:
			continue

		partial_report += "<br/><em>%s</em>:<br/><strong>%s</strong>" % (ROLE_CHANGE_PERMISSION_TESTS[test][1],
				string.join(actual_results_match_expected_results[test][(status == 0)], "<br/>"))

	if (status != 0):

		correct_results = ""

		for test in actual_results_match_expected_results.keys():

			if len(actual_results_match_expected_results[test][(status != 0)]) == 0:
				continue

			correct_results += "<br/><em>%s</em>:<br/><strong>%s</strong>" % (ROLE_CHANGE_PERMISSION_TESTS[test][1],
					string.join(actual_results_match_expected_results[test][(status != 0)], "<br/>"))

		if correct_results != "":

			partial_report += "<br/><br/><span class='muted'>The following role change permission tests were successful:<br/>"
			partial_report += correct_results + "</span>"

	return (status, partial_report)
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)
Example #15
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)
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 performVisibilityTests(domain_url, username, expected_results):

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

	actual_results_match_expected_results = {}
	status = 0

	for test in expected_results.keys():

		if not test in VISIBILITY_TESTS:
			continue

		if not test in actual_results_match_expected_results:
			actual_results_match_expected_results[test] = { True : [], False : [] }

		for target_channel_name in expected_results[test].get(True, []):

			if VISIBILITY_TESTS[test][0](api_location, username, target_channel_name):
				veredict = "%s (%s)" % (target_channel_name, "had access, as expected")
				actual_results_match_expected_results[test][True].append(veredict)
			else:
				veredict = "%s (%s)" % (target_channel_name, "should have access")
				actual_results_match_expected_results[test][False].append(veredict)
				status = 1

		for target_channel_name in expected_results[test].get(False, []):

			if VISIBILITY_TESTS[test][0](api_location, username, target_channel_name):
				veredict = "%s (%s)" % (target_channel_name, "should not have access")
				actual_results_match_expected_results[test][False].append(veredict)
				status = 1
			else:
				veredict = "%s (%s)" % (target_channel_name, "didn't have access, as expected")
				actual_results_match_expected_results[test][True].append(veredict)

	if status == 0:
		partial_report = "<br/>Every visibility test had the expected results!<br/>"
	else:
		partial_report = "<br/>Not all visibility tests had the expected results!<br/>"

	for test in actual_results_match_expected_results.keys():

		if len(actual_results_match_expected_results[test][(status == 0)]) == 0:
			continue

		partial_report += "<br/><em>%s</em>:<br/><strong>%s</strong>" % (VISIBILITY_TESTS[test][1],
				string.join(actual_results_match_expected_results[test][(status == 0)], "<br/>"))

	if (status != 0):

		correct_results = ""

		for test in actual_results_match_expected_results.keys():

			if len(actual_results_match_expected_results[test][(status != 0)]) == 0:
				continue

			correct_results += "<br/><em>%s</em>:<br/><strong>%s</strong>" % (VISIBILITY_TESTS[test][1],
					string.join(actual_results_match_expected_results[test][(status != 0)], "<br/>"))

		if correct_results != "":

			partial_report += "<br/><br/><span class='muted'>The following visibility tests were successful:<br/>"
			partial_report += correct_results + "</span>"

	return (status, partial_report)
Example #18
0
def performRoleChangePermissionChecks(domain_url, session, tested_username,
                                      expected_results):

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

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

    actual_results_match_expected_results = {}
    status = 0

    for test in expected_results.keys():

        if not test in ROLE_CHANGE_PERMISSION_TESTS:
            continue

        if not test in actual_results_match_expected_results:
            actual_results_match_expected_results[test] = {True: [], False: []}

        for target_channel_name in expected_results[test].get(True, []):

            if ROLE_CHANGE_PERMISSION_TESTS[test][0](session, api_location,
                                                     target_channel_name,
                                                     tested_username,
                                                     new_follower_username):
                veredict = "%s (%s)" % (target_channel_name,
                                        "had permission, as expected")
                actual_results_match_expected_results[test][True].append(
                    veredict)
            else:
                veredict = "%s (%s)" % (target_channel_name,
                                        "should have permission")
                actual_results_match_expected_results[test][False].append(
                    veredict)
                status = 1

        for target_channel_name in expected_results[test].get(False, []):

            if ROLE_CHANGE_PERMISSION_TESTS[test][0](session, api_location,
                                                     target_channel_name,
                                                     tested_username,
                                                     new_follower_username):
                veredict = "%s (%s)" % (target_channel_name,
                                        "should not have permission")
                actual_results_match_expected_results[test][False].append(
                    veredict)
                status = 1
            else:
                veredict = "%s (%s)" % (target_channel_name,
                                        "didn't have permission, as expected")
                actual_results_match_expected_results[test][True].append(
                    veredict)

    if status == 0:
        partial_report = "<br/>Every role change permission test had the expected results!<br/>"
    else:
        partial_report = "<br/>Not all role change permission tests had the expected results!<br/>"

    for test in actual_results_match_expected_results.keys():

        if len(actual_results_match_expected_results[test][(
                status == 0)]) == 0:
            continue

        partial_report += "<br/><em>%s</em>:<br/><strong>%s</strong>" % (
            ROLE_CHANGE_PERMISSION_TESTS[test][1],
            string.join(
                actual_results_match_expected_results[test][(status == 0)],
                "<br/>"))

    if (status != 0):

        correct_results = ""

        for test in actual_results_match_expected_results.keys():

            if len(actual_results_match_expected_results[test][(status !=
                                                                0)]) == 0:
                continue

            correct_results += "<br/><em>%s</em>:<br/><strong>%s</strong>" % (
                ROLE_CHANGE_PERMISSION_TESTS[test][1],
                string.join(
                    actual_results_match_expected_results[test][(status != 0)],
                    "<br/>"))

        if correct_results != "":

            partial_report += "<br/><br/><span class='muted'>The following role change permission tests were successful:<br/>"
            partial_report += correct_results + "</span>"

    return (status, partial_report)
Example #19
0
def testFunction(domain_url, session):

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

    test_topic_channel_name = "test_topic_channel_open"
    test_topic_channel_owner_username = "******"

    if delete_topic_channel(session, domain_url, api_location,
                            test_topic_channel_owner_username,
                            test_topic_channel_name):

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

    else:

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

            status = 1
            briefing = "Channel owner <strong>%s</strong> doesn't exist anymore, so we can't assert that " % test_topic_channel_owner_username
            briefing += "test topic channel deletion is working."
            message = briefing
            message += "<br/>The channel owner <strong>%s</strong> was deleted and " % test_topic_channel_owner_username
            message += " so was its topic channel <strong>%s</strong> along with him." % test_topic_channel_name

        elif not topic_channel_exists(session, domain_url, api_location,
                                      test_topic_channel_name):

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

            if (create_topic_channel(session, domain_url, api_location,
                                     test_topic_channel_owner_username,
                                     test_topic_channel_name)
                    and delete_topic_channel(
                        session, domain_url, api_location,
                        test_topic_channel_owner_username,
                        test_topic_channel_name)):

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

        else:

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

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

	CLASSIFIED = { 'SUBSCRIBED' : [],
		'PROBLEM_SUBSCRIBING_ASKING' : [],
		'PROBLEM_SUBSCRIBING_APPROVING' : [],
		'PROBLEM_CHANGING_SUBSCRIBER_ROLE' : [],
		'PROBLEM_DID_NOT_PROMOTE' : []}

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

	for moderated_channel in MODERATED_USER_CHANNELS:

		if subscribe_to_user_channel(session, domain_url, api_location, MODERATOR_USERNAME, moderated_channel, "member"):
			
			if approve_user_channel_subscription_request(session, domain_url, api_location, moderated_channel, [MODERATOR_USERNAME]):

				if change_user_channel_subscriber_role(session, domain_url, api_location, moderated_channel, MODERATOR_USERNAME, "moderator"):

					if has_subscriber_role_in_user_channel(session, domain_url, api_location, MODERATOR_USERNAME, moderated_channel, "moderator"):
						CLASSIFIED['SUBSCRIBED'].append(moderated_channel + "@" + domain_url)
					else:
						CLASSIFIED['PROBLEM_DID_NOT_PROMOTE'].append(moderated_channel + "@" + domain_url)

				else:
					CLASSIFIED['PROBLEM_CHANGING_SUBSCRIBER_ROLE'].append(moderated_channel + "@" + domain_url)

			else:
				CLASSIFIED['PROBLEM_SUBSCRIBING_APPROVING'].append(moderated_channel + "@" + domain_url)

		else:
			CLASSIFIED['PROBLEM_SUBSCRIBING_ASKING'].append(moderated_channel + "@" + domain_url)

	for moderated_channel in [MODERATED_TOPIC_CHANNEL]:

		if subscribe_to_topic_channel(session, domain_url, api_location, MODERATOR_USERNAME, moderated_channel, "member"):
	
			if approve_topic_channel_subscription_request(session, domain_url, api_location, moderated_channel, MODERATED_USER_CHANNELS[0], [MODERATOR_USERNAME]):

				if change_topic_channel_subscriber_role(session, domain_url, api_location, MODERATED_USER_CHANNELS[0], MODERATOR_USERNAME, moderated_channel, "moderator"):

					if has_subscriber_role_in_topic_channel(session, domain_url, api_location, MODERATOR_USERNAME, moderated_channel, "moderator"):
						CLASSIFIED['SUBSCRIBED'].append(moderated_channel + "@" + domain_url)
					else:
						CLASSIFIED['PROBLEM_DID_NOT_PROMOTE'].append(moderated_channel + "@" + domain_url)

				else:
					CLASSIFIED['PROBLEM_CHANGING_SUBSCRIBER_ROLE'].append(moderated_channel + "@" + domain_url)

			else:
				CLASSIFIED['PROBLEM_SUBSCRIBING_APPROVING'].append(moderated_channel + "@" + domain_url)

		else:
			CLASSIFIED['PROBLEM_SUBSCRIBING_ASKING'].append(moderated_channel + "@" + domain_url)

	status = 0

	if ( ( len(CLASSIFIED.get('PROBLEM_SUBSCRIBING_ASKING', [])) > 0)
	or ( len(CLASSIFIED.get('PROBLEM_SUBSCRIBING_APPROVING', [])) > 0 )
	or ( len(CLASSIFIED.get('PROBLEM_CHANGING_SUBSCRIBER_ROLE', [])) > 0 )
	or ( len(CLASSIFIED.get('PROBLEM_DID_NOT_PROMOTE', [])) > 0 ) ):

		problematic_channels = string.join(CLASSIFIED.get('PROBLEM_SUBSCRIBING_ASKING', []) + CLASSIFIED.get('PROBLEM_SUBSCRIBING_APPROVING', []) + CLASSIFIED.get('PROBLEM_CHANGING_SUBSCRIBER_ROLE', []) + CLASSIFIED.get('PROBLEM_DID_NOT_PROMOTE', []), " | ")

		status = 1
		briefing = "Could not have some of these test channels promote <strong>%s@%s</strong> to <em>moderator</em>: <br/><br/>" % (MODERATOR_USERNAME, domain_url)
		briefing += "<strong>%s</strong>" % problematic_channels
		message = "Something weird happened while we tried having some test channels promote <strong>%s@%s</strong> to <em>moderator</em> for testing purposes." % (MODERATOR_USERNAME, domain_url)
		message += "<br/>The following test channels were problematic: <br/><br/>"
		message += "<strong>%s</strong>" % problematic_channels
		message += "<br/><br/>It seems like your HTTP API is problematic."

	else:

		briefing = "Could successfully have these test channels promote <strong>%s@%s</strong> to <em>moderator</em>: " % (MODERATOR_USERNAME, domain_url)
		briefing += "<strong>%s</strong>" % string.join(CLASSIFIED.get('SUBSCRIBED', []), " | ")
		message = "We could assert that these user channels which will be used later for testing purposes"
		message += " could successfully promote <strong>%s@%s</strong> to <em>moderator</em>:" % (MODERATOR_USERNAME, domain_url)
		message += "<br/><br/><strong>%s</strong>" % string.join(CLASSIFIED.get('SUBSCRIBED', []), "<br/>")

	return (status, briefing, message, None)
def performVisibilityTests(session, domain_url, username, expected_results):

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

    actual_results_match_expected_results = {}
    status = 0

    for test in expected_results.keys():

        if not test in VISIBILITY_TESTS:
            continue

        if not test in actual_results_match_expected_results:
            actual_results_match_expected_results[test] = {True: [], False: []}

        for target_channel_name in expected_results[test].get(True, []):

            if VISIBILITY_TESTS[test][0](session, api_location, username,
                                         target_channel_name):
                veredict = "%s (%s)" % (target_channel_name,
                                        "had access, as expected")
                actual_results_match_expected_results[test][True].append(
                    veredict)
            else:
                veredict = "%s (%s)" % (target_channel_name,
                                        "should have access")
                actual_results_match_expected_results[test][False].append(
                    veredict)
                status = 1

        for target_channel_name in expected_results[test].get(False, []):

            if VISIBILITY_TESTS[test][0](session, api_location, username,
                                         target_channel_name):
                veredict = "%s (%s)" % (target_channel_name,
                                        "should not have access")
                actual_results_match_expected_results[test][False].append(
                    veredict)
                status = 1
            else:
                veredict = "%s (%s)" % (target_channel_name,
                                        "didn't have access, as expected")
                actual_results_match_expected_results[test][True].append(
                    veredict)

    if status == 0:
        partial_report = "<br/>Every visibility test had the expected results!<br/>"
    else:
        partial_report = "<br/>Not all visibility tests had the expected results!<br/>"

    for test in actual_results_match_expected_results.keys():

        if len(actual_results_match_expected_results[test][(
                status == 0)]) == 0:
            continue

        partial_report += "<br/><em>%s</em>:<br/><strong>%s</strong>" % (
            VISIBILITY_TESTS[test][1],
            string.join(
                actual_results_match_expected_results[test][(status == 0)],
                "<br/>"))

    if (status != 0):

        correct_results = ""

        for test in actual_results_match_expected_results.keys():

            if len(actual_results_match_expected_results[test][(status !=
                                                                0)]) == 0:
                continue

            correct_results += "<br/><em>%s</em>:<br/><strong>%s</strong>" % (
                VISIBILITY_TESTS[test][1],
                string.join(
                    actual_results_match_expected_results[test][(status != 0)],
                    "<br/>"))

        if correct_results != "":

            partial_report += "<br/><br/><span class='muted'>The following visibility tests were successful:<br/>"
            partial_report += correct_results + "</span>"

    return (status, partial_report)
def testFunction(domain_url, session):

    CLASSIFIED = {
        'SUBSCRIBED': [],
        'PROBLEM_SUBSCRIBING_ASKING': [],
        'PROBLEM_SUBSCRIBING_APPROVING': [],
        'PROBLEM_CHANGING_SUBSCRIBER_ROLE': [],
        'PROBLEM_DID_NOT_PROMOTE': []
    }

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

    for moderated_channel in MODERATED_USER_CHANNELS:

        if subscribe_to_user_channel(session, domain_url, api_location,
                                     MODERATOR_USERNAME, moderated_channel,
                                     "member"):

            if approve_user_channel_subscription_request(
                    session, domain_url, api_location, moderated_channel,
                [MODERATOR_USERNAME]):

                if change_user_channel_subscriber_role(session, domain_url,
                                                       api_location,
                                                       moderated_channel,
                                                       MODERATOR_USERNAME,
                                                       "moderator"):

                    if has_subscriber_role_in_user_channel(
                            session, domain_url, api_location,
                            MODERATOR_USERNAME, moderated_channel,
                            "moderator"):
                        CLASSIFIED['SUBSCRIBED'].append(moderated_channel +
                                                        "@" + domain_url)
                    else:
                        CLASSIFIED['PROBLEM_DID_NOT_PROMOTE'].append(
                            moderated_channel + "@" + domain_url)

                else:
                    CLASSIFIED['PROBLEM_CHANGING_SUBSCRIBER_ROLE'].append(
                        moderated_channel + "@" + domain_url)

            else:
                CLASSIFIED['PROBLEM_SUBSCRIBING_APPROVING'].append(
                    moderated_channel + "@" + domain_url)

        else:
            CLASSIFIED['PROBLEM_SUBSCRIBING_ASKING'].append(moderated_channel +
                                                            "@" + domain_url)

    for moderated_channel in [MODERATED_TOPIC_CHANNEL]:

        if subscribe_to_topic_channel(session, domain_url, api_location,
                                      MODERATOR_USERNAME, moderated_channel,
                                      "member"):

            if approve_topic_channel_subscription_request(
                    session, domain_url, api_location, moderated_channel,
                    MODERATED_USER_CHANNELS[0], [MODERATOR_USERNAME]):

                if change_topic_channel_subscriber_role(
                        session, domain_url, api_location,
                        MODERATED_USER_CHANNELS[0], MODERATOR_USERNAME,
                        moderated_channel, "moderator"):

                    if has_subscriber_role_in_topic_channel(
                            session, domain_url, api_location,
                            MODERATOR_USERNAME, moderated_channel,
                            "moderator"):
                        CLASSIFIED['SUBSCRIBED'].append(moderated_channel +
                                                        "@" + domain_url)
                    else:
                        CLASSIFIED['PROBLEM_DID_NOT_PROMOTE'].append(
                            moderated_channel + "@" + domain_url)

                else:
                    CLASSIFIED['PROBLEM_CHANGING_SUBSCRIBER_ROLE'].append(
                        moderated_channel + "@" + domain_url)

            else:
                CLASSIFIED['PROBLEM_SUBSCRIBING_APPROVING'].append(
                    moderated_channel + "@" + domain_url)

        else:
            CLASSIFIED['PROBLEM_SUBSCRIBING_ASKING'].append(moderated_channel +
                                                            "@" + domain_url)

    status = 0

    if ((len(CLASSIFIED.get('PROBLEM_SUBSCRIBING_ASKING', [])) > 0)
            or (len(CLASSIFIED.get('PROBLEM_SUBSCRIBING_APPROVING', [])) > 0)
            or
        (len(CLASSIFIED.get('PROBLEM_CHANGING_SUBSCRIBER_ROLE', [])) > 0)
            or (len(CLASSIFIED.get('PROBLEM_DID_NOT_PROMOTE', [])) > 0)):

        problematic_channels = string.join(
            CLASSIFIED.get('PROBLEM_SUBSCRIBING_ASKING', []) +
            CLASSIFIED.get('PROBLEM_SUBSCRIBING_APPROVING', []) +
            CLASSIFIED.get('PROBLEM_CHANGING_SUBSCRIBER_ROLE', []) +
            CLASSIFIED.get('PROBLEM_DID_NOT_PROMOTE', []), " | ")

        status = 1
        briefing = "Could not have some of these test channels promote <strong>%s@%s</strong> to <em>moderator</em>: <br/><br/>" % (
            MODERATOR_USERNAME, domain_url)
        briefing += "<strong>%s</strong>" % problematic_channels
        message = "Something weird happened while we tried having some test channels promote <strong>%s@%s</strong> to <em>moderator</em> for testing purposes." % (
            MODERATOR_USERNAME, domain_url)
        message += "<br/>The following test channels were problematic: <br/><br/>"
        message += "<strong>%s</strong>" % problematic_channels
        message += "<br/><br/>It seems like your HTTP API is problematic."

    else:

        briefing = "Could successfully have these test channels promote <strong>%s@%s</strong> to <em>moderator</em>: " % (
            MODERATOR_USERNAME, domain_url)
        briefing += "<strong>%s</strong>" % string.join(
            CLASSIFIED.get('SUBSCRIBED', []), " | ")
        message = "We could assert that these user channels which will be used later for testing purposes"
        message += " could successfully promote <strong>%s@%s</strong> to <em>moderator</em>:" % (
            MODERATOR_USERNAME, domain_url)
        message += "<br/><br/><strong>%s</strong>" % string.join(
            CLASSIFIED.get('SUBSCRIBED', []), "<br/>")

    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, api_location)

    expected_results = {
        "UPDATE_TITLE": {
            False: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url,
                "test_user_channel_authorized@" + domain_url,
            ]
        },
        "UPDATE_DESCRIPTION": {
            False: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url,
                "test_user_channel_authorized@" + domain_url,
            ]
        },
        "UPDATE_ACCESS_MODEL": {
            False: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url,
                "test_user_channel_authorized@" + domain_url,
            ]
        },
        "UPDATE_CREATION_DATE": {
            False: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url,
                "test_user_channel_authorized@" + domain_url,
            ]
        },
        "UPDATE_CHANNEL_TYPE": {
            False: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url,
                "test_user_channel_authorized@" + domain_url,
            ]
        },
        "UPDATE_DEFAULT_AFFILIATION": {
            False: [
                "test_user_channel_open@" + domain_url,
                "test_topic_channel_open@topics." + domain_url,
                "test_user_channel_authorized@" + domain_url,
            ]
        },
    }

    (status, partial_report) = performMetadataModificationTests(
        session, domain_url, api_location, "test_user_channel_follower2", expected_results
    )

    if status == 0:
        briefing = (
            "Metadata change tests for <strong>test_user_channel_follower2@%s</strong> were successful!" % domain_url
        )
    else:
        briefing = (
            "Metadata change tests for <strong>test_user_channel_follower2@%s</strong> were not entirely successful!"
            % domain_url
        )

    message = briefing + "<br/>"
    message += partial_report

    return (status, briefing, message, None)