def test_generate_object_repository():
    # given
    property_name = "test_property"
    schema_json = {
        "type": "object",
        "$generator": "#/object-repository/dim-sample",
        "$pairwise": True
    }
    config = {
        "object_repository_dir": "tap_test_data_generator/object-repositories"
    }
    object_repositories = load_repositories(config)
    faker_factory = Faker()
    value_lists = data_generator.extract_value_lists("test_property",
                                                     schema_json,
                                                     object_repositories, {})
    # adding a second property into value_lists because at least 2 properties are required in order to AllPairs works
    value_lists["boolean"] = [True, False]
    pairwise_values = AllPairs(value_lists)
    pairs = pairwise_values.next()
    # when
    dictionary = data_generator.generate_object({}, property_name, schema_json,
                                                faker_factory,
                                                object_repositories, pairs, {},
                                                5)
    # then
    assert dictionary is not None
    assert "test_property" in dictionary
    assert "width" in dictionary["test_property"]
    assert "height" in dictionary["test_property"]
def test_generate_dictionary():
    # given
    config = {
        "schema_dir": "tap_test_data_generator/schemas",
        "metadata_dir": "tap_test_data_generator/metadatas",
        "object_repository_dir": "tap_test_data_generator/object-repositories",
        "static_input_dir": "",
        "record_number": 100,
        "apply_record_number_on_pairwise": True,
        "data_locale_list": ["en_US", "fr_FR"]
    }
    object_repositories = load_repositories(config)
    catalog = discover(config)
    stream = catalog.get_stream("sample")
    schema_json = load_schema_json(config, stream)
    definitions = load_definitions(schema_json, config)
    value_lists = data_generator.extract_value_lists(None, schema_json,
                                                     object_repositories,
                                                     definitions)
    pairwise_values = AllPairs(value_lists)
    pairs = pairwise_values.next()
    faker_factory = Faker()
    # when
    generated_dict = data_generator.generate_dictionary(
        None, schema_json, {}, faker_factory, object_repositories, pairs,
        definitions, 5)
    # then
    assert generated_dict is not None
    assert "checked" in generated_dict
    assert "dimensions" in generated_dict
    assert "id" in generated_dict
    assert "color" in generated_dict
    assert "price" in generated_dict
    assert "tags" in generated_dict
    assert "hour" in generated_dict
Пример #3
0
    def test_normal(self):
        parameters = OrderedDict({
            "brand": ["Brand X", "Brand Y"],
            "os": ["NT", "2000", "XP"],
            "minute": [15, 30, 60],
        })

        for pairs in AllPairs(parameters):
            assert pairs.brand == 'Brand X'
            assert pairs.os == 'NT'
            assert pairs.minute == 15
            break

        assert len(list(AllPairs(parameters))) == 9
Пример #4
0
def dual_test_case(_base):
    """对偶生成测试用例"""
    if not isinstance(_base, dict):
        return []
    key_list = list()
    value_list = list()
    case_list = list()

    for k, v in _base.items():
        key_list.append(k)
        value_list.append(get_data_list(v))

    print(key_list)
    print('value_list---', value_list)

    if value_list.__len__() >= 2:
        res = AllPairs(value_list)
        for i, b in enumerate(res):
            # print i, b
            dic = dict()
            for n in range(b.__len__()):
                dic[key_list[n]] = b[n]
            case_list.append(dic)
    else:
        for v in value_list[0]:
            dic = dict()
            dic[key_list[0]] = v
            case_list.append(dic)
    return case_list
 def generate_params_list(self):
     parameters = http_params_generator.get_pairwise_list(
         self.get_params_num())
     params_usage_2d_list = []
     params_combo_list = []
     if len(parameters) > 1:
         for pairs in AllPairs(parameters):
             params_usage_2d_list.append(pairs)
         for params_usage_list in params_usage_2d_list:
             yield_params_usage_list = http_params_generator.yield_list(
                 params_usage_list)
             raw_params_list = self.generate_params(
                 parameters_usage_list=yield_params_usage_list)
             prepared_params_list = http_params_generator.get_value_dic(
                 raw_params_list)
             params_combo_list.append(prepared_params_list)
     elif len(parameters) == 1:  # 当只有一个参数的时候第三方库ALLPAIRS不支持
         yield_params_usage_list_true = http_params_generator.yield_list(
             [True])
         yield_params_usage_list_false = http_params_generator.yield_list(
             [False])
         raw_params_list_true = self.generate_params(
             parameters_usage_list=yield_params_usage_list_true)
         prepared_params_list_true = http_params_generator.get_value_dic(
             raw_params_list_true)
         raw_params_list_false = self.generate_params(
             parameters_usage_list=yield_params_usage_list_false)
         prepared_params_list_false = http_params_generator.get_value_dic(
             raw_params_list_false)
         params_combo_list.append(prepared_params_list_true)
         params_combo_list.append(prepared_params_list_false)
     self.generated_params_list = params_combo_list
