def test_internal_product_id_label(self):
        settings = AppSettings()

        # get values
        value = settings.get_internal_product_id_label()
        assert value == "Internal Product ID"

        # set values
        test_internal_product_label = "My custom label"
        settings.set_internal_product_id_label(test_internal_product_label)
        value = settings.get_internal_product_id_label()

        assert value == test_internal_product_label
    def test_internal_product_id_label(self):
        settings = AppSettings()

        # get values
        value = settings.get_internal_product_id_label()
        assert value == "Internal Product ID"

        # set values
        test_internal_product_label = "My custom label"
        settings.set_internal_product_id_label(test_internal_product_label)
        value = settings.get_internal_product_id_label()

        assert value == test_internal_product_label
def get_internal_product_id_label(request):
    app_config = AppSettings()
    return {
        "INTERNAL_PRODUCT_ID_LABEL": app_config.get_internal_product_id_label(),
        "STAT_AMOUNT_OF_PRODUCT_CHECKS": app_config.get_amount_of_product_checks(),
        "STAT_AMOUNT_OF_UNIQUE_PRODUCT_CHECK_ENTRIES": app_config.get_amount_of_unique_product_check_entries(),
    }
예제 #4
0
def get_internal_product_id_label(request):
    app_config = AppSettings()
    return {
        "INTERNAL_PRODUCT_ID_LABEL":
        app_config.get_internal_product_id_label(),
        "STAT_AMOUNT_OF_PRODUCT_CHECKS":
        app_config.get_amount_of_product_checks(),
        "STAT_AMOUNT_OF_UNIQUE_PRODUCT_CHECK_ENTRIES":
        app_config.get_amount_of_unique_product_check_entries()
    }
    def test_product_group_view(self, browser, live_server):
        # navigate to the homepage
        browser.get(live_server + reverse("productdb:home"))

        # go to the "All Product Groups" view
        browser.find_element_by_id("nav_browse").click()
        browser.find_element_by_id("nav_browse_all_product_groups").click()

        # verify page by page title
        assert "All Product Groups" in browser.find_element_by_tag_name(
            "body").text

        # test table content
        expected_table_content = """Vendor\nName"""
        table_rows = [
            'Cisco Systems Catalyst 3850',
            'Cisco Systems Catalyst 2960X',
            'Cisco Systems Catalyst 2960',
            'Juniper Networks EX2200',
        ]

        table = browser.find_element_by_id('product_group_table')
        assert expected_table_content in table.text
        for r in table_rows:
            assert r in table.text

        # search product group by vendor column
        table_rows = [
            'Juniper Networks EX2200',
        ]

        browser.find_element_by_id("column_search_Vendor").send_keys("Juni")
        table = browser.find_element_by_id('product_group_table')
        assert expected_table_content in table.text
        for r in table_rows:
            assert r in table.text
        browser.find_element_by_id("column_search_Vendor").clear()

        # search product group by vendor column
        table_rows = [
            'Cisco Systems Catalyst 3850',
            'Cisco Systems Catalyst 2960X',
            'Cisco Systems Catalyst 2960',
        ]

        browser.find_element_by_id("column_search_Name").send_keys("yst")
        time.sleep(2)
        table = browser.find_element_by_id('product_group_table')
        assert expected_table_content in table.text
        for r in table_rows:
            assert r in table.text
        browser.find_element_by_id("column_search_Name").clear()
        time.sleep(2)

        # click on the "Catalyst 2960X" link
        browser.find_element_by_partial_link_text("Catalyst 2960X").click()

        # verify page title
        assert "Catalyst 2960X Product Group details" in browser.find_element_by_tag_name(
            "body").text

        # verify table content
        expected_table_content = """Product ID\nDescription\nList Price Lifecycle State"""
        table_rows = [
            'C2960X-STACK',
            'CAB-ACE',
            'CAB-STK-E-0.5M',
        ]

        table = browser.find_element_by_id('product_table')
        assert expected_table_content in table.text
        for r in table_rows:
            assert r in table.text
            # search product group by vendor column

        table_rows = [
            'WS-C2960X-24PD-L',
            'WS-C2960X-24TD-L',
        ]

        browser.find_element_by_id("column_search_Description").send_keys(
            "2 x")
        table = browser.find_element_by_id('product_table')
        assert expected_table_content in table.text
        for r in table_rows:
            assert r in table.text
        browser.find_element_by_id("column_search_Description").clear()
        time.sleep(2)

        # open detail page
        browser.find_element_by_partial_link_text("C2960X-STACK").click()
        detail_link = browser.current_url

        # verify page by title
        assert "C2960X-STACK Product details" in browser.find_element_by_tag_name(
            "body").text

        # verify that the "Internal Product ID" is not visible (because not set)
        app_config = AppSettings()
        assert app_config.get_internal_product_id_label(
        ) not in browser.find_element_by_tag_name("body").text

        # add an internal product ID and verify that it is visible
        test_internal_product_id = "123456789-abcdef"
        p = Product.objects.get(product_id="C2960X-STACK")
        p.internal_product_id = test_internal_product_id
        p.save()

        browser.get(detail_link)
        page_text = browser.find_element_by_tag_name("body").text
        assert app_config.get_internal_product_id_label() in page_text
        assert test_internal_product_id in page_text
