Пример #1
0
def upload_image():
    if request.headers['Content-Type'] in [
            'image/jpeg', 'image/png', 'image/tiff'
    ]:
        dbx_path = ''
        DropBoxDataProvider.file_upload(request.files, dbx_path)
    elif request.headers['Content-Type'] == 'application/json':
        request_data = request.get_json()
        file_id = request_data["file_id"]
        dbx_path = upload_image_to_dbx(file_id)
        return json.dumps({"dropbox_path": dbx_path})
Пример #2
0
def test_not_empty_get_list_of_objects_success():
    dbdp = DropBoxDataProvider(ACS_TOKEN)

    dummy_file_object = Mock(
        path_lower='/ss_dpb_test_not_empty_folder/dropbox_t_file.txt')
    n = PropertyMock(return_value='dropbox_t_file.txt')
    type(dummy_file_object).name = n

    dbdp.dbx.files_list_folder = Mock(return_value=Mock(
        entries=tuple([dummy_file_object])))
    list_of_objects = dbdp.get_list_of_objects()

    assert isinstance(list_of_objects, list)
    assert isinstance(list_of_objects[0], tuple)
    assert list_of_objects[0].filename == 'dropbox_t_file.txt'
    assert list_of_objects[
        0].filepatch == '/ss_dpb_test_not_empty_folder/dropbox_t_file.txt'
Пример #3
0
def my_setup(request):
    path = os.path.join(os.path.dirname(__file__), 'dpb_download/')
    os.makedirs(path)
    dbdp = DropBoxDataProvider(ACS_TOKEN)

    with open(con.local_file, 'w') as f:
        f.write(str(con.rand))

    dbdp.file_upload(con.local_file, con.dbx_file)
    dbdp.create_folder(con.dbx_empty_folder)
    dbdp.file_upload(con.local_file, con.dbx_not_empty_folder_file)

    def my_teardown():
        path = os.path.join(os.path.dirname(__file__), 'dpb_download/')
        file_from = os.path.join(os.path.dirname(__file__),
                                 'dpb_download/' + con.file_name)
        os.remove(file_from)
        os.rmdir(path)
        dbdp.file_delete(con.dbx_folder)
        dbdp.file_delete(con.dbx_empty_folder)
        dbdp.file_delete(con.dbx_folder_file_to_move)
        dbdp.file_delete(con.dbx_not_empty_folder)

    request.addfinalizer(my_teardown)
Пример #4
0
def test_empty_get_list_of_objects_success(my_setup):
    dbdp = DropBoxDataProvider(ACS_TOKEN)
    assert isinstance(dbdp.get_list_of_objects(con.dbx_empty_folder), list)
Пример #5
0
def test_api_smoke_negative():
    dbdp = DropBoxDataProvider(ACS_TOKEN)
    dbdp.dbx.files_list_folder = Mock(return_value=Mock(entries=None))
    dbdp.api_smoke()
Пример #6
0
def test_api_smoke_positive():
    dbdp = DropBoxDataProvider(ACS_TOKEN)
    res = dbdp.api_smoke()
    exp = 3
    assert res == exp
Пример #7
0
def test_smoke_positive():
    dbdp = DropBoxDataProvider(ACS_TOKEN)
    assert dbdp.smoke()[0] == 200
    assert dbdp.smoke()[1] == 'Ok'
Пример #8
0
def test_smoke_missed_url():
    dbdp = DropBoxDataProvider(ACS_TOKEN)
    dbdp.smoke_url = None
    dbdp.smoke()
Пример #9
0
def main():

    dbdp = DropBoxDataProvider(ACS_TOKEN)

    print(file_name)
    list_of_objects = dbdp.get_list_of_objects(dbx_folder)
    pprint(list_of_objects)

    for f in list_of_objects:
        if file_name not in f:
            try:
                dbdp.file_upload(local_file, dbx_file)
            except IOError:
                print('File read error')

        else:
            user_choice = input(
                'The file already exists what you want to do:\n'
                '- Overwrite - press "O"\n'
                '- Move - press "M"\n'
                '-->')

            if str(user_choice).lower().isalpha():
                if user_choice in FILE_OVERWRITE and user_choice not in FILE_MOVE:
                    dbdp.file_upload(local_file, dbx_file)
                    break
                elif user_choice in FILE_MOVE and user_choice not in FILE_OVERWRITE:
                    dbdp.file_move(dbx_file, dbx_file_to_move)
                    break
                else:
                    print(
                        'You decide to make the wrong choice and the files will be deleted.'
                    )
                    dbdp.file_delete(dbx_file)
                    break
Пример #10
0
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, ConversationHandler
from transport.data_provider import DropBoxDataProvider
from database.db_connection import connect_db
from bots.mockbase import Database
from stella_api.service_data import store_bot_data

dbx_token = os.environ['DROPBOX_TOKEN']
telegram_token = os.environ['TELEGRAM_TOKEN']
port = int(os.environ['PORT'])
url_path = os.environ['URL_PATH']

logging.basicConfig(
    level=logging.DEBUG,
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__)
dbx_provider = DropBoxDataProvider(dbx_token)

db_object = Database()
ACTION, CHOICE, CHOOSE_STATION, SENT_LOCATION = range(4)