Пример #6
0
class Test__parameterized(object):

    @pytest.mark.parametrize(
        ["username", "email", "password","button"],
        [
            value_list for value_list in AllPairs([
                ["testpairwise", "test","","!@#@#"],
                ["*****@*****.**", "test","!@$!@$!@%"],
                ["testpairwise", "0", "", "!$!@@#@#@%"],
                ["done", "cancel"]
        ])
        ])

    def test(self, username, email, password,button):

        assert function_to_be_tested(username, email, password,button)


# output:
#pass  0: ['testpairwise', '*****@*****.**', 'testpairwise', 'done']
#fail  1: ['test', 'test', '0', 'done']
#fail  2: ['', '!@$!@$!@%', '', 'done']
#fail  3: ['!@#@#', '!@$!@$!@%', '!$!@@#@#@%', 'cancel']
#fail  4: ['!@#@#', 'test', 'testpairwise', 'cancel']
#fail  5: ['', '*****@*****.**', '!$!@@#@#@%', 'cancel']
#fail  6: ['test', '*****@*****.**', '', 'cancel']
#fail  7: ['testpairwise', '!@$!@$!@%', '0', 'cancel']
#fail  8: ['!@#@#', '*****@*****.**', '0', 'done']
#fail  9: ['testpairwise', 'test', '!$!@@#@#@%', 'done']
#fail 10: ['test', '!@$!@$!@%', 'testpairwise', 'done']
#fail 11: ['', 'test', 'testpairwise', 'done']
#fail 12: ['', 'test', '0', 'done']
#fail 13: ['test', 'test', '!$!@@#@#@%', 'done']
#fail 14: ['testpairwise', 'test', '', 'done']
#fail 15: ['!@#@#', 'test', '', 'done']
Пример #7
0
    def test_normal(self):
        parameters = [
            ["Brand X", "Brand Y"],
            ["98", "NT", "2000", "XP"],
            ["Internal", "Modem"],
            ["Salaried", "Hourly", "Part-Time", "Contr."],
            [6, 10, 15, 30, 60],
        ]

        assert list(AllPairs(parameters)) == [
            ['Brand X', '98', 'Internal', 'Salaried', 6],
            ['Brand Y', 'NT', 'Modem', 'Hourly', 6],
            ['Brand Y', '2000', 'Internal', 'Part-Time', 10],
            ['Brand X', 'XP', 'Modem', 'Contr.', 10],
            ['Brand X', '2000', 'Modem', 'Part-Time', 15],
            ['Brand Y', 'XP', 'Internal', 'Hourly', 15],
            ['Brand Y', '98', 'Modem', 'Salaried', 30],
            ['Brand X', 'NT', 'Internal', 'Contr.', 30],
            ['Brand X', '98', 'Internal', 'Hourly', 60],
            ['Brand Y', '2000', 'Modem', 'Contr.', 60],
            ['Brand Y', 'NT', 'Modem', 'Salaried', 60],
            ['Brand Y', 'XP', 'Modem', 'Part-Time', 60],
            ['Brand Y', '2000', 'Modem', 'Hourly', 30],
            ['Brand Y', '98', 'Modem', 'Contr.', 15],
            ['Brand Y', 'XP', 'Modem', 'Salaried', 15],
            ['Brand Y', 'NT', 'Modem', 'Part-Time', 15],
            ['Brand Y', 'XP', 'Modem', 'Part-Time', 30],
            ['Brand Y', '98', 'Modem', 'Part-Time', 6],
            ['Brand Y', '2000', 'Modem', 'Salaried', 6],
            ['Brand Y', '98', 'Modem', 'Salaried', 10],
            ['Brand Y', 'XP', 'Modem', 'Contr.', 6],
            ['Brand Y', 'NT', 'Modem', 'Hourly', 10]
        ]
