def test_add_country_preferences(self):
        """ Tests that adding country preferences works """
        # Initialization
        params = self.valid_params.copy()
        for i in xrange(1,11):
            params['country_pref' + str(i)] = 0

        # No preferences at all
        params['school_name'] = 'CountryTest1'
        form = RegistrationForm(params)

        self.assertTrue(form.is_valid())
        school = form.create_school()
        self.assertTrue(form.add_country_preferences(school))

        prefs = CountryPreference.objects.filter(school=school)
        self.assertEqual(len(prefs), 0)

        # Couple of random preferences scattered around
        params['school_name'] = 'CountryTest2'
        params['country_pref1'] = 2
        params['country_pref3'] = 10
        params['country_pref7'] = 7
        form = RegistrationForm(params)

        self.assertTrue(form.is_valid())
        school = form.create_school()
        self.assertTrue(form.add_country_preferences(school))

        prefs = CountryPreference.objects.filter(school=school)
        self.assertEqual(len(prefs), 3)

        self.assertEqual(prefs[0].country.id, params['country_pref1'])
        self.assertEqual(prefs[1].country.id, params['country_pref3'])
        self.assertEqual(prefs[2].country.id, params['country_pref7'])
Exemple #2
0
    def test_add_country_preferences(self):
        """ Tests that adding country preferences works """
        # Initialization
        params = self.valid_params.copy()
        for i in xrange(1, 11):
            params['country_pref' + str(i)] = 0

        # No preferences at all
        params['school_name'] = 'CountryTest1'
        form = RegistrationForm(params)

        self.assertTrue(form.is_valid())
        school = form.create_school()
        self.assertTrue(form.add_country_preferences(school))

        prefs = CountryPreference.objects.filter(school=school)
        self.assertEqual(len(prefs), 0)

        # Couple of random preferences scattered around
        params['school_name'] = 'CountryTest2'
        params['country_pref1'] = 2
        params['country_pref3'] = 10
        params['country_pref7'] = 7
        form = RegistrationForm(params)

        self.assertTrue(form.is_valid())
        school = form.create_school()
        self.assertTrue(form.add_country_preferences(school))

        prefs = CountryPreference.objects.filter(school=school)
        self.assertEqual(len(prefs), 3)

        self.assertEqual(prefs[0].country.id, params['country_pref1'])
        self.assertEqual(prefs[1].country.id, params['country_pref3'])
        self.assertEqual(prefs[2].country.id, params['country_pref7'])
Exemple #3
0
    def test_school_uniqueness(self):
        """ Tests that the school name checks if it's unique """
        params = self.valid_params.copy()
        params['school_name'] = 'MySchool'

        # This should be valid, as 'abcdef' should be unique
        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())
        form.create_school()

        # This shouldn't be valid.
        form = RegistrationForm(params)
        self.assertFalse(form.is_valid())

        self.assertEqual(len(form.errors), 1)
        self.assertIn('school_name', form.errors)
        self.assertItemsEqual(form.errors['school_name'], [
            'A school with the name "%s" has already been registered.' %
            (params['school_name'])
        ])

        # Now try another valid one
        params['school_name'] = 'MySchool2'
        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())
    def test_school_uniqueness(self):
        """ Tests that the school name checks if it's unique """
        params = self.valid_params.copy()
        params['school_name'] = 'MySchool'

        # This should be valid, as 'abcdef' should be unique
        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())
        form.create_school()

        # This shouldn't be valid.
        form = RegistrationForm(params)
        self.assertFalse(form.is_valid())

        self.assertEqual(len(form.errors), 1)
        self.assertIn('school_name', form.errors)
        self.assertItemsEqual(form.errors['school_name'], ['A school with the name "%s" has already been registered.' % (params['school_name'])])

        # Now try another valid one
        params['school_name'] = 'MySchool2'
        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())
