Beispiel #1
0
    def test_user_getotherperson_method(self):
        """ test that the method works as prescribed"""

        billy = User(username="******")
        billy.set_password("billy")
        billy.save()
        p = Pair(person1=billy, person2=self.uche)
        p.save()
        self.assertEqual(billy.username, self.uche.getotherperson(p.pairname))
        self.assertEqual(self.uche.username, billy.getotherperson(p.pairname))
Beispiel #2
0
    def test_pair_getAPair_method_works_as_prescribed(self):
        """ test that irrespective of order of users in the method it will
			return the same pair object regardless if the users exists
			or none if the user doesnt exist
		"""

        self.assertEqual(self.pair, Pair.getAPair(self.brian, self.suzy))
        self.assertEqual(self.pair, Pair.getAPair(self.suzy, self.brian))
        popo = User(username="******")
        popo.set_password("popo")
        popo.save()
        self.assertIsNone(Pair.getAPair(popo, self.suzy))
Beispiel #3
0
    def test_pair_ondelete_refrenceusers_associatingPairnamesAreDeleted(self):
        """ test that when we delete a pair the pairname stored in the 
			pair's referenced users are also deleted as well
		"""

        eze = User(username="******")
        eze.set_password('ezeiscool')
        eze.save()

        p = Pair(person1=eze, person2=self.suzy)
        p.save()
        self.assertEqual(2, len(self.suzy.pairnames))
        p.delete()
        self.assertEqual(1, len(self.suzy.pairnames))
Beispiel #4
0
    def test_pair_adds_pairnamesToIndividualUsers(self):
        """ test that when a pair is created its pairname is added to
			pairnames list of the users it references
		"""

        # test with a brand new pair
        eze = User(username="******")
        eze.set_password('ezeiscool')
        eze.save()

        Pair(person1=eze, person2=self.suzy).save()
        self.assertEqual(1, len(eze.pairnames))
        self.assertIn(self.suzy.username, eze.pairnames[0])
        self.assertEqual(2, len(self.suzy.pairnames))
Beispiel #5
0
    def test_pair_doesnt_duplicate_pairnames_onRepeatedSaveCalls(self):
        """ test that if we call save on the same pair object again we doen
			add the same pairname a=on its user references again
		"""

        eze = User(username="******")
        eze.set_password('ezeiscool')
        eze.save()

        p = Pair(person1=eze, person2=self.suzy)
        p.save()
        p.save()
        p.save()

        self.assertNotEqual(3, len(eze.pairnames))
        self.assertEqual(1, len(eze.pairnames))
Beispiel #6
0
    def test_pair_uniqueness_works_for_both_persons(self):
        """ ensure a pair is only considered unique as a pair, that is 
			if there is a pair(a, b) then creating another pair(a, c) or
			pair(d, b) is valid 
		"""
        yemi = User(username="******")
        yemi.set_password("yemi")
        yemi.save()

        p1 = Pair(person1=self.brian, person2=yemi)
        p1.save()
        p2 = Pair(person1=yemi, person2=self.suzy)
        p2.save()

        self.assertIsNotNone(p1)
        self.assertIsNotNone(p2)
Beispiel #7
0
 def createUser(name, password):
     u = User(username=name)
     u.set_password(password)
     u.save()
     return u