Пример #8
0
    def test_normal(self):
        parameters = [
            ["Brand X", "Brand Y"],
            ["98", "NT", "2000", "XP"],
            ["Internal", "Modem"],
            ["Salaried", "Hourly", "Part-Time", "Contr."],
            [6, 10, 15, 30, 60],
        ]

        assert list(AllPairs(parameters)) == [
            ["Brand X", "98", "Internal", "Salaried", 6],
            ["Brand Y", "NT", "Modem", "Hourly", 6],
            ["Brand Y", "2000", "Internal", "Part-Time", 10],
            ["Brand X", "XP", "Modem", "Contr.", 10],
            ["Brand X", "2000", "Modem", "Part-Time", 15],
            ["Brand Y", "XP", "Internal", "Hourly", 15],
            ["Brand Y", "98", "Modem", "Salaried", 30],
            ["Brand X", "NT", "Internal", "Contr.", 30],
            ["Brand X", "98", "Internal", "Hourly", 60],
            ["Brand Y", "2000", "Modem", "Contr.", 60],
            ["Brand Y", "NT", "Modem", "Salaried", 60],
            ["Brand Y", "XP", "Modem", "Part-Time", 60],
            ["Brand Y", "2000", "Modem", "Hourly", 30],
            ["Brand Y", "98", "Modem", "Contr.", 15],
            ["Brand Y", "XP", "Modem", "Salaried", 15],
            ["Brand Y", "NT", "Modem", "Part-Time", 15],
            ["Brand Y", "XP", "Modem", "Part-Time", 30],
            ["Brand Y", "98", "Modem", "Part-Time", 6],
            ["Brand Y", "2000", "Modem", "Salaried", 6],
            ["Brand Y", "98", "Modem", "Salaried", 10],
            ["Brand Y", "XP", "Modem", "Contr.", 6],
            ["Brand Y", "NT", "Modem", "Hourly", 10],
        ]
Пример #9
0
    def test_whitelist(self):
        parameters = [
            ("brand", ["Brand X", "Brand Y"]),
            ("os", ["98", "NT", "2000", "XP"]),
            ("network", ["Internal", "Modem"]),
            ("employee", ["Salaried", "Hourly", "Part-Time", "Contr."]),
            ("increment", [6, 10, 15, 30, 60]),
        ]

        def whitelist(chosen_item_list, item):
            found_brand_x = False
            found_os_98 = False
            for chosen_item in chosen_item_list:
                if chosen_item.value == "Brand X": found_brand_x = True
                if chosen_item.value == "98": found_os_98 = True

            if item.value == "Brand X": found_brand_x = True
            if item.value == "98": found_os_98 = True
            if found_brand_x and found_os_98:
                return False
            else:
                return True

        new_list = list(
            AllPairs([x[1] for x in parameters], whitelist_func=whitelist))
        print(new_list)
        for record in new_list:
            found_brand_x = False
            found_os_98 = False
            for item in record:
                if item == "Brand X": found_brand_x = True
                if item == "98": found_os_98 = True
            assert not (found_brand_x and found_os_98)
    def test_declined_combinations(self):
        for _, pairs in enumerate(AllPairs(self.declined_parameters_dict)):
            data = {
                'username': pairs.username,
                'first_name': pairs.textfield_30,
                'last_name': pairs.textfield_30,
                'categories': pairs.categories,
                'company': pairs.textfield_30,
                'email': pairs.email,
                'email_confirmation': pairs.email,
                'password1': pairs.password,
                'password2': pairs.password,
                'phone_number': pairs.textfield_50,
                'country': pairs.textfield_50,
                'state': pairs.textfield_50,
                'city': pairs.textfield_50,
                'postal_code': pairs.textfield_50,
                'street_address': pairs.textfield_50
            }
            form = SignUpForm(data)

            # Using subtest to prevent return of test failure immediately,
            # possibly before all combinations are tested!
            with self.subTest(form=form):
                self.assertFalse(form.is_valid())