Exemple #5
0
    def test_school_uniqueness(self):
        """ Tests that the school name checks if it's unique """
        params = self.valid_params.copy()
        params["SchoolName"] = "MySchool"

        # This should be valid, as "abcdef" should be unique
        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())
        form.create_school()

        # This shouldn't be valid.
        form = RegistrationForm(params)
        self.assertFalse(form.is_valid())

        self.assertEqual(len(form.errors), 1)
        self.assertIn("SchoolName", form.errors)
        self.assertItemsEqual(form.errors["SchoolName"], ["A school with the name '%s' has already been registered." % (params["SchoolName"])])

        # Now try another valid one
        params["SchoolName"] = "MySchool2"
        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())
    def test_add_committee_preferences(self):
        """ Tests that adding committee preferences works """
        params = self.valid_params.copy()
        params['school_name'] = 'CommitteeTest1'
        form = RegistrationForm(params)

        # No committee preferences
        self.assertTrue(form.is_valid())
        school = form.create_school()
        self.assertTrue(form.add_committee_preferences(school))
        self.assertEqual(len(school.committeepreferences.all()), 0)

        # Some preferences
        params['committee_prefs'] = [13, 14, 19]
        params['school_name'] = 'CommitteeTest2'
        form = RegistrationForm(params)

        self.assertTrue(form.is_valid())
        school = form.create_school()
        self.assertTrue(form.add_committee_preferences(school))
        self.assertEqual(len(school.committeepreferences.all()), 3)

        for committee in school.committeepreferences.all():
            self.assertIn(committee.id, params['committee_prefs'])
Exemple #7
0
    def test_add_committee_preferences(self):
        """ Tests that adding committee preferences works """
        params = self.valid_params.copy()
        params['school_name'] = 'CommitteeTest1'
        form = RegistrationForm(params)

        # No committee preferences
        self.assertTrue(form.is_valid())
        school = form.create_school()
        self.assertTrue(form.add_committee_preferences(school))
        self.assertEqual(len(school.committeepreferences.all()), 0)

        # Some preferences
        params['committee_prefs'] = [13, 14, 19]
        params['school_name'] = 'CommitteeTest2'
        form = RegistrationForm(params)

        self.assertTrue(form.is_valid())
        school = form.create_school()
        self.assertTrue(form.add_committee_preferences(school))
        self.assertEqual(len(school.committeepreferences.all()), 3)

        for committee in school.committeepreferences.all():
            self.assertIn(committee.id, params['committee_prefs'])
Exemple #8
0
    def test_create_advisor_profile(self):
        """ Tests that an advisor profile for a user and a school is successfully created upon registration """
        params = self.valid_params.copy()
        params["Username"] = "******"
        params["SchoolName"] = "advisor_profile_test"
        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())

        user = form.create_user()
        school = form.create_school()

        profile = form.create_advisor_profile(user, school)
        self.assertFalse(profile is None)

        self.assertEqual(profile.user, user)
        self.assertEqual(profile.school, school)
    def test_create_school(self):
        """ Tests that the form creates a school object in the DB properly """

        # Test that American schools are created properly
        params = self.valid_params.copy()
        params['school_name'] = 'GirlsGeneration'

        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())

        school = form.create_school()
        self.assertFalse(school is None)

        self.assertEqual(school.name, params['school_name'])
        self.assertEqual(school.address, params['school_address'])
        self.assertEqual(school.city, params['school_city'])
        self.assertEqual(school.state, params['school_state'])
        self.assertEqual(school.zip_code, str(params['school_zip']))
        self.assertEqual(school.primary_name, params['primary_name'])
        self.assertEqual(school.primary_email, params['primary_email'])
        self.assertEqual(school.primary_phone, params['primary_phone'])
        self.assertEqual(school.program_type, params['program_type'])
        self.assertEqual(school.times_attended, params['times_attended'])
        self.assertEqual(school.min_delegation_size, params['min_delegation_size'])
        self.assertEqual(school.max_delegation_size, params['max_delegation_size'])
        self.assertFalse(school.international)

        # Make sure state isn't an empty string, or a string of spaces
        # Bit unnecessary though
        matches = re.match('^\s*$', school.state)
        self.assertTrue(matches is None)

        if 'secondary_name' in params:
            self.assertEqual(school.secondary_name, params['secondary_name'])
        if 'secondary_email' in params:
            self.assertEqual(school.secondary_email, params['secondary_email'])
        if 'secondary_phone' in params:
            self.assertEqual(school.secondary_phone, params['secondary_phone'])

        # Check to see that it's in the database as well
        schools_in_db = School.objects.filter(name=params['school_name'])
        self.assertGreater(len(schools_in_db), 0)
        self.assertEqual(schools_in_db[0], school)

        # Test international school creation
        params['school_name'] = 'GirlsGenerationInternational'
        params['school_country'] = '10'
        params['school_location'] = School.LOCATION_INTERNATIONAL
        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())

        school = form.create_school()
        self.assertFalse(school is None)
        self.assertEqual(school.name, params['school_name'])
        self.assertEqual(school.address, params['school_address'])
        self.assertEqual(school.city, params['school_city'])
        self.assertEqual(school.zip_code, str(params['school_zip']))
        self.assertEqual(school.country, params['school_country'])
        self.assertEqual(school.primary_name, params['primary_name'])
        self.assertEqual(school.primary_email, params['primary_email'])
        self.assertEqual(school.primary_phone, params['primary_phone'])
        self.assertEqual(school.program_type, params['program_type'])
        self.assertEqual(school.times_attended, params['times_attended'])
        self.assertEqual(school.min_delegation_size, params['min_delegation_size'])
        self.assertEqual(school.max_delegation_size, params['max_delegation_size'])
        self.assertTrue(school.international)

        if 'school_state' in params:
            self.assertEqual(school.state, params['school_state'])
        if 'secondary_name' in params:
            self.assertEqual(school.secondary_name, params['secondary_name'])
        if 'secondary_email' in params:
            self.assertEqual(school.secondary_email, params['secondary_email'])
        if 'secondary_phone' in params:
            self.assertEqual(school.secondary_phone, params['secondary_phone'])

        # Check to see that it's in the database as well
        schools_in_db = School.objects.filter(name=params['school_name'])
        self.assertGreater(len(schools_in_db), 0)
        self.assertEqual(schools_in_db[0], school)