예제 #6
0
def change_configuration(request):
    """
    change configuration of the Product Database
    """
    # read settings from configuration file
    app_config = AppSettings()

    # read settings from database
    hp_content_after, _ = TextBlock.objects.get_or_create(
        name=TextBlock.TB_HOMEPAGE_TEXT_AFTER_FAVORITE_ACTIONS
    )
    hp_content_before, _ = TextBlock.objects.get_or_create(
        name=TextBlock.TB_HOMEPAGE_TEXT_BEFORE_FAVORITE_ACTIONS
    )

    if request.method == "POST":
        # create a form instance and populate it with data from the request:
        form = SettingsForm(request.POST)
        if form.is_valid():
            # set common settings
            app_config.set_login_only_mode(form.cleaned_data["login_only_mode"])

            hp_content_before.html_content = form.cleaned_data["homepage_text_before"]
            hp_content_before.save()
            hp_content_after.html_content = form.cleaned_data["homepage_text_after"]
            hp_content_after.save()

            # set the Cisco API configuration options
            api_enabled = form.cleaned_data["cisco_api_enabled"]

            if not api_enabled:
                # api is disabled, reset values to default
                app_config.set_cisco_api_enabled(api_enabled)
                app_config.set_cisco_api_client_id("PlsChgMe")
                app_config.set_cisco_api_client_secret("PlsChgMe")
                app_config.set_periodic_sync_enabled(False)
                app_config.set_auto_create_new_products(False)
                app_config.set_cisco_eox_api_queries("")
                app_config.set_product_blacklist_regex("")
                app_config.set_cisco_eox_api_sync_wait_time("5")

            else:
                app_config.set_cisco_api_enabled(api_enabled)

                client_id = form.cleaned_data["cisco_api_client_id"] \
                    if form.cleaned_data["cisco_api_client_id"] != "" else "PlsChgMe"
                app_config.set_cisco_api_client_id(client_id)
                client_secret = form.cleaned_data["cisco_api_client_secret"] \
                    if form.cleaned_data["cisco_api_client_secret"] != "" else "PlsChgMe"
                app_config.set_cisco_api_client_secret(client_secret)

                app_config.set_internal_product_id_label(form.cleaned_data["internal_product_id_label"])
                app_config.set_periodic_sync_enabled(form.cleaned_data["eox_api_auto_sync_enabled"])
                app_config.set_auto_create_new_products(form.cleaned_data["eox_auto_sync_auto_create_elements"])
                app_config.set_cisco_eox_api_queries(form.cleaned_data["eox_api_queries"])
                app_config.set_product_blacklist_regex(form.cleaned_data["eox_api_blacklist"])
                if form.cleaned_data["eox_api_wait_time"]:
                    app_config.set_cisco_eox_api_sync_wait_time(form.cleaned_data["eox_api_wait_time"])

                if client_id != "PlsChgMe":
                    result = utils.check_cisco_eox_api_access(
                        form.cleaned_data["cisco_api_client_id"],
                        form.cleaned_data["cisco_api_client_secret"]
                    )

                    if result:
                        messages.success(request, "Successfully connected to the Cisco EoX API")

                    else:
                        messages.error(request, "Cannot contact the Cisco EoX API. Please contact your "
                                                "Administrator")

                else:
                    messages.info(
                        request,
                        "Please configure your Cisco API credentials within the Cisco API settings tab."
                    )

            # expire cached settings
            cache.delete("LOGIN_ONLY_MODE_SETTING")

            messages.success(request, "Settings saved successfully")
            return redirect(resolve_url("productdb_config:change_settings"))

        else:
            messages.error(request, "Invalid configuration option detected, please check it below.")

    else:
        form = SettingsForm()
        form.fields['cisco_api_enabled'].initial = app_config.is_cisco_api_enabled()
        form.fields['login_only_mode'].initial = app_config.is_login_only_mode()
        form.fields['internal_product_id_label'].initial = app_config.get_internal_product_id_label()
        form.fields['cisco_api_client_id'].initial = app_config.get_cisco_api_client_id()
        form.fields['cisco_api_client_secret'].initial = app_config.get_cisco_api_client_secret()
        form.fields['eox_api_auto_sync_enabled'].initial = app_config.is_periodic_sync_enabled()
        form.fields['eox_auto_sync_auto_create_elements'].initial = app_config.is_auto_create_new_products()
        form.fields['eox_api_queries'].initial = app_config.get_cisco_eox_api_queries()
        form.fields['eox_api_blacklist'].initial = app_config.get_product_blacklist_regex()
        form.fields['eox_api_wait_time'].initial = app_config.get_cisco_eox_api_sync_wait_time()
        form.fields['homepage_text_before'].initial = hp_content_before.html_content
        form.fields['homepage_text_after'].initial = hp_content_after.html_content

    context = {
        "form": form,
        "is_cisco_api_enabled": app_config.is_cisco_api_enabled(),
        "is_cisco_eox_api_auto_sync_enabled": app_config.is_periodic_sync_enabled()
    }
    return render(request, "config/change_configuration.html", context=context)
    def test_product_group_view(self, browser, live_server):
        # navigate to the homepage
        browser.get(live_server + reverse("productdb:home"))

        # go to the "All Product Groups" view
        browser.find_element_by_id("nav_browse").click()
        browser.find_element_by_id("nav_browse_all_product_groups").click()

        # verify page by page title
        assert "All Product Groups" in browser.find_element_by_tag_name("body").text

        # test table content
        expected_table_content = """Vendor\nName"""
        table_rows = [
            'Cisco Systems Catalyst 3850',
            'Cisco Systems Catalyst 2960X',
            'Cisco Systems Catalyst 2960',
            'Juniper Networks EX2200',
        ]

        table = browser.find_element_by_id('product_group_table')
        assert expected_table_content in table.text
        for r in table_rows:
            assert r in table.text

        # search product group by vendor column
        table_rows = [
            'Juniper Networks EX2200',
        ]

        browser.find_element_by_id("column_search_Vendor").send_keys("Juni")
        table = browser.find_element_by_id('product_group_table')
        assert expected_table_content in table.text
        for r in table_rows:
            assert r in table.text
        browser.find_element_by_id("column_search_Vendor").clear()

        # search product group by vendor column
        table_rows = [
            'Cisco Systems Catalyst 3850',
            'Cisco Systems Catalyst 2960X',
            'Cisco Systems Catalyst 2960',
        ]

        browser.find_element_by_id("column_search_Name").send_keys("yst")
        time.sleep(2)
        table = browser.find_element_by_id('product_group_table')
        assert expected_table_content in table.text
        for r in table_rows:
            assert r in table.text
        browser.find_element_by_id("column_search_Name").clear()
        time.sleep(2)

        # click on the "Catalyst 2960X" link
        browser.find_element_by_partial_link_text("Catalyst 2960X").click()

        # verify page title
        assert "Catalyst 2960X Product Group details" in browser.find_element_by_tag_name("body").text

        # verify table content
        expected_table_content = """Product ID\nDescription\nList Price Lifecycle State"""
        table_rows = [
            'C2960X-STACK',
            'CAB-ACE',
            'CAB-STK-E-0.5M',
        ]

        table = browser.find_element_by_id('product_table')
        assert expected_table_content in table.text
        for r in table_rows:
            assert r in table.text
            # search product group by vendor column

        table_rows = [
            'WS-C2960X-24PD-L',
            'WS-C2960X-24TD-L',
        ]

        browser.find_element_by_id("column_search_Description").send_keys("2 x")
        table = browser.find_element_by_id('product_table')
        assert expected_table_content in table.text
        for r in table_rows:
            assert r in table.text
        browser.find_element_by_id("column_search_Description").clear()
        time.sleep(2)

        # open detail page
        browser.find_element_by_partial_link_text("C2960X-STACK").click()
        detail_link = browser.current_url

        # verify page by title
        assert "C2960X-STACK Product details" in browser.find_element_by_tag_name("body").text

        # verify that the "Internal Product ID" is not visible (because not set)
        app_config = AppSettings()
        assert app_config.get_internal_product_id_label() not in browser.find_element_by_tag_name("body").text

        # add an internal product ID and verify that it is visible
        test_internal_product_id = "123456789-abcdef"
        p = Product.objects.get(product_id="C2960X-STACK")
        p.internal_product_id = test_internal_product_id
        p.save()

        browser.get(detail_link)
        page_text = browser.find_element_by_tag_name("body").text
        assert app_config.get_internal_product_id_label() in page_text
        assert test_internal_product_id in page_text
