Exemplo n.º 1
0
def test():
    provider1 = helper.add_instance(Provider, name=tomer)

    rate1 = helper.add_instance(Rate,
                                product_name='cucumba',
                                rate=200,
                                scope=provider1.id)

    truck1 = helper.add_instance(Truck,
                                 truck_id='1234',
                                 provider_id=provider1.id)
    return 'Hello!'
Exemplo n.º 2
0
 def test_put_nonexist_provider_id(self):
     print("testing put request without provider_id param ...")
     tid = "noclue"
     helper.add_instance(Truck,
                         id=6,
                         truck_id=tid,
                         weight=500.5,
                         provider_id=10)
     helper.commit_changes()
     with self.app.test_client() as c:
         resp = c.put(f'/truck/{tid}')
         print("response: ", resp.data)
         self.assert_400(resp,
                         "Fail:  put request without provider_id param")
Exemplo n.º 3
0
    def setUp(self):
        self.app = create_app(config_file='settings.py')
        self.helper = ApiTestHelper()

        with self.app.test_request_context():
            self.base_url = request.host
            self.provider1 = helper.add_instance(Provider, name='tomer')
Exemplo n.º 4
0
    def populate_db(
            provider_name: str,
            product_name: str,
            truck_id: str):

        with app.app_context():
            provider1 = helper.add_instance(Provider,
                                            name=provider_name)

            rate1 = helper.add_instance(Rate,
                                        product_name=product_name,
                                        rate=200,
                                        scope=provider1.id)

            truck1 = helper.add_instance(Truck,
                                         truck_id=truck_id,
                                         provider_id=provider1.id)
Exemplo n.º 5
0
    def test_put_nonexistent_new_prov_id_in_providers(self):
        tid = "moo"
        pid = 10
        helper.add_instance(Truck,
                            id=6,
                            truck_id=tid,
                            weight=500.5,
                            provider_id=pid)
        # helper.add_instance(Provider,id=pid,name="hanks")
        helper.commit_changes()
        #sys.stdout.write("testing truck put request with new id that is not found in the providers table...")

        with self.app.test_client() as c:
            resp = c.put(f'/truck/{tid}', data=dict(provider_id=15))
            #sys.stdout.write("response: " + resp.data)
            self.assert_400(
                resp,
                "Fail: put request with nonexistent new_provider_id in providers table"
            )
Exemplo n.º 6
0
def truck():
    if request.method == 'POST':

        provider_id = (request.form and request.form["provider_id"]) or (
            request.json and request.json.get("provider_id"))
        truck_id = (request.form and request.form["truck_id"]) or (
            request.json and request.json.get("truck_id"))

        queried_provider = helper.get_one(Provider, id=provider_id)

        if queried_provider and truck_id:
            helper.add_instance(Truck,
                                truck_id=truck_id,
                                provider_id=queried_provider.id)
            return 'truck was added successfully'

        elif not queried_provider:
            return 'Provider was not found'

        elif not truck_id:
            return 'Please provide a valid truck ID'
Exemplo n.º 7
0
def upload_xml_data():
    data = (request.form
            and request.form["file"]) or (request.json
                                          and request.json.get("file"))

    if data is None or not os.path.isfile(XLSX_DIR + data):
        return 'Bad parameters, expected {"file":"<name>"} or "file=<name>"\n', 400
    xlsx_file = Path(XLSX_DIR + data)
    try:
        wb_obj = load_workbook(xlsx_file)
    except:
        return f'Bad file {data}, unreadable or wrong format\n', 500
    sheet = wb_obj.active

    title = True
    for row in sheet.iter_rows():
        if title:  # first row is title we skip it
            title = False
            continue

        record = helper.get_one(Rate,
                                product_name=row[0].value,
                                scope=row[2].value)
        if record is not None:
            # TODO: should we check the case were there is ALL scope after provider scope and keep only ALL scope ?
            record.rate = row[1].value
            helper.commit_changes()
        else:
            helper.add_instance(Rate,
                                product_name=row[0].value,
                                rate=row[1].value,
                                scope=row[2].value)

        TimeUtils.set_file_last_modified(XLSX_DIR + data, TimeUtils.get_now())

    return 'OK\n', 200
Exemplo n.º 8
0
    def test_put_correct_request(self):
        tid = "too"
        pid = 20
        new_pid = 30
        helper.add_instance(Truck,
                            id=6,
                            truck_id=tid,
                            weight=500.5,
                            provider_id=pid)
        helper.add_instance(Provider, id=pid, name="john")
        helper.add_instance(Provider, id=new_pid, name="mario")
        helper.commit_changes()
        print("testing correct truck put request ...")

        with self.app.test_client() as c:
            resp = c.put(f'/truck/{tid}', data=dict(provider_id=new_pid))
            print("response: ", resp.data)
            self.assert_200(resp,
                            "Fail: put request with correct request info")
Exemplo n.º 9
0
def create_id(name):
    helper.add_instance(Provider, name=name)
    new_name = helper.get_one(Provider, name=name)
    return jsonify(id=new_name.id, name=new_name.name)