Exemple #10
0
    def test_create_school(self):
        """ Tests that the form creates a school object in the DB properly """

        # Test that American schools are created properly
        params = self.valid_params.copy()
        params["SchoolName"] = "GirlsGeneration"

        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())

        school = form.create_school()
        self.assertFalse(school is None)

        self.assertEqual(school.name, params["SchoolName"])
        self.assertEqual(school.address, params["SchoolAddress"])
        self.assertEqual(school.city, params["SchoolCity"])
        self.assertEqual(school.state, params["SchoolState"])
        self.assertEqual(school.zip_code, str(params["SchoolZip"]))
        self.assertEqual(school.primary_name, params["PrimaryName"])
        self.assertEqual(school.primary_email, params["PrimaryEmail"])
        self.assertEqual(school.primary_phone, params["PrimaryPhone"])
        self.assertEqual(school.program_type, params["program_type"])
        self.assertEqual(school.times_attended, params["howmany"])
        self.assertEqual(school.min_delegation_size, params["MinDelegation"])
        self.assertEqual(school.max_delegation_size, params["MaxDelegation"])
        self.assertFalse(school.international)

        # Make sure state isn't an empty string, or a string of spaces
        # Bit unnecessary though
        matches = re.match("^\s*$", school.state)
        self.assertTrue(matches is None)

        if "SecondaryName" in params:
            self.assertEqual(school.secondary_name, params["SecondaryName"])
        if "SecondaryEmail" in params:
            self.assertEqual(school.secondary_email, params["SecondaryEmail"])
        if "SecondaryPhone" in params:
            self.assertEqual(school.secondary_phone, params["SecondaryPhone"])

        # Check to see that it's in the database as well
        schools_in_db = School.objects.filter(name=params["SchoolName"])
        self.assertGreater(len(schools_in_db), 0)
        self.assertEqual(schools_in_db[0], school)

        # Test international school creation
        params["SchoolName"] = "GirlsGenerationInternational"
        params["SchoolCountry"] = 10
        params["us_or_int"] = "international"
        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())

        school = form.create_school()
        self.assertFalse(school is None)
        self.assertEqual(school.name, params["SchoolName"])
        self.assertEqual(school.address, params["SchoolAddress"])
        self.assertEqual(school.city, params["SchoolCity"])
        self.assertEqual(school.zip_code, str(params["SchoolZip"]))
        #self.assertEqual(school.country, params["SchoolCountry"]) TODO
        self.assertEqual(school.primary_name, params["PrimaryName"])
        self.assertEqual(school.primary_email, params["PrimaryEmail"])
        self.assertEqual(school.primary_phone, params["PrimaryPhone"])
        self.assertEqual(school.program_type, params["program_type"])
        self.assertEqual(school.times_attended, params["howmany"])
        self.assertEqual(school.min_delegation_size, params["MinDelegation"])
        self.assertEqual(school.max_delegation_size, params["MaxDelegation"])
        self.assertTrue(school.international)

        if "SchoolState" in params:
            self.assertEqual(school.state, params["SchoolState"])
        if "SecondaryName" in params:
            self.assertEqual(school.secondary_name, params["SecondaryName"])
        if "SecondaryEmail" in params:
            self.assertEqual(school.secondary_email, params["SecondaryEmail"])
        if "SecondaryPhone" in params:
            self.assertEqual(school.secondary_phone, params["SecondaryPhone"])

        # Check to see that it's in the database as well
        schools_in_db = School.objects.filter(name=params["SchoolName"])
        self.assertGreater(len(schools_in_db), 0)
        self.assertEqual(schools_in_db[0], school)
