예제 #1
0
 def test_sample_data4(self):
     result = {
         "modelversion": {
             "key1": ["value1"],
             "key2": "value2"
         },
         "vorgangsID":
         "1",
         "versorgungsvorschlagDatum":
         1510558834978,
         "eingangsdatum":
         1510558834978,
         "plz":
         82269,
         "vertragsteile": [
             {
                 "typ":
                 "1",
                 "beitragsDaten": {
                     "endalter": 85,
                     "brutto": 58.76,
                     "netto": 58.76,
                     "zahlungsrhythmus": "MONATLICH",
                     "plz": 86899,
                 },
                 "beginn":
                 1512082800000,
                 "lebenslang":
                 "True",
                 "ueberschussverwendung": {
                     "ueberschussverwendung": "2",
                     "indexoption": "3",
                 },
                 "deckung": [{
                     "typ": "2",
                     "art": "1",
                     "leistung": {
                         "value": 7500242424.0,
                         "einheit": "2"
                     },
                     "leistungsRhythmus": "1",
                 }],
                 "zuschlagNachlass": [],
             },
             {
                 "typ": "1",
                 "beitragsDaten": {
                     "endalter": 85,
                     "brutto": 0.6,
                     "netto": 0.6,
                     "zahlungsrhythmus": "1",
                 },
                 "zuschlagNachlass": [],
             },
         ],
     }
     self.assertEqual(
         result,
         nested_update(
             self.sample_data4,
             "modelversion",
             {
                 "key1": ["value1"],
                 "key2": "value2"
             },
         ),
     )
f_url = open(URL_FILE, 'r')
URL_DATA = f_url.readline().rstrip()
f_url.close()

f_result = open(RESULT_FILE, 'r')
RESULT_DATA = json.loads(f_result.read())
f_result.close()

req = requests.get(URL_DATA)
compare_actual = json.loads(req.text)
compare_expected = RESULT_DATA

if "TEST_IGNORE_SCORE" in os.environ:
	if os.environ["TEST_IGNORE_SCORE"] != "":
		compare_actual = nested_update(compare_actual, key='score', value=1.0)
		compare_expected = nested_update(compare_expected, key='score', value=1.0)

try:
	assert compare_actual == compare_expected
except AssertionError as err:
	print("=== BEGIN EXPECTED ===")
	print(compare_expected)
	print("=== END EXPECTED ===")
	
	print("=== BEGIN ACTUAL ===")
	print(compare_actual)
	print("=== END ACTUAL ===")
	if "AUTOTEST" in os.environ:
		if os.environ["AUTOTEST"] != "":
			raise err
예제 #3
0
                    json.dumps({
                        "command": "status",
                        "success": True,
                        "response": "connected"
                    }))
            elif command == "get":
                print(
                    json.dumps({
                        "command": "camera get",
                        "success": True,
                        "response": cam.get_info(profile)
                    }))
            elif command == "set":
                config = cam.get_info(profile)

                nested_update(config, key=setting, value=value)
                response = cam.set_info(profile, config)
                new_config = cam.get_info(profile)
                if nested_lookup(setting, config)[0] == nested_lookup(
                        setting, new_config)[0]:
                    print(
                        json.dumps({
                            "command": "camera set",
                            "success": True,
                            "response": response,
                            "value": value
                        }))
                else:
                    print(
                        json.dumps({
                            "command": "camera set",
예제 #4
0
    def validate_body(self):
        """
        Method for validating the request body.

        """
        retrieve = ["capec", "cpe", "cves", "cwe", "via4"]

        sort_dir = ["ASC", "DESC"]

        required_keys = ["retrieve", "dict_filter"]

        optional_keys = ["sort", "limit", "skip", "query_filter", "sort_dir"]

        date_keys = ["Published", "Modified", "last-modified"]

        if self.body is None or len(self.body) == 0:
            return (
                False,
                "Please send a proper request with a json formatted like in the documentation.",
            )

        if not all(key.lower() in self.body for key in required_keys):
            return False, "Request is missing one or more required keys!"

        # convert date_keys from string to datetime objects
        if "dict_filter" in self.body:
            for key in date_keys:
                convert_values = nested_lookup(key, self.body["dict_filter"])
                if len(convert_values) != 0:
                    converted_val = self.convert_datetimestring_to_datetime(
                        convert_values[0])
                    if converted_val:
                        nested_update(
                            document=self.body["dict_filter"],
                            key=key,
                            value=converted_val,
                        )
                    else:
                        return (
                            False,
                            "Could not convert provided date string to valid datetime object; currently supported "
                            "formats are: {}".format(date_time_formats),
                        )

        if not self.body["retrieve"].lower() in retrieve:
            return False, "Unable to retrieve from specified data source!"

        if "sort_dir" in self.body.keys():
            if not self.body["sort_dir"] in sort_dir:
                return (
                    False,
                    "Specified sorting direction not possible; possible options are: {}!"
                    .format(sort_dir),
                )

        all_keys = retrieve + required_keys + optional_keys

        if not all(key in all_keys for key in self.body):
            return False, "Request contains unknown keys!"

        if "skip" in self.body:
            try:
                self.body["skip"] = int(self.body["skip"])
            except ValueError:
                return False, "Skip parameter is not a integer!"

        if "limit" in self.body:
            try:
                self.body["limit"] = int(self.body["limit"])
            except ValueError:
                return False, "Limit parameter is not a integer!"

        return True, "Ok"