Пример #11
0
    def __set_fuzz(self, d):
        data = []
        for i, par in enumerate(AllPairs(OrderedDict(d))):
            app = []
            for j in par:
                app.append(j)
            data.append(app)

        dd = []
        for i in data:
            d = []
            for j in range(len(i)):
                d.append(i[j])
            dd.append(d)

        d2 = []
        for i in dd:
            d1 = []
            for j in i:
                app = {}
                if j.get("code", -9) == -1:
                    app[j["key"]] = ""
                elif j.get("code", -9) == -3:
                    pass
                else:
                    app[j["key"]] = j["value"]
                app["info"] = j["key"] + j["info"]
                d1.append(app)
            d2.append(d1)
        return d2
Пример #12
0
def generate_object_all_pairs():
    test_parameters = OrderedDict({
        "obj_start_y": [
            "left",
            "right",
        ],
        "obj_start_x": [
            "close",
            "medium",
            "far",
        ],
        "obj_speed": [
            "stationary",
            "slow",
            "fast",
        ],
        "obj_angle": [
            "perpendicular",
        ],
        "car_speed": [
            "slow",
            "medium",
            "fast",
        ],
        "obj_type": [
            "box",
            "cone",
            "pyramid",
            "sphere",
        ],
    })

    for pair in AllPairs(test_parameters, filter_func=is_valid_combination):
        pair = cast(Any, pair)
        collision_values = calculate_collision_values(
            start_y_class=pair.obj_start_y,
            start_x_class=pair.obj_start_x,
            obj_speed_class=pair.obj_speed,
            obj_angle_class=pair.obj_angle,
            car_speed_class=pair.car_speed,
        )

        if not collision_values:
            raise Exception("Expected collision values to exists")

        obj_x0, car_speed = collision_values
        obj_y0 = latteral_offset_mapping[pair.obj_start_y]

        print(
            ObjectTestConfiguration(
                object_type=pair.obj_type,
                start_x=obj_x0,
                start_y=obj_y0,
                end_x=obj_x0,
                end_y=-obj_y0,
                angle=-np.sign(obj_y0) * 90,
                speed=object_speed_mapping[pair.obj_speed],
                car_speed=car_speed,
            ))
