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)
def test_client_route_pairnames_show_if_they_exist(self): """ ensure that the client route shows a pairname if a pair exoist on client """ with self.client: Pair(person1=self.user1, person2=self.user2).save() HelperFunctions.login(self.client, self.user1.username, "tracce") response = self.client.get(self.client_url) self.assertEqual(response.status_code, 200) self.assertIn(self.user2.username.encode(), response.data)
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))
def setUpClass(cls): super().setUpClass() cls.brian = User(username="******") cls.brian.set_password("brian password ayyee") cls.brian.save() cls.suzy = User(username="******") cls.suzy.set_password("shwingggg") cls.suzy.save() cls.pair = Pair(person1=cls.brian, person2=cls.suzy) cls.pair.save()
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))
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))
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))
def test_getChats_route_works_for_valid_pairs(self): """ ensure that getchats route works as expected """ HelperFunctions.login(self.client, self.user1.username, "tracce") p = Pair(person1=self.user1, person2=self.user2) p.save() chat = {"sender": "joe", "message": "this is message"} p.addChat(**chat) p.addChat(**chat) data = {"channel": p.pairname, "ispublic": "false"} response = self.client.post(self.getChats_url, data=data) json_data = response.get_json() self.assertEqual(json_data["success"], True) self.assertEqual(2, len(json_data["messages"]))
def test_pair_doesnt_allow_symmetric_pairs(self): """ ensure that if a pair(a, b) is stored already, then a pair(b, a) cannot also be be stored """ # we already have a pair brian, suzy so creating a pair suzy, brian should be an error Pair(person1=self.suzy, person2=self.brian).save()
def test_pair_doesnt_allow_duplicate_pairs(self): """ ensure that if a pair(a,b) has been stored, then another pair(a,b) should not be allowed to be stored """ Pair(person1=self.brian, person2=self.suzy).save()