예제 #8
0
def change_configuration(request):
    """
    change configuration of the Product Database
    """
    # read settings from configuration file
    app_config = AppSettings()

    # read settings from database
    hp_content_after, _ = TextBlock.objects.get_or_create(
        name=TextBlock.TB_HOMEPAGE_TEXT_AFTER_FAVORITE_ACTIONS
    )
    hp_content_before, _ = TextBlock.objects.get_or_create(
        name=TextBlock.TB_HOMEPAGE_TEXT_BEFORE_FAVORITE_ACTIONS
    )

    if request.method == "POST":
        # create a form instance and populate it with data from the request:
        form = SettingsForm(request.POST)
        if form.is_valid():
            # set common settings
            app_config.set_login_only_mode(form.cleaned_data["login_only_mode"])

            hp_content_before.html_content = form.cleaned_data["homepage_text_before"]
            hp_content_before.save()
            hp_content_after.html_content = form.cleaned_data["homepage_text_after"]
            hp_content_after.save()

            # set the Cisco API configuration options
            api_enabled = form.cleaned_data["cisco_api_enabled"]

            if not api_enabled:
                # api is disabled, reset values to default
                app_config.set_cisco_api_enabled(api_enabled)
                app_config.set_cisco_api_client_id("PlsChgMe")
                app_config.set_cisco_api_client_secret("PlsChgMe")
                app_config.set_periodic_sync_enabled(False)
                app_config.set_auto_create_new_products(False)
                app_config.set_cisco_eox_api_queries("")
                app_config.set_product_blacklist_regex("")
                app_config.set_cisco_eox_api_sync_wait_time("5")

            else:
                app_config.set_cisco_api_enabled(api_enabled)

                client_id = form.cleaned_data["cisco_api_client_id"] \
                    if form.cleaned_data["cisco_api_client_id"] != "" else "PlsChgMe"
                app_config.set_cisco_api_client_id(client_id)
                client_secret = form.cleaned_data["cisco_api_client_secret"] \
                    if form.cleaned_data["cisco_api_client_secret"] != "" else "PlsChgMe"
                app_config.set_cisco_api_client_secret(client_secret)

                if client_id != "PlsChgMe":
                    result = utils.check_cisco_eox_api_access(
                        form.cleaned_data["cisco_api_client_id"],
                        form.cleaned_data["cisco_api_client_secret"]
                    )

                    if result:
                        messages.success(request, "Successfully connected to the Cisco EoX API")

                    else:
                        messages.error(request, "Cannot contact the Cisco EoX API. Please contact your "
                                                "Administrator")

                else:
                    messages.info(
                        request,
                        "Please configure your Cisco API credentials within the Cisco API settings tab."
                    )

                app_config.set_periodic_sync_enabled(form.cleaned_data["eox_api_auto_sync_enabled"])
                app_config.set_internal_product_id_label(form.cleaned_data["internal_product_id_label"])
                app_config.set_auto_create_new_products(form.cleaned_data["eox_auto_sync_auto_create_elements"])
                app_config.set_cisco_eox_api_queries(form.cleaned_data["eox_api_queries"])
                app_config.set_product_blacklist_regex(form.cleaned_data["eox_api_blacklist"])
                if form.cleaned_data["eox_api_wait_time"]:
                    app_config.set_cisco_eox_api_sync_wait_time(form.cleaned_data["eox_api_wait_time"])

            # expire cached settings
            cache.delete("LOGIN_ONLY_MODE_SETTING")

            messages.success(request, "Settings saved successfully")
            return redirect(resolve_url("productdb_config:change_settings"))

        else:
            messages.error(request, "Invalid configuration option detected, please check it below.")

    else:
        form = SettingsForm()
        form.fields['cisco_api_enabled'].initial = app_config.is_cisco_api_enabled()
        form.fields['login_only_mode'].initial = app_config.is_login_only_mode()
        form.fields['internal_product_id_label'].initial = app_config.get_internal_product_id_label()
        form.fields['cisco_api_client_id'].initial = app_config.get_cisco_api_client_id()
        form.fields['cisco_api_client_secret'].initial = app_config.get_cisco_api_client_secret()
        form.fields['eox_api_auto_sync_enabled'].initial = app_config.is_periodic_sync_enabled()
        form.fields['eox_auto_sync_auto_create_elements'].initial = app_config.is_auto_create_new_products()
        form.fields['eox_api_queries'].initial = app_config.get_cisco_eox_api_queries()
        form.fields['eox_api_blacklist'].initial = app_config.get_product_blacklist_regex()
        form.fields['eox_api_wait_time'].initial = app_config.get_cisco_eox_api_sync_wait_time()
        form.fields['homepage_text_before'].initial = hp_content_before.html_content
        form.fields['homepage_text_after'].initial = hp_content_after.html_content

    context = {
        "form": form,
        "is_cisco_api_enabled": app_config.is_cisco_api_enabled(),
        "is_cisco_eox_api_auto_sync_enabled": app_config.is_periodic_sync_enabled()
    }
    return render(request, "config/change_configuration.html", context=context)