Пример #13
0
    def test_normal_example22(self):
        # example2.2.py

        parameters = [("brand", ["Brand X", "Brand Y"]),
                      ("os", ["98", "NT", "2000", "XP"]),
                      ("network", ["Internal", "Modem"]),
                      ("employee",
                       ["Salaried", "Hourly", "Part-Time", "Contr."]),
                      ("increment", [6, 10, 15, 30, 60])]

        def is_valid_combination(values, names):

            dictionary = dict(zip(names, values))
            """
            Should return True if combination is valid and False otherwise.

            Dictionary that is passed here can be incomplete.
            To prevent search for unnecessary items filtering function
            is executed with found subset of data to validate it.
            """

            rules = [
                # Brand Y does not support Windows 98
                # Brand X does not work with XP
                # Contractors are billed in 30 min increments
                lambda d: "98" == d["os"] and "Brand Y" == d["brand"],
                lambda d: "XP" == d["os"] and "Brand X" == d["brand"],
                lambda d: "Contr." == d["employee"] and d["increment"] < 30
            ]

            for rule in rules:
                try:
                    if rule(dictionary):
                        return False
                except KeyError:
                    pass

            return True

        assert list(
            AllPairs([x[1] for x in parameters],
                     filter_func=lambda values: is_valid_combination(
                         values, [x[0] for x in parameters]))) == [
                             ['Brand X', '98', 'Internal', 'Salaried', 6],
                             ['Brand Y', 'NT', 'Modem', 'Hourly', 6],
                             ['Brand Y', '2000', 'Internal', 'Part-Time', 10],
                             ['Brand X', '2000', 'Modem', 'Contr.', 30],
                             ['Brand X', 'NT', 'Internal', 'Contr.', 60],
                             ['Brand Y', 'XP', 'Modem', 'Salaried', 60],
                             ['Brand X', '98', 'Modem', 'Part-Time', 15],
                             ['Brand Y', 'XP', 'Internal', 'Hourly', 15],
                             ['Brand Y', 'NT', 'Internal', 'Part-Time', 30],
                             ['Brand X', '2000', 'Modem', 'Hourly', 10],
                             ['Brand Y', 'XP', 'Modem', 'Contr.', 30],
                             ['Brand Y', '2000', 'Modem', 'Salaried', 15],
                             ['Brand Y', 'NT', 'Modem', 'Salaried', 10],
                             ['Brand Y', 'XP', 'Modem', 'Part-Time', 6],
                             ['Brand Y', '2000', 'Modem', 'Contr.', 60],
                         ]
class Test__parameterized(object):
    @pytest.mark.parametrize(["brand", "operating_system", "minute"], [
        value_list for value_list in AllPairs([["Brand X", "Brand Y"],
                                               ["98", "NT", "2000", "XP"],
                                               [10, 15, 30, 60]])
    ])
    def test(self, brand, operating_system, minute):
        assert function_to_be_tested(brand, operating_system, minute)
Пример #15
0
def zhengjiao_play(request):
    end_values = request.GET['end_values'].split(',')
    new_values = [i.split('/') for i in end_values]
    res = []
    for i in AllPairs(new_values):
        res.append(i)
    d = {"res": res}
    return HttpResponse(json.dumps(d), content_type="application/json")
def test_generate_boolean_pair():
    # given
    property_name = "test_property"
    schema_json = {"type": "boolean", "$pairwise": True}
    faker_factory = Faker()
    value_lists = data_generator.extract_value_lists(property_name,
                                                     schema_json, None, {})
    # adding a second property into value_lists because at least 2 properties are required in order to AllPairs works
    value_lists["test2"] = ["A", "B"]
    pairwise_values = AllPairs(value_lists)
    pairs = pairwise_values.next()
    # when
    generated_boolean = data_generator.generate_boolean(
        property_name, schema_json, faker_factory, pairs, 0)
    # then
    assert generated_boolean is not None
    assert isinstance(generated_boolean, bool)
    assert getattr(pairs, property_name) == generated_boolean
Пример #17
0
def print_result(dimensions):
    header_list = []
    for d in dimensions:
        header_list.append("%i^%i" % d)

    pairwise = AllPairs(get_arrays(dimensions))
    n = len(list(pairwise))

    print("{:s}: produces {:d} rows".format(" * ".join(header_list), n))