def start(bot, update):
    reply_keyboard = [['/setdata', '/getdata']]

    update.message.reply_text(
            "Hello! My name is Stella, and I will provide you with the actual information on prices of Ukrainian" \
            "gas stations.\n"
            "Simply type or choose button, what do yo want\n"
            "/setdata - send us actual photo with gas prices.\n"
            "/getdata - get information about gas prices\n"
            "If something goes wrong, simply type '/start'. If you need help, type 'help'.",
Пример #11
0
def test_file_upload_failed_file_not_found():
    dbdp = DropBoxDataProvider(ACS_TOKEN)
    wrong_local_file = os.path.join(os.path.dirname(__file__),
                                    'dpb_downloa/' + con.file_name)
    dbdp.file_upload(wrong_local_file, con.dbx_file)
Пример #12
0
def test_file_download_file_None_failed(my_setup):
    dbdp = DropBoxDataProvider(ACS_TOKEN)
    assert dbdp.file_download(con.local_file, con.dbx_file_empty) is None
Пример #13
0
def test_file_move_failed(my_setup):
    dbdp = DropBoxDataProvider(ACS_TOKEN)
    assert dbdp.file_move(con.dbx_no_file, con.dbx_file_to_move) is None
Пример #14
0
def test_file_move_success(my_setup):
    dbdp = DropBoxDataProvider(ACS_TOKEN)
    res = dbdp.file_move(con.dbx_file, con.dbx_file_to_move)
    exp = str(con.dbx_file_to_move)

    assert res == exp
Пример #15
0
def test_file_delete_success(my_setup):
    dbdp = DropBoxDataProvider(ACS_TOKEN)
    res = dbdp.file_delete(con.dbx_file)
    exp = con.dbx_file
    assert res == exp
Пример #16
0
def test_file_download_success(my_setup):
    dbdp = DropBoxDataProvider(ACS_TOKEN)
    res = dbdp.file_download(con.local_file, con.dbx_file)
    exp = str(con.dbx_file)
    assert res == exp
Пример #17
0
def test_file_delete_failed(my_setup):
    dbdp = DropBoxDataProvider(ACS_TOKEN)
    assert dbdp.file_delete(con.dbx_file_empty) is None
Пример #18
0
def upload_image_to_dbx(file_path, dbx_path):
    dbx_provider = DropBoxDataProvider(dbx_token)
    dbx_path = dbx_provider.file_upload(file_path, dbx_path)
    return dbx_path, dbx_provider.get_file_tmp_link(dbx_path)
Пример #19
0
    def getGraph(self):
        dbdp = DropBoxDataProvider(os.environ['DROPBOX_TOKEN'])
        py.plotly.tools.set_credentials_file(
            username=os.environ['Plotly_username'],
            api_key=os.environ['Plotly_api_key'])
        # data_from_qery = query_to_dict(self.query)

        date = ['80', '92', '95']
        price = [55.22, 66.44, 88.33]
        price2 = [44.11, 53.23, 35.14]
        price3 = [33.15, 46.31, 28.23]

        trace0 = go.Bar(x=date,
                        y=price,
                        text=price,
                        textposition='auto',
                        name='OKKO',
                        marker=dict(
                            color='rgb(49,130,189)',
                            line=dict(color='rgb(15,42,176)', width=1.5),
                        ),
                        opacity=0.6)

        trace1 = go.Bar(x=date,
                        y=price2,
                        text=price2,
                        textposition='auto',
                        name='WOG',
                        marker=dict(
                            color='rgb(204,204,204)',
                            line=dict(color='rgb(33,149,10)', width=1.5),
                        ),
                        opacity=0.6)

        trace2 = go.Bar(x=date,
                        y=price3,
                        text=price3,
                        textposition='auto',
                        name='NefTek',
                        marker=dict(
                            color='rgb(195,85,91)',
                            line=dict(color='rgb(144,8,8)', width=1.5),
                        ),
                        opacity=0.6)

        data = [trace0, trace1, trace2]
        layout = go.Layout(
            xaxis=dict(tickangle=-45),
            barmode='group',
        )

        fig = go.Figure(data=data, layout=layout)

        if not os.path.exists('graph_images'):
            os.mkdir('graph_images')

        path = os.path.join(os.path.dirname(__file__), 'graph_images/')
        path_crome_driver = os.path.join(os.path.dirname(__file__),
                                         'chromedriver.exe')

        date = datetime.today().strftime('%Y-%m-%d_%H.%M.%S')
        html_file_name = f'Fuel-price-graph-{date}.html'
        png_file_name = f'Fuel-price-graph-{date}.png'

        dbx_file_html = '/graph_html/' + html_file_name
        dbx_file_png = '/graph_png/' + png_file_name

        plot(fig, filename=f'{path}{html_file_name}', auto_open=False)

        chrome_options = webdriver.ChromeOptions()
        chrome_options.accept_untrusted_certs = True
        chrome_options.assume_untrusted_cert_issuer = True
        chrome_options.add_argument("--no-sandbox")

        chrome_options.add_argument('headless')
        chrome_options.add_argument('window-size=1200x600')

        driver = webdriver.Chrome(executable_path=path_crome_driver,
                                  chrome_options=chrome_options)
        driver.get(f'{path}{html_file_name}')
        driver.save_screenshot(f'{path}{png_file_name}')
        time.sleep(1)
        driver.quit()

        dbdp.file_upload(f'{path}{png_file_name}', dbx_file_png)
        dbdp.file_upload(f'{path}{html_file_name}', dbx_file_html)

        shutil.rmtree(path)

        return