Example #1
0
    def updateClientId(self, clientId, newId):
        '''
                A functions that updates a client's id and also provides data validation
            :param clientId: integer
            :param newId: integer
            :return: True if the client was updated, False otherwise
        '''
        try:
            clientId = int(clientId)
        except ValueError:
            raise ValueError("Error: \n Client Id cannot be string")
        try:
            newId = int(newId)
        except ValueError:
            raise ValueError("Error: \n New Client Id cannot be string")

        item = self.getItemById(clientId)
        newItem = self.getItemById(newId)

        if newItem is not False and clientId != newId:
            raise ValueError("Error:\n The given id is already taken")
        if item is not False:
            item = Client(*item)
            item.id = newId
            return self.updateItemById(clientId, item)
Example #2
0
 def test_FileRepo(self):
     self.test_Repo()
     self.assertEqual(self.fileRepo.getItemById(3), Client(3, "Birhan"))
     c = Client(4, "numeFaaaain")
     self.fileRepo.createItem(c)
     self.assertEqual(self.fileRepo.getItemById(4), c)
     self.fileRepo.updateItemById(4, Client(4, "lapteeee"))
     self.fileRepo.deleteItemById(4)
     self.assertEqual(self.fileRepo.getItemById(4), False)
 def __init__(self, isCreating):
     Client.__init__(self, '', '')
     BaseWidget.__init__(self, 'Client')
     self.__isCreating = isCreating
     self._idField = ControlText("Id")
     if not isCreating:
         self._idField.enabled = False
     self._nameField = ControlText("Name")
     self._buttonField = ControlButton('Add a new client')
     self._buttonField.value = self._updateAction
     self._label = ControlLabel("")
Example #4
0
    def put(self):
        json_data = request.get_json(force=True)
        if not json_data:
            return {'message': 'No input data provided'}, 400
        # Validate and deserialize input
        data, errors = client_schema.load(json_data)
        if errors:
            return errors, 422
        client = Client.query.filter_by(id=data['id']).first()
        if not client:
            return {'message': 'Client does not exist'}, 400
        client = Client(
            nom=json_data['nom'],
            prenom=json_data['prenom'],
            date_naissance=json_data['date_naissance'],
            situation_matrimonial=json_data['situation_matrimonial'],
            entreprise=json_data['entreprise'],
            longitude=json_data['longitude'],
            latitude=json_data['latitude'],
            forme_juridique=json_data['forme_juridique'],
            adresse=json_data['adresse'],
            fonction=json_data['fonction'],
            domaine_activite=json_data['domaine_activite'])
        db.session.commit()

        result = client_schema.dump(client).data

        return {"status": 'success', 'data': result}, 204
Example #5
0
 def __readAllFromFile(self):
     try:
         with open(self.__fileName, "r") as file:
             lines = file.readlines()
             for line in lines:
                 words = line.strip().split(',')
                 if len(words) == 2:
                     client_id = int(words[0].strip())
                     client_name = words[1].strip()
                     client = Client(client_id, client_name)
                     RepoData.add(self, client)
     except FileNotFoundError:
         print("Inexistent file : " + self.__fileName)
Example #6
0
 def addClient(self, clientId, name):
     '''
         A function that validates and adds a client to the repository
     :param clientId: integer
     :param name: string // cannot be empty
     :return: True if the client was added with success
     '''
     if ClientValidator.validate(clientId, name):
         clientId = int(clientId)
         client = Client(clientId, name)
         if self.getItemById(int(clientId)) is not False:
             raise ValueError("Error:\n The given id is already taken")
         self.addItem(client)
         return True
Example #7
0
 def updateClientName(self, clientId, clientName):
     '''
         A functions that updates a client's name and also provides data validation
     :param clientId: integer
     :param clientName: string // cannot be empty
     :return: True if the client was updated, False otherwise
     '''
     if ',' in clientName:
         raise ValueError(
             "Error:\n Parameters should not contain the ',' character")
     try:
         clientId = int(clientId)
     except ValueError:
         raise ValueError("Error:\n Client Id must be integer")
     if len(clientName.strip()) == 0:
         raise ValueError("Error: \n Client Name should not be empty")
     item = self.getItemById(clientId)
     if item is not False:
         item = Client(*item)
         if len(clientName.strip()) > 0:
             item.name = clientName
             return self.updateItemById(int(clientId), item)
     else:
         raise ValueError("Error:\n Client Id cannot be find")