Пример #18
0
class Test_tcconfig(object):
    """
    Tests in this class are not executable on CI services.
    Execute the following command at the local environment to running tests:
      python setup.py test --addopts "--runxfail --device=<test device>"

    These tests are expected to execute on following environment:
       - Linux w/ iputils-ping package
       - English locale (for parsing ping output)
    """

    @pytest.mark.skipif("SKIP_TEST is True")
    @pytest.mark.parametrize(
        [
            "rate", "delay", "delay_distro", "loss", "corrupt",
            "direction", "network", "port", "overwrite", "is_enable_iptables",
        ],
        [
            opt_list
            for opt_list in AllPairs([
                NormalTestValue.RATE_LIST,
                NormalTestValue.DELAY_LIST,
                NormalTestValue.DELAY_DISTRO_LIST,
                NormalTestValue.PACKET_LOSS_RATE_LIST,
                NormalTestValue.CORRUPTION_RATE_LIST,
                NormalTestValue.DIRECTION_LIST,
                NormalTestValue.NETWORK_LIST,
                NormalTestValue.PORT_LIST,
                NormalTestValue.OVERWRITE_LIST,
                NormalTestValue.IPTABLES_LIST,
            ], n=3, filter_func=is_valid_combination)
        ])
    def test_smoke(
            self, device_value, rate, delay, delay_distro, loss, corrupt,
            direction, network, port, overwrite, is_enable_iptables):

        if device_value is None:
            pytest.skip("device is empty")

        if is_invalid_param(rate, delay, loss, corrupt):
            pytest.skip("skip null parameters")

        device_option = "--device {}".format(device_value)

        SubprocessRunner("{:s} {:s}".format(
            TcCommand.TCDEL, device_option)).run()

        tcset_proc = SubprocessRunner(" ".join([
            TcCommand.TCSET,
            device_option,
            rate, delay, delay_distro, loss, corrupt,
            direction, network, port, overwrite, is_enable_iptables,
        ]))
        assert tcset_proc.run() == 0, tcset_proc.stderr

        SubprocessRunner("tcdel {:s}".format(device_option)).run()
Пример #19
0
def hello():
    pairwise = request.forms.get('pairwise')
    result = {'pairwise':pairwise, 'result':[]}

    rows =  [x.strip().split(',') for x in pairwise.split('\n')]

    for i, pairs in enumerate(AllPairs(rows)):
        result['result'].append('{:2d}: {}'.format(i, pairs))

    return template('index.tpl', result=result)
def test_generate_string_pair_pattern():
    # given
    property_name = "test_property"
    schema_json = {"type": "string", "pattern": "(A|P)M", "$pairwise": True}
    faker_factory = Faker()
    value_lists = data_generator.extract_value_lists_from_string(
        property_name, schema_json)
    # adding a second property into value_lists because at least 2 properties are required in order to AllPairs works
    value_lists["boolean"] = [True, False]
    pairwise_values = AllPairs(value_lists)
    pairs = pairwise_values.next()
    # when
    generated_string = data_generator.generate_string(property_name,
                                                      schema_json,
                                                      faker_factory, pairs, 0)
    # then
    assert generated_string is not None
    assert "" != generated_string
    assert getattr(pairs, property_name) == generated_string
Пример #21
0
def zhengjiao_play(request):
    end_values = request.GET["end_values"].split(",")
    # print(end_values)
    new_values = [i.split("/") for i in end_values]
    # print(new_values)
    res = []
    for i in AllPairs(new_values):
        # print(i)
        res.append(i)
    d = {"res": res}
    return HttpResponse(json.dumps(d), content_type='application/json')
