Exemplo n.º 1
0
class TestPerson(TestCase):

    def setup(self):
        self.person1 = Person("*****@*****.**", "DEFAULT_PASSWORD")
        self.person2 = Person("*****@*****.**", "DEFAULT_PASSWORD")

    def test_init_(self):
        self.assertEquals(self.person1.email, "*****@*****.**")
        self.assertEquals(self.person1.password, "DEFAULT_PASSWORD")
        self.assertEquals(self.person1.name, "DEFAULT")
        self.assertEquals(self.person1.phone_number, 0000000000)

    def test_change_password(self):
        self.assertTrue(self.person1.change_password("DEFAULT_PASSWORD", "password"))
        self.assertEquals(self.person1.password, "password")
        self.assertNotEquals(self.person1.password, "DEFAULT_PASSWORD")
        self.assertFalse(self.person1.change_password("DEFAULT_PASSWORD", "some_password"))

    def test_change_email(self):
        self.person1.change_email("*****@*****.**")
        self.assertEquals(self.person1.email, "*****@*****.**")
        self.assertNotEquals(self.person1.email, "*****@*****.**")

        with self.assertRaises(ValueError):
            self.person1.change_email("*****@*****.**")

        with self.assertRaises(ValueError):
            self.person1.change_email("no_at_symbol_or_dot_something")

    def test_change_phone(self):
        self.person1.change_phone(4144244343)
        self.assertEquals(self.person1.phone_number, 4144244343)
        self.assertNotEquals(self.person1.phone_number, 0000000000)

    def test_change_name(self):
        self.person1.change_name("Snoop Doggy Dog")
        self.assertEquals(self.person1.name, "Snoop Doggy Dog")
        self.assertNotEquals(self.person1.name, "DEFAULT")

    def test_get_contact_info(self):
        self.assertEquals(self.person1.get_contact_info(), "Snoop Doggy Dog, [email protected], 4144244343")
        self.assertNotEquals(self.person1.get_contact_info(), "DEFAULT, [email protected], 0000000000")

    def test_login(self):
        self.assertEquals(self.person1.login("*****@*****.**", "DEFAULT_PASSWORD"), "Invalid login info.")
        self.assertEquals(self.person1.login("*****@*****.**", "password"), "Login successful.")

    def test_logout(self):
        self.assertTrue(self.person1.logout())
Exemplo n.º 2
0
    def change_name(self, parse_cmd):

        some_guy = self.whos_logged_in()

        if len(parse_cmd) < 2:
            return "Parameter error."

        person = Person(some_guy.email, some_guy.password, some_guy.type)

        name_length = len(parse_cmd)
        i = 2
        some_name = parse_cmd[1]

        while i < name_length:
            some_name = some_name + " " + parse_cmd[i]
            i = i + 1

        did_work = person.change_name(some_name)

        if did_work:
            return "Name changed."
        else:
            return "Bad name."
Exemplo n.º 3
0
class TestPerson(TestCase):
    def test_init_(self):
        self.person1 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT")
        self.assertEquals(self.person1.email, "*****@*****.**")
        self.assertEquals(self.person1.password, "DEFAULT_PASSWORD")

    def test_change_password(self):
        self.person1 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT")
        self.assertTrue(self.person1.change_password("password"))
        self.assertEquals(self.person1.password, "password")
        self.assertNotEquals(self.person1.password, "DEFAULT_PASSWORD")
        model_person1 = models.ModelPerson.objects.get(
            email=self.person1.email)
        self.assertEquals(model_person1.password, "password")

    def test_change_email(self):
        self.person1 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT")
        self.person2 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT")
        self.person1.change_email("*****@*****.**")
        self.assertEquals(self.person1.email, "*****@*****.**")
        self.assertNotEquals(self.person1.email, "*****@*****.**")
        model_person1 = models.ModelPerson.objects.get(
            email=self.person1.email)
        self.assertEquals(model_person1.email, "*****@*****.**")
        self.assertFalse(self.person1.change_email("*****@*****.**"))
        self.assertFalse(
            self.person1.change_email("no_at_symbol_or_dot_something"))
        self.assertFalse(self.person1.change_email("*****@*****.**"))

    def test_change_phone(self):
        self.person1 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT")
        self.person1.change_phone("414.414.4141")
        model_person1 = models.ModelPerson.objects.get(
            email=self.person1.email)
        self.assertEquals(model_person1.phone, "414.414.4141")
        self.assertEquals(self.person1.phone_number, "414.414.4141")
        self.assertNotEquals(self.person1.phone_number, "000.000.0000")
        self.assertFalse(self.person1.change_phone("1234567890"))
        self.assertFalse(self.person1.change_phone("414-414-4141"))
        self.assertFalse(self.person1.change_phone("(414)414-4141"))
        self.assertFalse(self.person1.change_phone("abc.abc.abcd"))
        self.assertFalse(self.person1.change_phone("1234.1234.1234"))

    def test_change_name(self):
        self.person1 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT")
        self.person1.change_name("Snoop Doggy Dog")
        model_person1 = models.ModelPerson.objects.get(
            email=self.person1.email)
        self.assertEquals(model_person1.name, "Snoop Doggy Dog")
        self.assertEquals(self.person1.name, "Snoop Doggy Dog")
        self.assertNotEquals(self.person1.name, "DEFAULT")

    def test_get_contact_info(self):
        self.person1 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT")
        self.assertEquals(self.person1.get_contact_info(),
                          "Snoop Doggy Dog, [email protected], 4144244343")
        self.assertNotEquals(self.person1.get_contact_info(),
                             "DEFAULT, [email protected], 0000000000")

    def test_login(self):
        self.person1 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT")
        self.person2 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT")
        self.assertEquals(Person.login("*****@*****.**", "password"),
                          "Invalid login info")
        self.assertEquals(Person.login("*****@*****.**", "DEFAULT_PASSWORD"),
                          "Login successful")
        model_person1 = models.ModelPerson.objects.get(
            email=self.person1.email)
        self.assertTrue(model_person1.isLoggedOn)
        self.assertEquals(Person.login("*****@*****.**", "DEFAULT_PASSWORD"),
                          "User already logged in")
        self.assertEquals(Person.login("*****@*****.**", "DEFAULT_PASSWORD"),
                          "User already logged in")

    def test_logout(self):
        self.person1 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT")
        self.person2 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT")
        self.assertEquals(Person.login("*****@*****.**", "DEFAULT_PASSWORD"),
                          "Login successful")
        self.assertEquals(Person.login("*****@*****.**", "DEFAULT_PASSWORD"),
                          "User already logged in")
        self.assertTrue(self.person1.logout())

    def test_view_info(self):
        self.person1 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT")
        self.person2 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT")
        self.assertEquals(
            self.person1.view_info(),
            ["*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT", "000.000.0000"])
        self.assertEquals(
            self.person2.view_info(),
            ["*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT", "000.000.0000"])