def testAllPersonsAddedAreReturnedOnLoadAll(self):
        person1 = Person ('Stephanie', '051.265.789.89')
        person1.addID(RFID('dfeferscd'))
        person1.addAllowedRoom(512)
        
        person2 = Person ('Katz', '789.265.789.89')
        person2.addID(RFID('derscd'))
        person2.addAllowedRoom(256)
  
        self._person_dao.save(person1)
        persons = self._person_dao.load_all()
        self.assertEqual(1, len(persons))
        self.assertTrue(person1 in persons)
        self.assertPersonsAreEqualAndHaveSameData (person1, persons[0])

        self._person_dao.save(person2)
        persons = self._person_dao.load_all()
        self.assertEqual(2, len(persons))
        self.assertTrue(person1 in persons)
        self.assertTrue(person2 in persons)
        
        if person1 == persons[0]:
            self.assertPersonsAreEqualAndHaveSameData (person1, persons[0])
            self.assertPersonsAreEqualAndHaveSameData (person2, persons[1])
        else:
            self.assertPersonsAreEqualAndHaveSameData (person1, persons[1])
            self.assertPersonsAreEqualAndHaveSameData (person2, persons[0])
 def testWhenAPersonIsSavedIfThereIsAlreadyAPersonWithTheGivenCPFTheFirstOneRemains(self):
     cpf = '051.265.789.89'
     firstSaved = Person ('Stephanie', cpf)
     firstSaved.addID(RFID('dfeferscd'))
     firstSaved.addAllowedRoom(512)
     
     self.assertTrue(self._person_dao.save(firstSaved))
     self.assertFalse(self._person_dao.save(Person ('Stephanie B. A.', cpf)))
     personLoaded = self._person_dao.load(cpf)
     self.assertPersonsAreEqualAndHaveSameData (firstSaved, personLoaded)
 def testRFIDsAreSavedCorrectly(self):
     name = 'Stephanie'
     cpf = '051.265.789.89'
     
     person = Person (name, cpf)
     person.addID(RFID('dfeferscd'))
     person.addID(RFID('dfeferscdsdsd234'))
     
     self._person_dao.save (person)
     personLoaded = self._person_dao.load(cpf)
     
     self.assertPersonsAreEqualAndHaveSameData(person, personLoaded)
 def testTheAllowedRoomsAreSavedCorrectly(self):
     name = 'Stephanie'
     cpf = '051.265.789.89'
     
     person = Person (name, cpf)
     person.addAllowedRoom(512)
     person.addAllowedRoom(256)
     
     self._person_dao.save (person)
     personLoaded = self._person_dao.load(cpf)
     
     self.assertPersonsAreEqualAndHaveSameData (person, personLoaded)
    def getAddedPerson(self):
        name = self.__ui.person_name.text()
        if name == '':
            return

        cpf = self.__ui.person_cpf.text()
        if cpf == '':
            return

        person = Person(name, cpf)

        [person.addAllowedRoom(self.__ui.allowed_rooms.item(i).text()) for i in range(self.__ui.allowed_rooms.count())]
        
        if self.__ui.person_rfid.text() != '':
            person.addID(RFID(self.__ui.person_rfid.text()))

        return person