Пример #22
0
    def test_normal_example21(self):
        # example2.1.py

        parameters = [
            ["Brand X", "Brand Y"],
            ["98", "NT", "2000", "XP"],
            ["Internal", "Modem"],
            ["Salaried", "Hourly", "Part-Time", "Contr."],
            [6, 10, 15, 30, 60],
        ]

        def is_valid_combination(row):
            """
            Should return True if combination is valid and False otherwise.

            Test row that is passed here can be incomplete.
            To prevent search for unnecessary items filtering function
            is executed with found subset of data to validate it.
            """

            n = len(row)
            if n > 1:
                # Brand Y does not support Windows 98
                if "98" == row[1] and "Brand Y" == row[0]:
                    return False
                # Brand X does not work with XP
                if "XP" == row[1] and "Brand X" == row[0]:
                    return False
            if n > 4:
                # Contractors are billed in 30 min increments
                if "Contr." == row[3] and row[4] < 30:
                    return False

            return True

        assert list(AllPairs(
            parameters, filter_func=is_valid_combination)) == [
                ["Brand X", "98", "Internal", "Salaried", 6],
                ["Brand Y", "NT", "Modem", "Hourly", 6],
                ["Brand Y", "2000", "Internal", "Part-Time", 10],
                ["Brand X", "2000", "Modem", "Contr.", 30],
                ["Brand X", "NT", "Internal", "Contr.", 60],
                ["Brand Y", "XP", "Modem", "Salaried", 60],
                ["Brand X", "98", "Modem", "Part-Time", 15],
                ["Brand Y", "XP", "Internal", "Hourly", 15],
                ["Brand Y", "NT", "Internal", "Part-Time", 30],
                ["Brand X", "2000", "Modem", "Hourly", 10],
                ["Brand Y", "XP", "Modem", "Contr.", 30],
                ["Brand Y", "2000", "Modem", "Salaried", 15],
                ["Brand Y", "NT", "Modem", "Salaried", 10],
                ["Brand Y", "XP", "Modem", "Part-Time", 6],
                ["Brand Y", "2000", "Modem", "Contr.", 60],
            ]
Пример #23
0
    def allpairs(self):
        result = []
        items = []
        for key, value in self.data['var'].items():
            items.append(['"' + key + '":"' + str(i) + '"' for i in value])

        if len(items) == 1:
            return items[0]

        for i in AllPairs(items, n=2):
            if i not in result:
                result.append(','.join(i))

        return result
class TestParameterized(object):
    @pytest.mark.parametrize(("brand, operating_system, minute"), [
        value_list
        for value_list in AllPairs([["X", "Y"], ["98", "NT", "2000", "XP"],
                                    [10, 15, 30, 60]])
    ])
    def test_with_pw(self, brand, operating_system, minute):
        pass

    @pytest.mark.parametrize("brand", ["X", "Y"])
    @pytest.mark.parametrize("operating_system", ["98", "NT", "2000", "XP"])
    @pytest.mark.parametrize("minute", [10, 15, 30, 60])
    def test_no_pw(self, brand, operating_system, minute):
        pass
Пример #25
0
def compute_value_pairs(value_lists, pair_generation_mode):
    pair_values = []
    keys = value_lists.keys()
    vals = value_lists.values()
    Pairs = namedtuple("Pairs", keys)
    if 'all_combinations' == pair_generation_mode:
        # create Pairs using cartesian product of value lists
        pair_values = cartesian_product(Pairs, keys, vals)
    elif 'every_value_at_least_once' == pair_generation_mode:
        # create Pairs until every value is used at least once
        pair_values = every_value_once(Pairs, keys, vals)
    else:
        # computing pairwise Pairs using lib
        pair_values = AllPairs(value_lists)
    return pair_values
Пример #26
0
class TestParameterized(object):
    @pytest.mark.parametrize(("brand, operating_system, browser"), [
        value_list
        for value_list in AllPairs([["DELL", "ACER"], ["98", "NT", "2000"],
                                    ["CHROME", "FIREFOX", "IE11", "SAFARI"]])
    ])
    def test_with_pw(self, brand, operating_system, browser):
        pass

    @pytest.mark.parametrize("brand", ["X", "Y"])
    @pytest.mark.parametrize("operating_system", ["98", "NT", "2000"])
    @pytest.mark.parametrize("browser",
                             ["CHROME", "FIREFOX", "IE11", "SAFARI"])
    def test_no_pw(self, brand, operating_system, browser):
        pass
Пример #27
0
def create_test_data(parame_value):
    """
    创建测试数据并存入Excel(正交法或allpairs规则创建测试集)
    :param parame_value: 参数值
    :return: True
    """
    value_data = AllPairs(parame_value)
    for i, value in enumerate(value_data):
        excel_data.excel_write_data(
            i + 1, 1, json.dumps(value._asdict(), ensure_ascii=False),
            'allPairs_data.xlsx')
        print(value)
        # a = i._asdict()  # 从namedtuple 转化为 OrderedDict
        # print(json.dumps(a)) #从OrderedDict转化为 json 字符串
    return True
