コード例 #1
0
    def view_info(self, parse_cmd):

        some_guy = self.whos_logged_in()

        if len(parse_cmd) != 1:
            return "Parameter error."

        person = Person(some_guy.email, some_guy.password, some_guy.type)
        return person.view_info()
コード例 #2
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"])