def test_get_generate_social_post_view_normal_customer(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    response = test_client.get(URL.USERPANEL_GENERATE_SOCIAL_POST, follow_redirects=True)

    assert response.status_code == 200
    assert b'You do not have access here!' in response.data
def test_get_aggregator_run_view_normal_customer(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    response = test_client.get(URL.USERPANEL_RUN_AGGREGATOR, follow_redirects=True)

    assert response.status_code == 200
    assert b'You do not have access here!' in response.data
コード例 #3
0
def test_get_userpanel(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    response = test_client.get(URL.USERPANEL_GET, follow_redirects=True)

    assert response.status_code == 200
    assert b'Dashboard' in response.data
def test_get_add_article_normal_customer(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    response = test_client.get(URL.USERPANEL_ARTICLE_ADD)

    assert response.status_code == 200
    assert b'You do not have access here!' in response.data
コード例 #5
0
def test_get_logout_ok(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    response = test_client.get(URL.USERPANEL_LOGOUT_GET, follow_redirects=True)

    assert response.status_code == 200
    assert b'Login to your account' in response.data
コード例 #6
0
def test_get_edit_profile(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    response = test_client.get(URL.USERPANEL_EDITPROFILE_GET)

    assert response.status_code == 200
    assert b'Edit profile' in response.data
コード例 #7
0
def test_get_all_emails_normal_customer(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    response = test_client.get(URL.USERPANEL_MAILS_ALL)

    assert response.status_code == 200
    assert b'You do not have access here!' in response.data
コード例 #8
0
def test_get_run_scrapper_normal_customer(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    response = test_client.get(URL.USERPANEL_RUN_SCRAPPER)

    assert response.status_code == 200
    assert b'You do not have access here!' in response.data
コード例 #9
0
def test_get_mail_packages_view_normal_customer(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    response = test_client.get(URL.USERPANEL_ALL_PACKAGES)

    assert response.status_code == 200
    assert b'You do not have access here!' in response.data
コード例 #10
0
def test_get_statistics_all_models_with_normal_customer(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    response = test_client.get(URL.USERPANEL_STATISTICS_ALL_MODELS)

    assert response.status_code == 200
    assert b'You do not have access here!' in response.data
コード例 #11
0
def test_get_dashboard(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    response = test_client.get(URL.USERPANEL_DASHBOARD_GET)

    assert response.status_code == 200
    assert customer.login in response.data.decode()
    assert 'Total calculations' in response.data.decode()
    assert 'Total visits' in response.data.decode()
コード例 #12
0
def test_get_apmc_as_logged_in_user(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    response = test_client.get(URL.APMC_GET)

    assert response.status_code == 200
    assert b'Your project name' in response.data
    assert b'Click to upload file' in response.data
    assert b'Pre-train' in response.data
コード例 #13
0
def test_get_customers(test_client):
    customer, plain_password = create_superuser_customer()
    login_customer(test_client, customer.login, plain_password)

    test_customer, _ = create_customer()

    response = test_client.get(URL.USERPANEL_CUSTOMERS_GET)

    assert response.status_code == 200
    assert test_customer.email in response.data.decode()
コード例 #14
0
def test_get_article_details_view_normal_customer(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    articles_fixture = get_fixture('blog_aggregator_articles.json')

    for article_fixture in articles_fixture:
        response = test_client.get(f"{URL.USERPANEL_ARTICLE_DETAILS}{article_fixture.get('id')}")

        assert b'You do not have access here!' in response.data
コード例 #15
0
def test_get_mail_details_view_normal_customer(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    mails_fixture = get_fixture('ncbi_mails.json')

    for mail_fixture in mails_fixture:
        response = test_client.get(
            f"{URL.USERPANEL_MAIL_DETAILS}{mail_fixture.get('id')}")

        assert b'You do not have access here!' in response.data
コード例 #16
0
def test_get_calculation_view(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    calculations = create_calculations(customer)

    response = test_client.get(URL.USERPANEL_CALCULATIONS_GET)

    assert response.status_code == 200

    for calculation in calculations:
        assert calculation.get('title').encode() in response.data
コード例 #17
0
def test_post_edit_profile_password_must_match(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    data = dict()
    data['password'] = "******"
    data['password_confirm'] = "new_password"

    response = test_client.post(URL.USERPANEL_EDITPROFILE_POST,
                                data=data,
                                follow_redirects=True)

    assert response.status_code == 200
    assert b'Passwords must match' in response.data
コード例 #18
0
def test_get_calculation_details(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    _ = create_calculations(customer)

    calculation_id = 1
    response = test_client.get(
        f'{URL.USERPANEL_CALCULATION_DETAILS_GET}{calculation_id}')

    assert response.status_code == 200
    assert b'Calculation details' in response.data
    assert b'Input' in response.data
    assert b'Result' in response.data
コード例 #19
0
def test_post_login_with_email_ok(test_client):
    customer, plain_password = create_customer()

    data = dict()
    data['login_or_email'] = customer.email
    data['password'] = plain_password

    response = test_client.post(URL.USERPANEL_LOGIN_POST,
                                data=data,
                                follow_redirects=True)
    customers = Customer.query.all()

    assert response.status_code == 200
    assert len(customers) == 1
    assert b'Dashboard' in response.data
コード例 #20
0
def test_post_login_with_not_valid_next_param(test_client):
    customer, plain_password = create_customer()

    data = dict()
    data['login_or_email'] = customer.login
    data['password'] = plain_password

    query_string = {'next': "//evil.net/redirect/"}

    response = test_client.post(URL.USERPANEL_LOGIN_POST,
                                data=data,
                                query_string=query_string,
                                follow_redirects=True)

    assert response.status_code == 400
コード例 #21
0
def test_post_register_with_email_which_already_exist(test_client):
    customer, plain_password = create_customer()

    data = dict()
    data['login'] = "******"
    data['email'] = customer.email
    data['password'] = "******"
    data['password_confirm'] = "test123test123"

    response = test_client.post(URL.USERPANEL_REGISTER_POST,
                                data=data,
                                follow_redirects=True)

    assert response.status_code == 200
    assert b'That email is taken. Please choose a different one.' in response.data
コード例 #22
0
def test_get_calculation_search_view(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    calculations = create_calculations(customer)

    for calculation in calculations:
        calculation_title = calculation.get('title')
        response = test_client.get(
            f'{URL.USERPANEL_CALCULATIONS_SEARCH_GET}?query={calculation_title}'
        )

        assert response.status_code == 200
        assert 'Results for query:'.encode() in response.data
        assert f'{calculation_title}'.encode() in response.data
        assert f'Title: {calculation_title}'.encode() in response.data
コード例 #23
0
def test_get_calculation_delete(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    _ = create_calculations(customer)

    calculation_id = 1
    response = test_client.get(
        f'{URL.USERPANEL_CALCULATIONS_DELETE}{calculation_id}',
        follow_redirects=True)

    calculations = CustomerCalculation.query.all()

    assert response.status_code == 200
    assert b'You have successfully deleted the calculation' in response.data
    assert len(calculations) == 2
コード例 #24
0
def test_post_customer_details(test_client):
    customer, plain_password = create_superuser_customer()
    login_customer(test_client, customer.login, plain_password)

    test_customer, _ = create_customer()

    data = dict()
    data['first_name'] = "New first name"

    response = test_client.post(
        f"{URL.USERPANEL_CUSTOMER_DETAILS_POST}{test_customer.id}",
        data=data,
        follow_redirects=True)

    assert response.status_code == 200
    assert b'You have successfully edited the customer.' in response.data
コード例 #25
0
def test_post_edit_profile_change_password(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    old_password = customer.password

    data = dict()
    data['password'] = "******"
    data['password_confirm'] = "new_password_123"

    response = test_client.post(URL.USERPANEL_EDITPROFILE_POST,
                                data=data,
                                follow_redirects=True)

    assert response.status_code == 200
    assert b'You have successfully edited the profile' in response.data
    assert customer.password != old_password
コード例 #26
0
def test_post_login_with_next_param(test_client):
    customer, plain_password = create_customer()

    data = dict()
    data['login_or_email'] = customer.login
    data['password'] = plain_password

    query_string = {'next': URL.APMC_GET}

    response = test_client.post(URL.USERPANEL_LOGIN_POST,
                                data=data,
                                query_string=query_string,
                                follow_redirects=True)
    customers = Customer.query.all()

    assert response.status_code == 200
    assert len(customers) == 1
    assert b'APMC' in response.data
コード例 #27
0
def test_post_edit_profile_edit_first_and_last_name(test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    data = dict()
    data['first_name'] = "Other First Name"
    data['last_name'] = "Other Last Name"
    data['password'] = plain_password
    data['password_confirm'] = plain_password

    response = test_client.post(URL.USERPANEL_EDITPROFILE_POST,
                                data=data,
                                follow_redirects=True)

    assert response.status_code == 200
    assert b'You have successfully edited the profile' in response.data
    assert customer.first_name == data['first_name']
    assert customer.last_name == data['last_name']
コード例 #28
0
def test_post_edit_profile_upload_profile_pic_with_wrong_file_extension(
        test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    old_profile_pic = customer.profile_pic

    data = dict()
    data['picture'] = (BytesIO(b'test_image_data'), 'test_file.pdf')
    data['password'] = plain_password
    data['password_confirm'] = plain_password

    response = test_client.post(URL.USERPANEL_EDITPROFILE_POST,
                                data=data,
                                content_type='multipart/form-data',
                                follow_redirects=True)

    assert response.status_code == 200
    assert b'File does not have an approved extension: jpg, png, jpeg' in response.data
    assert old_profile_pic == customer.profile_pic
コード例 #29
0
def test_post_edit_profile_upload_profile_pic(image_mock, test_client):
    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    old_profile_pic = customer.profile_pic

    image_mock.save.return_value = True

    data = dict()
    data['picture'] = (BytesIO(b'test_image_data'), 'test_file.jpg')
    data['password'] = plain_password
    data['password_confirm'] = plain_password

    response = test_client.post(URL.USERPANEL_EDITPROFILE_POST,
                                data=data,
                                content_type='multipart/form-data',
                                follow_redirects=True)

    assert response.status_code == 200
    assert b'You have successfully edited the profile' in response.data
    assert old_profile_pic != customer.profile_pic
コード例 #30
0
def test_post_apmc_pre_train_regression_ok(secrets_mock, test_client):
    secrets_mock.token_hex.return_value = 100

    customer, plain_password = create_customer()
    login_customer(test_client, customer.login, plain_password)

    data = dict()
    data['project_name'] = "Test project name"
    file_content = get_dataset_data('usa_dataset.csv')
    data['file'] = (BytesIO(file_content.encode()), 'apmc_test_dataset.csv')
    data['model_type'] = "regression"
    data['normalization'] = False

    response = test_client.post(URL.APMC_PRE_TRAIN_POST,
                                data=data,
                                content_type='multipart/form-data')
    pre_train_result = json.loads(response.data)

    assert response.status_code == 200
    assert 'data_id' in pre_train_result
    assert 'model_metrics' in pre_train_result
    assert 'user_choices' in pre_train_result
    assert 'best_model' in pre_train_result
    assert 'dummy_model_warnings' in pre_train_result