class PersonTest(unittest.TestCase):
   

    def setUp (self):
        self._james_name = 'James Bond'
        self._james_cpf = '014.012.356.98'
        self._james = Person (self._james_name, self._james_cpf)


    def testHasAName(self):
        self.assertEqual(self._james_name, self._james.getName())
        
    def testHasACPF(self):
        self.assertEqual(self._james_cpf, self._james.getCPF())
        
    def testIfHasNoIdsThenGetIDsReturnsEmptySet(self):
        self.assertEqual (set(), self._james.getIDs())
        
    def testIfHasNoAllowedRoomsThenGetAllowedRoomsReturnsEmptySet(self):
        self.assertEqual (set(), self._james.getAllowedRooms())
    
    def testAfterAddingAIDGetIDsWillReturnIt (self):
        rfid = RFID('abacate')
        self._james.addID(rfid)
        ids = self._james.getIDs ()
        self.assertEqual(1, len(ids))
        self.assertTrue(rfid in ids)
        
    def testAfterAddingARoomGetAllowedRoomsWillReturnIt (self):
        room = 512
        self._james.addAllowedRoom(room)
        rooms = self._james.getAllowedRooms()
        self.assertEqual(1, len(rooms))
        self.assertTrue(room in rooms)
    
    def testAddingTheSameARoomTwiceHasNoEffect (self):
        room = 512
        self._james.addAllowedRoom(room)
        self._james.addAllowedRoom(room)
        rooms = self._james.getAllowedRooms ()
        self.assertEqual(1, len(rooms))
        self.assertTrue(room in rooms)
        
    def testAddingTheSameAIDTwiceHasNoEffect (self):
        rfid = RFID('abacate')
        self._james.addID(rfid)
        self._james.addID(rfid)
        ids = self._james.getIDs ()
        self.assertEqual(1, len(ids))
        self.assertTrue(rfid in ids)
    
    def testIfTwoPersonsHaveTheSameCPFTheyAreEqual (self):
        otherPerson = Person (self._james_name + ' Johannes', self._james_cpf)
        self.assertEqual (otherPerson, self._james)
        
    def testIfTwoPersonsHaveDifferentCPFsTheyArentEqual (self):
        otherPerson = Person (self._james_name, self._james_cpf + '0152')
        self.assertNotEqual (otherPerson, self._james)

    def testIfTwoPersonsAreEqualTheyCantBeUnEqual (self):
        otherPerson = Person (self._james_name, self._james_cpf)
        self.assertTrue(otherPerson == self._james)
        self.assertFalse(otherPerson != self._james)
        
    def testIfTwoPersonsAreEqualTheyHaveTheSameHash (self):
        otherPerson = Person (self._james_name, self._james_cpf)
        self.assertEqual (hash(otherPerson), hash(self._james))
        
    def testIfTwoPersonsArentEqualTheyDontHaveTheSameHash (self):
        otherPerson = Person (self._james_name, self._james_cpf + '0152')
        self.assertNotEqual (hash(otherPerson), hash(self._james))

    def testAllowedRoomsWillAlwaysBeAnInt(self):
        self._james.addAllowedRoom('512')
        self.assertTrue(512 in self._james.getAllowedRooms())
        self.assertFalse('512' in self._james.getAllowedRooms())
        
    def testNameCantBeAEmptyString(self):
        self.assertRaises(PersonConstructionError, Person, '', self._james_cpf)

    def testCPFCantBeAEmptyString(self):
        self.assertRaises(PersonConstructionError, Person, self._james_cpf, '')

    def testKnowsItIsNotNone(self):
        self.assertNotEqual(None, self._james)

    def testIsHashableAndCanBeInsertedOnASet(self):
        person_set = set()
        person_set.add(self._james)
        person_set.add(self._james)
        
        self.assertTrue(self._james in person_set)
        self.assertEqual(1, len(person_set))
 def setUp (self):
     self._james_name = 'James Bond'
     self._james_cpf = '014.012.356.98'
     self._james = Person (self._james_name, self._james_cpf)
 def testWhenAPersonIsUpdatedTheOldPersonInfoIsReplacedByTheNewOne(self):
     cpf = '051.265.789.89'
     firstSaved = Person ('Stephanie', cpf)
     firstSaved.addID(RFID('dfeferscd'))
     firstSaved.addAllowedRoom(512)
     
     updatedperson = Person ('Stephanie B. A. K.', cpf)
     updatedperson.addID(RFID('anotherRFID'))
     updatedperson.addAllowedRoom(256)
     updatedperson.addAllowedRoom(1024)
     
     self.assertTrue(self._person_dao.save(firstSaved))
     personLoaded = self._person_dao.load(cpf)
     self.assertPersonsAreEqualAndHaveSameData (firstSaved, personLoaded)
     
     self.assertTrue(self._person_dao.update(updatedperson))
     personLoaded = self._person_dao.load(cpf)
     self.assertPersonsAreEqualAndHaveSameData (updatedperson, personLoaded)