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()
Esempio n. 2
0
def get_for_utilizer():
    if roles_required(["utilizer"]) == 400:
        return jsonify({"msg": "no access"}), 400
    if not request.is_json:
        return jsonify({"msg": "Missing JSON in request"}), 400

    num = request.json['num']
    series = request.json['series']
    try:
        returned_data = blank_model.read({"num": num, "series": series})

        from models.usages_register import UsagesRegisterModel
        usages_register_model = UsagesRegisterModel(
            PostgresConnection().get_connection())
        usages_register = usages_register_model.custom_query(
            "SELECT * FROM usages_register "
            "WHERE num_blank = %s "
            "AND series_blank = \'%s\'" % (num, series))

        from models.code_usages_blank import CodeUsagesBlankModel
        code_usages_blank_model = CodeUsagesBlankModel(
            PostgresConnection().get_connection())
        code_usages_blank = code_usages_blank_model.custom_query(
            "SELECT * FROM code_usages_blank "
            "WHERE code = %s" % (usages_register['code_usage']))

    except Exception as e:
        return jsonify({"msg": str(e)}), 400

    return jsonify({
        "statusCode": usages_register['code_usage'],
        "statusPhrase": code_usages_blank['text_representation'],
        "dateUsing": usages_register['date_usage']
    }), 200
Esempio n. 3
0
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 = CodeUsagesBlankModel(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(2),
                    "date_usage": date.today(),
                    "code_usage":  auxiliary_list[random_int_from_zero_to_num(length)]['code'],
                    "additional_info": random_string()
                })

        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)
Esempio n. 6
0
    def test(self):
        code_usages_blank_model = CodeUsagesBlankModel(
            PostgresConnection().get_connection())
        code_usages_blank_amount = code_usages_blank_model.amount()[0]
        code = random_int()
        returned_data = code_usages_blank_model.create({
            "code":
            code,
            "text_representation":
            'text_representation'
        })
        assert (code_usages_blank_amount +
                1 == code_usages_blank_model.amount()[0])

        code_register = code_usages_blank_model.read({'code': code})
        assert (code_register['text_representation'] == 'text_representation')
        new_code = random_int()
        code_usages_blank_model.update({"code": new_code}, {'code': code})
        code_register = code_usages_blank_model.read({'code': new_code})
        assert (code_register['code'] == new_code)

        code_usages_blank_model.delete({'code': new_code})
        assert (code_usages_blank_model.read({'code': new_code}) is None)
import unittest
from datetime import date

from connection import PostgresConnection
from models.usages_register import UsagesRegisterModel
from models.code_usages_blank import CodeUsagesBlankModel
from random_data_generators import (random_int, random_string)

auxiliary_model = CodeUsagesBlankModel(PostgresConnection().get_connection())
auxiliary_data = {'code': 0}


class TestUsagesRegisterModel(unittest.TestCase):
    def setUp(self):
        returned_data = auxiliary_model.create({
            "code":
            random_int(100),
            "text_representation":
            'text_representation'
        })
        auxiliary_data['code'] = returned_data['code']

    def test(self):
        usages_register_model = UsagesRegisterModel(
            PostgresConnection().get_connection())
        usages_register_amount = usages_register_model.amount()[0]
        num_blank = random_int()
        returned_data = usages_register_model.create({
            "num_blank":
            num_blank,
            "series_blank":