Пример #28
0
 def genPara(self):
     allkeys = []  #表头
     allvalue = []  #值的列表
     allpairs = []
     with open(self.path, 'r', encoding='utf8') as f:
         allParas = f.readlines()
     for all in allParas:
         r = '[:,:,]'
         all = re.split(r, all.strip())  #所有切割好的值,strip()去掉头和尾左右的空格
         allkeys.append(all[0])
         allvalue.append(all[1:])
     allpairs.append(allkeys)
     ##生成正交列表
     for pairs in AllPairs(allvalue):
         allpairs.append(pairs)
     return allpairs  #返回表头和正交值
    def setUp(self):
        fake = Faker()  # Generate fake data using a faker generator

        # Configure values used in the success test case
        self.approved_username = FuzzyText(length=20).fuzz()
        self.approved_textfield_30 = FuzzyText(length=20).fuzz()
        self.approved_textfield_50 = FuzzyText(length=40).fuzz()
        self.approved_email_1 = fake.email()
        self.approved_email_2 = fake.email()
        self.approved_password_1 = fake.password()
        self.approved_password_2 = fake.password()
        self.approved_categories = [ProjectCategory.objects.create(pk=1)]

        # Configure declined parameters for use in the test cases
        username_1 = ""
        username_2 = FuzzyText(
            length=50, chars=string.punctuation).fuzz()  # Special charaters
        username_3 = FuzzyText(length=151).fuzz()
        textfield_30_1 = ""
        textfield_30_2 = FuzzyText(length=40).fuzz()
        textfield_50_1 = ""
        textfield_50_2 = FuzzyText(length=60).fuzz()
        email_1 = FuzzyText(length=245, suffix="@gmail.com").fuzz()
        email_2 = FuzzyText(length=20).fuzz()
        password_1 = FuzzyText(length=4).fuzz()
        password_2 = FuzzyText(length=16, chars=string.digits).fuzz()
        categories = []

        declined_parameters = [[username_1, username_2, username_3],
                               [textfield_30_1, textfield_30_2],
                               [textfield_50_1, textfield_50_2],
                               [email_1, email_2], [email_1, email_2],
                               [password_1, password_2],
                               [password_1, password_2], [categories]]

        # Generate all possible combinations
        self.declined_combinations = list(AllPairs(declined_parameters))

        self.declined_parameters_dict = OrderedDict({
            "username": [username_1, username_2, username_3],
            "textfield_30": [textfield_30_1, textfield_30_2],
            "textfield_50": [textfield_50_1, textfield_50_2],
            "email": [email_1, email_2],
            "password": [password_1, password_2],
            "categories": [categories]
        })
Пример #30
0
    def __set_fuzz(self, d):
        data = []
        for i, par in enumerate(AllPairs(OrderedDict(d))):
            app = []
            for j in par:
                app.append(j)
            data.append(app)

        dd = []
        for i in data:
            d = []
            for j in range(len(i)):
                d.append(i[j])
            dd.append(d)

        d2 = []
        for i in dd:
            d1 = []
            for j in i:
                app = {}
                """
                 0 表示参数不传内容
                 1 所有参数全部正确
                 -1 表示删除此参数
                 -2 表示传超长字符串
                 -3 表示自定义规则, 需要配合fuzz_content使用
                """

                if j.get("code") == -1:
                    info = "删除此参数"
                elif j.get("code") == 0:
                    app[j["key"]] = ""
                    info = "参数不传内容"
                elif j.get("code") == -2:
                    info = "超长字符串"
                    app[j["key"]] = self.__max_text()
                elif j.get("code") == -3:
                    info = j.get("name")
                    app[j["key"]] = j.get("value")
                else:
                    app[j["key"]] = j["value"]
                    info = "参数正确"
                app["info"] = j["key"] + info
                d1.append(app)
            d2.append(d1)
        return d2