def test_name_unique(self):

        # Test first_name uniqueness with null cohort
        user = User.objects.create_user("user1", first_name="First")
        user.save()

        form = UserForm(data={"first_name": user.first_name, "cohort": user.cohort})
        self.assertFalse(form.is_valid())

        form = UserForm(data={"first_name": "adifferentname", "cohort": user.cohort})
        self.assertTrue(form.is_valid())

        # Test with a non-null cohort
        cohort = Cohort.objects.create(
            title="Test Cohort", oauth_key="mykey", oauth_secret="mysecret", login_url="http://google.com"
        )
        user.cohort = cohort
        user.save()

        form = UserForm(data={"first_name": user.first_name, "cohort": user.cohort.id})
        self.assertFalse(form.is_valid())

        form = UserForm(data={"first_name": "adifferentname", "cohort": user.cohort.id})
        self.assertTrue(form.is_valid())

        form = UserForm(data={"first_name": user.first_name, "cohort": None})
        self.assertTrue(form.is_valid())
    def test_time_zone(self):

        # Time zone not required
        data = {"first_name": "*****@*****.**"}
        form = UserForm(data=data)
        self.assertTrue(form.is_valid())

        # Invalid time zones are allowed (enforced by form Widget, not Model)
        data["time_zone"] = "NOT A TIME ZONE"
        form = UserForm(data=data)
        self.assertTrue(form.is_valid())

        # Valid time zone allowed
        data["time_zone"] = "Australia/Adelaide"
        form = UserForm(data=data)
        self.assertTrue(form.is_valid())
    def test_name_required(self):

        # User requires a first_name
        form = UserForm(data={})
        self.assertFalse(form.is_valid())

        # User requires a non-empty first_name
        form = UserForm(data={"first_name": ""})
        self.assertFalse(form.is_valid())

        # User requires a non-empty first_name
        form = UserForm(data={"first_name": "  "})
        self.assertFalse(form.is_valid())

        # User requires a first_name without spaces
        form = UserForm(data={"first_name": "name goes here"})
        self.assertFalse(form.is_valid())

        # User accepts a single word first name.
        form = UserForm(data={"first_name": "*****@*****.**"})
        self.assertTrue(form.is_valid())