Exemple #11
0
    def test_create_school(self):
        """ Tests that the form creates a school object in the DB properly """

        # Test that American schools are created properly
        params = self.valid_params.copy()
        params['school_name'] = 'GirlsGeneration'

        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())

        school = form.create_school()
        self.assertFalse(school is None)

        self.assertEqual(school.name, params['school_name'])
        self.assertEqual(school.address, params['school_address'])
        self.assertEqual(school.city, params['school_city'])
        self.assertEqual(school.state, params['school_state'])
        self.assertEqual(school.zip_code, str(params['school_zip']))
        self.assertEqual(school.primary_name, params['primary_name'])
        self.assertEqual(school.primary_email, params['primary_email'])
        self.assertEqual(school.primary_phone, params['primary_phone'])
        self.assertEqual(school.program_type, params['program_type'])
        self.assertEqual(school.times_attended, params['times_attended'])
        self.assertEqual(school.min_delegation_size,
                         params['min_delegation_size'])
        self.assertEqual(school.max_delegation_size,
                         params['max_delegation_size'])
        self.assertFalse(school.international)

        # Make sure state isn't an empty string, or a string of spaces
        # Bit unnecessary though
        matches = re.match('^\s*$', school.state)
        self.assertTrue(matches is None)

        if 'secondary_name' in params:
            self.assertEqual(school.secondary_name, params['secondary_name'])
        if 'secondary_email' in params:
            self.assertEqual(school.secondary_email, params['secondary_email'])
        if 'secondary_phone' in params:
            self.assertEqual(school.secondary_phone, params['secondary_phone'])

        # Check to see that it's in the database as well
        schools_in_db = School.objects.filter(name=params['school_name'])
        self.assertGreater(len(schools_in_db), 0)
        self.assertEqual(schools_in_db[0], school)

        # Test international school creation
        params['school_name'] = 'GirlsGenerationInternational'
        params['school_country'] = '10'
        params['school_location'] = School.LOCATION_INTERNATIONAL
        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())

        school = form.create_school()
        self.assertFalse(school is None)
        self.assertEqual(school.name, params['school_name'])
        self.assertEqual(school.address, params['school_address'])
        self.assertEqual(school.city, params['school_city'])
        self.assertEqual(school.zip_code, str(params['school_zip']))
        self.assertEqual(school.country, params['school_country'])
        self.assertEqual(school.primary_name, params['primary_name'])
        self.assertEqual(school.primary_email, params['primary_email'])
        self.assertEqual(school.primary_phone, params['primary_phone'])
        self.assertEqual(school.program_type, params['program_type'])
        self.assertEqual(school.times_attended, params['times_attended'])
        self.assertEqual(school.min_delegation_size,
                         params['min_delegation_size'])
        self.assertEqual(school.max_delegation_size,
                         params['max_delegation_size'])
        self.assertTrue(school.international)

        if 'school_state' in params:
            self.assertEqual(school.state, params['school_state'])
        if 'secondary_name' in params:
            self.assertEqual(school.secondary_name, params['secondary_name'])
        if 'secondary_email' in params:
            self.assertEqual(school.secondary_email, params['secondary_email'])
        if 'secondary_phone' in params:
            self.assertEqual(school.secondary_phone, params['secondary_phone'])

        # Check to see that it's in the database as well
        schools_in_db = School.objects.filter(name=params['school_name'])
        self.assertGreater(len(schools_in_db), 0)
        self.assertEqual(schools_in_db[0], school)