class Controller(object): def __init__(self): self._connection = PostgresConnection().get_connection() self._cursor = self._connection.cursor(cursor_factory=DictCursor) self._create_tables() self._code_usages_blank_model = CodeUsagesBlankModel(self._connection) self._notarius_model = NotariusModel(self._connection) self._blank_model = BlankModel(self._connection) self._usages_register_model = UsagesRegisterModel(self._connection) self._users_model = UsersModel(self._connection) self._journal_actions_model = JournalActionsModel(self._connection) self._verifications_register_model = VerificationsRegisterModel( self._connection) self._users_model.generate_data(5000) self._notarius_model.generate_data(5000) self._blank_model.generate_data(5000) self._usages_register_model.generate_data(5000) self._journal_actions_model.generate_data(5000) self._verifications_register_model.generate_data(5000) self._code_usages_blank_model.generate_data(5000) # self._users_model.generate_data(100) @property def connection(self): return self._connection def _create_tables(self): file_path = path.join(path.dirname(path.abspath(__file__)), '../create_tables.sql') with open(file_path, 'r') as f: sql = f.read() self._cursor.execute(sql) self._connection.commit()
def generate(): if roles_required(["admin", "registrar"]) == 400: return jsonify({"msg": "no access"}), 400 if not request.is_json: return jsonify({"msg": "Missing JSON in request"}), 400 try: num = request.json['number'] users_model = UsersModel(PostgresConnection().get_connection()) notarius_model = NotariusModel(PostgresConnection().get_connection()) blank_model = BlankModel(PostgresConnection().get_connection()) usages_register_model = UsagesRegisterModel( PostgresConnection().get_connection()) journal_actions_model = JournalActionsModel( PostgresConnection().get_connection()) verifications_register_model = VerificationsRegisterModel( PostgresConnection().get_connection()) code_usages_blank_model = CodeUsagesBlankModel( PostgresConnection().get_connection()) users_model.generate_data(num) notarius_model.generate_data(num) blank_model.generate_data(num) usages_register_model.generate_data(num) journal_actions_model.generate_data(num) verifications_register_model.generate_data(num) code_usages_blank_model.generate_data(num) except Exception as e: return jsonify({"msg": str(e)}), 400 return jsonify({"msg": "data generated"}), 200
def generate_data(self, num: int): try: auxiliary_model = NotariusModel(self._connection) auxiliary_list = auxiliary_model.read_all() length = len(auxiliary_list) for i in range(0, num): self.create({ "num_blank": random_int_from_zero_to_num(), "series_blank": random_string(), "user_id": auxiliary_list[random_int_from_zero_to_num(length)]['id'], "date_verification": date.today() }) except Exception as e: return str(e)
def __init__(self): self._connection = PostgresConnection().get_connection() self._cursor = self._connection.cursor(cursor_factory=DictCursor) self._create_tables() self._code_usages_blank_model = CodeUsagesBlankModel(self._connection) self._notarius_model = NotariusModel(self._connection) self._blank_model = BlankModel(self._connection) self._usages_register_model = UsagesRegisterModel(self._connection) self._users_model = UsersModel(self._connection) self._journal_actions_model = JournalActionsModel(self._connection) self._verifications_register_model = VerificationsRegisterModel( self._connection) self._users_model.generate_data(5000) self._notarius_model.generate_data(5000) self._blank_model.generate_data(5000) self._usages_register_model.generate_data(5000) self._journal_actions_model.generate_data(5000) self._verifications_register_model.generate_data(5000) self._code_usages_blank_model.generate_data(5000)
import unittest from datetime import date from connection import PostgresConnection from models.blank import BlankModel from models.notarius import NotariusModel from random_data_generators import (random_int, random_string) notarius_model = NotariusModel(PostgresConnection().get_connection()) notary_returned_data = {'id': 0} class TestBlank(unittest.TestCase): def setUp(self): returned_data = notarius_model.create({ "type": False, "status": 'status', "date_status_update": date.today(), "num_certificate": 'num_certificate', "num_card": 1, "name": 'name', "name_organization": 'name_organization', "region": 'region', "contacts": 'contacts', "notarius_region": 'notarius_region', "additional_info": 'additional_info', "date_issue_certificate": date.today(), "date_issue_card": date.today(), "date_reg_region": date.today(), "location": 'location'
def test(self): notarius_model = NotariusModel(PostgresConnection().get_connection()) notarius_amount = notarius_model.amount()[0] num_card = random_int() returned_data = notarius_model.create({ "type": False, "status": 'status', "date_status_update": date.today(), "num_certificate": 'num_certificate', "num_card": num_card, "name": 'name', "name_organization": 'name_organization', "region": 'region', "contacts": 'contacts', "notarius_region": 'notarius_region', "additional_info": 'additional_info', "date_issue_certificate": date.today(), "date_issue_card": date.today(), "date_reg_region": date.today(), "location": 'location' }) assert (notarius_amount + 1 == notarius_model.amount()[0]) notarius = notarius_model.read({'id': returned_data['id']}) assert (notarius['num_card'] == num_card) new_num_card = random_int() notarius_model.update({"num_card": new_num_card}, {'id': returned_data['id']}) notarius = notarius_model.read({'id': returned_data['id']}) assert (notarius['num_card'] == new_num_card) notarius_model.delete({'id': returned_data['id']}) assert (notarius_model.read({'id': returned_data['id']}) is None)