Example #8
0
    def createRental(self, rental_id, book_id, client_id):

        book_repo = self.__bookService.getAllBooks()
        client_repo = self.__clientService.getAllClients()
        # we create a new client in order to see if client_id valid or not
        client = Client(client_id, 'None')
        self.__valid.checkClientExistence(client, client_repo)

        # we create a new book in order to see if the book_is valid or not
        book = Book(book_id, 'None', 'None', 'None', None)
        self.__valid.checkBookExistenceAndAvailability(book, book_repo)

        # need to check the book if it is available

        current_date = datetime.now()
        current_day = current_date.day  # int
        current_month = current_date.month  # int
        current_year = current_date.year  # int
        rented_date = date(current_year, current_month, current_day)

        #rented_date = []            # rented_date will be a list
        #rented_date.append(current_day)
        #rented_date.append(current_month)
        #rented_date.append(current_year)

        # we need to create the due date
        due_date_p = current_date + timedelta(days=14)
        due_date_day = due_date_p.day  # int
        due_date_month = due_date_p.month  # int
        due_date_year = due_date_p.year  # int
        due_date = date(due_date_year, due_date_month, due_date_day)

        #due_date = []               # due_date will be a list
        #due_date.append(due_date_day)
        #due_date.append(due_date_month
        #due_date.append(due_date_year)

        returned_date = 0

        rental = Rental(rental_id, book_id, client_id, rented_date, due_date,
                        returned_date)
        return rental
 def setUp(self):
     self.Client = Client(3, 'name')
     self.repo = Repository('testClients', 'testClients')
     self.controller = ClientController(self.repo)
     if self.controller.getClientById(77) is not False:
         self.controller.removeClient(77)
     if self.controller.getClientById(772) is not False:
         self.controller.removeClient(772)
     if self.controller.getClientById(773) is not False:
         self.controller.removeClient(773)
     if self.controller.getClientById(23) is False:
         self.controller.addClient("23", "name")
     if self.controller.getClientById('233333') is not False:
         self.controller.removeClient('233333')
     if self.controller.getClientById(20) is False:
         self.controller.addClient("20", "name")
     if self.controller.getClientById(200) is False:
         self.controller.addClient("200", "name2")
     if self.controller.getClientById(90) is False:
         self.controller.addClient("90", "name3")
     if self.controller.getClientById(123) is False:
         self.controller.addClient("123", "tion")
     if self.controller.getClientById(234) is False:
         self.controller.addClient("234", "t")
     if self.controller.getClientById(33) is False:
         self.controller.addClient("33", "tit")
     if self.controller.getClientById(90) is not False:
         self.controller.removeClient(99)
     if self.controller.getClientById(323) is False:
         self.controller.addClient("323", "tit")
     if self.controller.getClientById(929) is not False:
         self.controller.removeClient(929)
     if self.controller.getClientById(33) is False:
         self.controller.addClient("333", "tin")
     if self.controller.getClientById(939) is not False:
         self.controller.removeClient(939)
 def test_GetAllClients(self):
     repo2 = Repository('ClientUpdateTest', "test2")
     client = Client("2", "223")
     controller2 = ClientController(repo2)
     l = controller2.getAllClients()
     self.assertEqual(controller2.getAllClients(), [client])
 def test_strClient(self):
     c = Client(2, "lapte")
     self.assertNotEqual(c, Client(3, "lapte"))
     self.assertEqual(str(self.Client), '3, name')
 def test_getClientById2(self):
     if self.controller.getClientById('111211111') is False:
         self.controller.addClient('111211111', 'sfsdfsf')
     self.assertEqual(self.controller.getClientById('111211111'),
                      Client('111211111', 'sfsdfsf'))
Example #13
0
 def searchClientById(self, client_id):
     client = Client(client_id, 'None')
     self.__valid.checkClientExistence(client, self.__repoClient.getAll())
     for cl in self.__repoClient.getAll():
         if cl.get_client_id() == client_id:
             return cl
Example #14
0
 def createClient(self, client_id, name):
     client = Client(client_id, name)
     return client
Example #15
0
from Models.Client import Client
from Models.Transaction import Transaction
from Models.block import Block
from Models.BlockChain import BlockChain

transactions = []

Dinesh = Client()
Ramesh = Client()
Seema = Client()
Vijay = Client()

print('print 1 : Creation Clients')
print(Dinesh.identity)

t0 = Transaction("Genesis", Dinesh.identity, 500.0)
t1 = Transaction(Dinesh, Ramesh.identity, 15.0)
transactions.append(t1)
t2 = Transaction(Dinesh, Seema.identity, 6.0)
t2.sign_transaction()
transactions.append(t2)
t3 = Transaction(Ramesh, Vijay.identity, 2.0)
t3.sign_transaction()
transactions.append(t3)
t4 = Transaction(Seema, Ramesh.identity, 4.0)
t4.sign_transaction()
transactions.append(t4)
t5 = Transaction(Vijay, Seema.identity, 7.0)
t5.sign_transaction()
transactions.append(t5)
t6 = Transaction(Ramesh, Seema.identity, 3.0)
 def setUp(self):
     self.__c0 = Client(1, "Ghita")
     self.__c1 = Client(2, "Marcel")
     self.__c2 = Client(3, "Birhan")
     self.__c3 = Client("4", "Erik")
     self.__c4 = Client(1, "Bbf")