class TestAtlasSource(unittest.TestCase): def setUp(self): self.kwargs = {"requested": 5, "value": "test", "type": "country"} self.source = AtlasSource(**self.kwargs) def test_setting_type(self): self.assertRaises( MalFormattedSource, lambda: setattr(self.source, "type", "testing") ) def test_clean(self): self.assertEqual(self.source.clean(), None) self.source.type = "msm" self.source.value = None self.assertRaises( MalFormattedSource, lambda: self.source.clean() ) self.source.value = "test" self.source.requested = None self.assertRaises( MalFormattedSource, lambda: self.source.clean() ) def test_build_api_struct(self): self.assertEqual(self.source.build_api_struct(), self.kwargs) validate(self.source.build_api_struct(), probes_create_schema)
def main(): our_as_with_own_probe = '7922' client_as_list = ('42610', '3320', '3215') # '2856') source_list = [] # add Philipp's probe as a source source = AtlasSource(type="probes", value='11090', requested=1) source_list.append(source) # add British one separate for AS 2856 # because the one it uses doesn't work source = AtlasSource(type="probes", value='14274', requested=1) source_list.append(source) # the rest for cli_as in client_as_list: source = AtlasSource(type="asn", value="AS" + cli_as, requested=1) source_list.append(source) tor_default_port = 9001 # useless now because not doing TCP traceroutes anymore limit = 85 tr_list = [] count = 0 # Need to do traceroutes to all IPs for ip_line in sys.stdin: ip_str = ip_line.rstrip() traceroute = Traceroute(target=ip_str, af=4, timeout=4000, description='Traceroute from client AS to ' + ip_str, protocol="UDP", resolve_on_probe=False, packets=3, size=48, first_hop=1, max_hops=32, port=tor_default_port, paris=16, destination_option_size=0, hop_by_hop_option_size=0, dont_fragment=False, skip_dns_check=False) tr_list.append(traceroute) count += 1 create_measurement(tr_list, source_list) # reset the tr_list tr_list = [] if count == limit: # sleep for 15 minutes # 60 seconds * 15 time.sleep(900) # reset the count count = 0
def test_build_api_struct_with_tags(self): kwargs = { "requested": 5, "value": "test", "type": "msm", "tags": {"include": ["one", "two"], "exclude": ["one", "two"]} } source = AtlasSource(**kwargs) self.assertEqual(source.build_api_struct(), kwargs) validate(source.build_api_struct(), probes_create_schema)
def send_ripe_measurement_request(website, ATLAS_API_KEY): traceroute1 = Traceroute( af=4, target=website, description="testing", protocol="ICMP", ) source1 = AtlasSource( type="country", value="CA", #, canada "CA", "PL", "AU", "AR"], requested=3, tags={"include": ["system-ipv4-works"]}) source2 = AtlasSource( type="country", value="ZA", #, South Africa "CA", "PL", "AU", "AR"], requested=3, tags={"include": ["system-ipv4-works"]}) source3 = AtlasSource( type="country", value="DE", #, Germany "CA", "PL", "AU", "AR"], requested=3, tags={"include": ["system-ipv4-works"]}) source4 = AtlasSource( type="country", value="NG", #, Nigeria "CA", "PL", "AU", "AR"], requested=3, tags={"include": ["system-ipv4-works"]}) source5 = AtlasSource( type="country", value="BR", #, Brazil "CA", "PL", "AU", "AR"], requested=3, tags={"include": ["system-ipv4-works"]}) atlas_request = AtlasCreateRequest( start_time=datetime.utcnow(), key=ATLAS_API_KEY, measurements=[traceroute1], sources=[source1, source2, source3, source4, source5], is_oneoff=True) is_success, response = atlas_request.create() result_id = [] if is_success: result_id = response['measurements'] print("Measurement for", website, "sent. Result ID is", result_id[0]) return result_id else: print("Measurement not successful") return []
def create_measurement(cc): """ Creates DNS and Traceroute measurements for given country code @param cc: Two characters (ISO) country code @type cc: str @return: tuple of measurement ids @rtype: tuple """ global API_CREATE_KEY traceroute = Traceroute(af=4, target="193.0.14.129", protocol="ICMP", description="Traceroute from %s to K Root" % cc) dns = Dns(af=4, target="193.0.14.129", query_argument="com.", query_type="NS", query_class="IN", description="DNS Response time fromt %s to K Root" % cc) source = AtlasSource(value=cc, requested=50, type="country", action="add") request = AtlasCreateRequest(start_time=datetime.utcnow(), key=API_CREATE_KEY, measurements=[traceroute, dns], sources=[source], is_oneoff=True) (is_success, response) = request.create() if is_success: print("- Created measurement for %s" % cc) return list(response['measurements']) else: print("- Failed to create measurement for %s: %s" % (cc, response)) return None
def submit_traceroute(asn): traceroute_time = int(time.time()) traceroute = Traceroute( af=4, target="208.45.214.0", description="{}_{}".format(asn, traceroute_time), protocol="ICMP", ) source = AtlasSource(type="asn", value=asn, requested=1) atlas_request = AtlasCreateRequest(start_time=datetime.datetime.utcnow(), key=ATLAS_API_KEY, measurements=[traceroute], sources=[source], is_oneoff=True) (is_success, response) = atlas_request.create() if not is_success: return None, traceroute_time measurement_id = response["measurements"][0] log_message( "Measurement ID of {} for ongoing traceroute".format(measurement_id)) return measurement_id, traceroute_time
def startTraceroute(self, query_params): # localhost:8080/api/v1/traceroute?dest=X.X.X.X&desc=description&proto=TCP dest = query_params["dest"][0] desc = query_params["desc"][0] proto = query_params["proto"][0] traceroute = Traceroute( af=4, target=dest, description=desc, protocol=proto, ) source = AtlasSource(type="area", value="WW", requested=5, tags={"include": ["system-ipv4-works"]}) start_time = datetime.utcnow() + timedelta(0, 2) atlas_request = AtlasCreateRequest(start_time=start_time, key=ATLAS_API_KEY, measurements=[traceroute], sources=[source], is_oneoff=True) (is_success, response) = atlas_request.create() print(response) print("Success ", is_success) self.wfile.write(json.dumps(response, ensure_ascii=False).encode())
def create_ripe_measurement(prefix_list): measurement_count = 0 measurement_limit = 10 ATLAS_API_KEY = "secret" for prefix, ip_list in prefix_list.iteritems(): for ip in ip_list: ipAddr = ip count = 0 descr = "Prefix: " + prefix + "Flapped " + str(count) + " times" ping = Ping(af=4, target=ipAddr, description=descr) traceroute = Traceroute( af=4, target=ipAddr, description=descr, protocol="ICMP", ) source = AtlasSource(type="area", value="WW", requested=5) atlas_request = AtlasCreateRequest( start_time=datetime.utcnow(), key=ATLAS_API_KEY, measurements=[ping, traceroute], sources=[source], is_oneoff=True ) (is_success, response) = atlas_request.create() measurement_count += 1 if measurement_count > measurement_limit: break
def create_source(): """Selects the RIPE Atlas probes for the measurements.""" # TO DO: Continent filter probe_selector = None requested = 0 value = "WW" probe_selector = "area" if config['RIPE']['probes'] is not None: if config['RIPE']['probes'] == 'all': requested = 10000 else: requested = int(config['RIPE']['probes']) if config['RIPE']['probe_ids'] is not None: probe_selector = 'probes' value = [] for probe_id in config['RIPE']['probe_ids'].split(','): value.append(probe_id.strip()) elif config['RIPE']['as_nr'] is not None: probe_selector = 'asn' value = int(config['RIPE']['as_nr']) elif config['RIPE']['country'] is not None: probe_selector = 'country' value = config['RIPE']['country'] #print(requested, probe_selector, value) return AtlasSource(requested=requested, type=probe_selector, value=value)
def create_measurements(probes, target): ''' Create two new ICMP traceroute measurements, one for the IPv4 target address and one for the IPv6. ''' probes.remove(target['id']) # Don't waste credits tracerouting to itself num_probes = len(probes) sources = AtlasSource( type='probes', value=','.join(str(x) for x in random.sample(probes, num_probes)), requested=num_probes) tr4 = Traceroute(af=4, target=target['address_v4'], description='Transient tr4 test', protocol='ICMP') tr6 = Traceroute(af=6, target=target['address_v6'], description='Transient tr6 test', protocol='ICMP') atlas_request = AtlasCreateRequest(key=API_KEY, measurements=[tr4, tr6], sources=[sources], is_oneoff=True) if dry_run: response = False else: response = atlas_request.create() return response
def _create_measurement_impl(self, target_probe): args = self._args log = self._log probe = target_probe if 'address_v4' not in probe: log.error('probe has no ipv4 addr') return None target_id = probe['id'] target_ip = probe['address_v4'] log.notice('Creating measurement to probe', target_id, target_ip) desc = '{} {} to {}'.format(args.test_name_prefix, args.src_probe, target_id) ping = Ping(af=4, target=target_ip, description=desc) source = AtlasSource(type='probes', value='{}'.format(args.src_probe), requested=1) req = AtlasCreateRequest(start_time=datetime.utcnow(), key=args.api, measurements=[ping], sources=[source], is_oneoff=True) is_success, resp = req.create() if not is_success: log.warn('Error creating measurement:', str(resp)) return None else: msm_id = resp['measurements'][0] return msm_id log(is_success, resp)
def main(): try: target = sys.argv[1] except: print('Please provide a host to traceroute') exit(1) probes = load_json() sources = AtlasSource( type='probes', value=','.join(str(x) for x in random.sample(probes, num_probes)), requested=num_probes) tr4 = Traceroute(af=4, target=target, description='Transient tr4 test', protocol='ICMP') tr6 = Traceroute(af=6, target=target, description='Transient tr6 test', protocol='ICMP') atlas_request = AtlasCreateRequest(key=API_KEY, measurements=[tr4, tr6], sources=[sources], is_oneoff=True) response = atlas_request.create() print(response)
def create_source(msm_type, value, num_of_probes): source = AtlasSource( type=msm_type, value=value, requested=num_of_probes ) return source
def create(self): creation_class = self.CREATION_CLASSES[self.arguments.type] return AtlasCreateRequest( server=conf["ripe-ncc"]["endpoint"].replace("https://", ""), key=self.arguments.auth, measurements=[creation_class(**self._get_measurement_kwargs())], sources=[AtlasSource(**self._get_source_kwargs())], is_oneoff=self._is_oneoff).create()
def getTracerouteResults(self, query_params): dest = query_params["dest"][0] myresults = getMyResults() id = 0 for result in myresults["results"]: target = result["target"] if target == dest: id = result["id"] if id == 0: # start a new measurement traceroute = Traceroute( af=4, target=dest, description="auto traceroute to %s" % dest, protocol="TCP", ) source = AtlasSource(type="area", value="WW", requested=5, tags={"include": ["system-ipv4-works"]}) start_time = datetime.utcnow() + timedelta(0, 1) atlas_request = AtlasCreateRequest(start_time=start_time, key=ATLAS_API_KEY, measurements=[traceroute], sources=[source], is_oneoff=True) (is_success, response) = atlas_request.create() if is_success: id = response['measurements'][0] # {'measurements': [23976423, 23976424]} print("Run traceroute back for id %d" % id) rt = RunReverseTraceroute(id) rt.start() rt.join(timeout=60) responses = get_json(id) # source = "https://atlas.ripe.net/api/v2/measurements/%d/results/"%id # responses = requests.get(source).json() # for i in responses: # dst_addr = i['dst_addr'] # i['dst_addr'] = self.getCity(dst_addr) # i['from'] = self.getCity(i['from']) # results = i['result'] # for j in results: # for k in j['result']: # if k.get('from'): # k['from'] = self.getCity(k['from']) self.wfile.write(json.dumps(responses, ensure_ascii=False).encode())
def measure(msm_spec): traceroute = Traceroute(**msm_spec['definitions']) source = AtlasSource(**msm_spec['probes']) atlas_request = AtlasCreateRequest(start_time=datetime.utcnow(), key=KEY, measurements=[traceroute], sources=[source], is_oneoff=True) (is_success, response) = atlas_request.create() return response['measurements'][0]
def oneofftrace(probes_def, dst, **kwargs): probe_list = [] if isinstance(probes_def, int): probe_list.append(probes_def) elif isinstance(probes_def, list): probe_list = probes_def else: raise ValueError( "Probes definition needs to be of type int or list, not %s" % (type(probes_def))) default_defs = { 'target': dst, 'type': 'traceroute', 'protocol': 'ICMP', 'resolve_on_probe': True, 'is_oneoff': True } defs = dict(default_defs.items() + kwargs.items()) # handle 'af' if not 'af' in defs: if ':' in dst: defs['af'] = 6 else: #default to 4 defs['af'] = 4 # handle 'descr' if not 'description' in defs: defs['description'] = 'trace to %s (IPv%d)' % (dst, defs['af']) data = { 'definitions': defs, 'probes': { 'requested': len(probe_list), 'type': 'probes', 'value': ','.join(map(str, probe_list)) } } traceroute = Traceroute(**data['definitions']) source = AtlasSource(**data['probes']) atlas_request = AtlasCreateRequest( # start_time = datetime.utcnow(), # this was generating "Measurements must have the start time in future" key=KEY, measurements=[traceroute], sources=[source], is_oneoff=True) (is_success, response) = atlas_request.create() if 'measurements' in response: return response['measurements'][0] else: print >> sys.stderr, response
def submit_traceroute(asn): global PREFIX global PEERING traceroute_time = int(time.time()) prefix_no_subnet = str(PREFIX.split('/')[0]) if PEERING: split_prefix = prefix_no_subnet.split('.') prefix_no_subnet = "{}.{}.{}.1".format(split_prefix[0], split_prefix[1], split_prefix[2]) traceroute = Traceroute(af=4, target=prefix_no_subnet, description="{}_{}_{}".format( asn, traceroute_time, "{}".format(prefix_no_subnet)), protocol="ICMP", max_hops=255) source = AtlasSource( type="asn", value=str(asn), requested=1, tags={"include": ["system-ipv4-works", "system-ipv4-stable-1d"]}) atlas_request = AtlasCreateRequest(start_time=datetime.datetime.utcnow(), key=ATLAS_API_KEY, measurements=[traceroute], sources=[source], is_oneoff=True) (is_success, response) = atlas_request.create() if not is_success: response = str(response) log_message("Traceroute failed: {}".format(response)) # Handle probe not found in ASN if "Your selected ASN is not covered by our network." in response: return -1, traceroute_time # Handle all other cases else: return None, traceroute_time measurement_id = response["measurements"][0] log_message( "Measurement ID of {} for ongoing traceroute".format(measurement_id)) return measurement_id, traceroute_time
def create(self): creation_class = self.CREATION_CLASSES[self._type] return AtlasCreateRequest( server=conf["ripe-ncc"]["endpoint"].replace("https://", ""), key=self.arguments.auth, user_agent=self.user_agent, measurements=[creation_class(**self._get_measurement_kwargs())], sources=[AtlasSource(**self._get_source_kwargs())], is_oneoff=self._is_oneoff, start_time = conf["specification"]["times"]["start"], stop_time = conf["specification"]["times"]["stop"] ).create()
def atlas_api_call(): #ATLAS_API_KEY = "" q = Target.objects.all().last() if (q.specification.one_off is True): traceroute = Traceroute( af=4, target=str(q.target), description=str(q.description), protocol=str(q.specification.protocol), ) else: traceroute = Traceroute( af=4, target=str(q.target), description=str(q.description), protocol=str(q.specification.protocol), interval=int(q.specification.interval), ) source = [] for i in range(0, q.probes.all().count()): l = q.probes.all()[i] #new[i]='source'+i source.append( AtlasSource(type="country", value=str(l.country), requested=int(l.number), tags={"exclude": ["system-anchor"]})) if (q.specification.one_off is True): atlas_request = AtlasCreateRequest(start_time=int(time.time()), key=ATLAS_API_KEY, measurements=[traceroute], sources=source, is_oneoff=q.specification.one_off) else: atlas_request = AtlasCreateRequest( start_time=int(time.time()), stop_time=int(time.mktime(q.specification.stop_time.timetuple())), key=ATLAS_API_KEY, measurements=[traceroute], sources=source, is_oneoff=q.specification.one_off) (is_success, response) = atlas_request.create() print response return response
def create_measurement(self, kwargs): ''' Creates the request for a measurement to ripe. Input: a) kwargs: The user input arguments in a dictionary. Output: a) response: The response from ripe. ''' default_defs = { 'target': 'www.inspire.edu.gr', 'type': 'traceroute', 'protocol': 'ICMP', 'resolve_on_probe': True, 'af': 4, 'description': 'traIXroute (IPv4)' } default_probes = {'type': 'probes', 'value': '23385', 'requested': 1} default_defs.update(kwargs[0].items()) default_probes.update(kwargs[1].items()) if (default_defs['type'] != 'traceroute' or default_defs['af'] != 4): print( 'TraIXroute only supports Traceroute and IPv4 measurements. Exiting.' ) traceroute = Traceroute(**default_defs) source = AtlasSource(**default_probes) atlas_request = AtlasCreateRequest(start_time=datetime.utcnow(), key=self.ripe_key, measurements=[traceroute], sources=[source], is_oneoff=True) (is_success, response) = atlas_request.create() if (is_success): print( 'Please wait for ripe to complete the measurements and run traIXroute again with: ripe -r \'{\"msm_id\":' + str(response['measurements'][0]) + '}\'') else: print( 'Please revise the arguments you have given. Ripe does not accept these arguments or it may be unavailable at this time.' ) sys.exit(0)
def test_clean(self): # all ok kwargs = {"requested": 5, "value": "test", "type": "msm"} source = AtlasSource(**kwargs) self.assertEqual(source.clean(), None) # value missing source.value = None self.assertRaises( MalFormattedSource, lambda: source.clean() ) # type missing kwargs = {"requested": 5, "value": "test"} self.assertRaises( MalFormattedSource, lambda: AtlasSource(**kwargs).clean() ) # requested missing source.value = "test" source.requested = None self.assertRaises( MalFormattedSource, lambda: source.clean() )
def setUp(self): self.create_source = AtlasSource( **{"type": "area", "value": "WW", "requested": 3} ) self.measurement = Ping(**{ "target": "testing", "af": 6, "description": "testing" }) self.request = AtlasCreateRequest(**{ "start_time": datetime(2015, 10, 16), "stop_time": 1445040000, "key": "path_to_key", "measurements": [self.measurement], "sources": [self.create_source], "is_oneoff": True, })
def run_measurement(tgt): m = [ Ping(af=4, target=addr, description="ROV tgt %d" % mid) for (mid, addr) in enumerate(tgt) ] source = AtlasSource(type="area", value="WW", requested=1000) atlas_request = AtlasCreateRequest(start_time=datetime.utcnow(), key=ATLAS_API_KEY, measurements=m, sources=[source], is_oneoff=True) (is_success, response) = atlas_request.create() print "tgt=%s is_success=%s response=%s" % (str(tgt), str(is_success), str(response))
def main(): # Handle command-line arguments exit_as_set_pickle_fname = sys.argv[1] with open(exit_as_set_pickle_fname, 'rb') as f: exit_as_set = pickle.load(f) source_list = [] for asn in exit_as_set: source = AtlasSource(type='asn', value='AS' + str(asn), requested=1) source_list.append(source) #print len(source_list) #print len(exit_as_set) #exit() the_port = 53 tr_list = [] for ip_line in sys.stdin: the_ip = ip_line.rstrip() traceroute = Traceroute( target=the_ip, af=4, timeout=4000, description='UDP Traceroute from exit ASes to ' + the_ip, protocol='UDP', resolve_on_probe=False, packets=3, size=48, first_hop=1, max_hops=32, port=the_port, paris=16, destination_option_size=0, hop_by_hop_option_size=0, dont_fragment=False, skip_dns_check=False) tr_list.append(traceroute) #print tr_list create_measurement(tr_list, source_list)
def measure_from_template( template_file, template_vars ): env = Environment() template = env.get_template( template_file ) msm_spec = template.render(**{template_vars}) traceroute = Traceroute( ** msm_spec['definitions'] ) source = AtlasSource( ** msm_spec['probes'] ) atlas_request = AtlasCreateRequest( start_time = datetime.utcnow(), key = KEY, measurements = [traceroute], sources = [source], is_oneoff = True ) (is_success, response) = atlas_request.create() return response['measurements'][0]
def submit_traceroute(asn, probe): global PREFIX traceroute_time = int(time.time()) prefix_no_subnet = str(PREFIX.split('/')[0]) o1, o2, o3, o4 = prefix_no_subnet.split('.') prefix_loopback = "{}.{}.{}.1".format(o1, o2, o3) traceroute = Traceroute(af=4, target=prefix_loopback, description="{}_{}_{}".format( asn, traceroute_time, "{}".format(prefix_no_subnet)), protocol="TCP", port=39876, max_hops=60) source = AtlasSource(type="probes", value=str(probe), requested=1) atlas_request = AtlasCreateRequest(start_time=datetime.datetime.utcnow(), key=ATLAS_API_KEY, measurements=[traceroute], sources=[source], is_oneoff=True) (is_success, response) = atlas_request.create() if not is_success: response = str(response) log_message("Traceroute failed: {}".format(response)) # Handle probe not found in ASN if "Your selected ASN is not covered by our network." in response: return -1, traceroute_time # Handle all other cases else: return None, traceroute_time measurement_id = response["measurements"][0] log_message( "Measurement ID of {} for ongoing traceroute".format(measurement_id)) return measurement_id, traceroute_time
def measure(port, hostname, afs): for af in afs: if (hostname, port, af) in msm_state: msm_state[(hostname, port, af)]['state'] = 'active' else: # the mapping between API and cousteau drives me nuts! msm_def['definitions'][0]['port'] = port msm_def['definitions'][0]['target'] = hostname msm_def['definitions'][0]['af'] = af traceroute = Traceroute(**msm_def['definitions'][0]) source = AtlasSource(**msm_def['probes'][0]) start = int(time.time()) + 60 atlas_request = AtlasCreateRequest(key=KEY, measurements=[traceroute], sources=[source], start_time=start) (is_success, response) = atlas_request.create() msm_id = None if is_success: msm_id = response['measurements'][0] json.dump( { 'hostname': hostname, 'port': port, 'af': af, 'action': 'started', 'ts': start, 'msm_id': msm_id }, log_fh) log_fh.write("\n") msm_state[(hostname, port, af)] = { 'msm_id': msm_id, 'state': 'new' } print("new msm created for %s %s %s (id: %s)" % (hostname, port, af, msm_id), file=sys.stderr) else: print("msm start failed for %s %s %s: %s" % (hostname, port, af, response), file=sys.stderr)
def measure_ping_and_dns(api_key, domains, probe_type, probe_value, probe_requested, probe_tags): # Todo: Make this a parameter? retrieve_measurements_timeout = 5 # Seconds # Create the probe source probe_source = [ AtlasSource(type=probe_type, value=probe_value, requested=int(probe_requested), tags=probe_tags) ] ## Get the data # Create ping measurements logger.info('Creating ping measurements') ping_measurements = [ Ping(af=4, target=domain, description='Ping to ' + domain) for domain in domains ] success, ping_request_ids, ping_results = measurements.run_measurements( api_key, ping_measurements, probe_source, retrieve_measurements_timeout) # Create subsequent dns measurements logger.info('Creating dns measurements') dns_measurements = [ Dns(af=4, query_class='IN', query_argument=domain, query_type='A', use_probe_resolver=True, include_abuf=True, retry=5, description='DNS A request for ' + domain) for domain in domains ] success, dns_request_ids, dns_results = measurements.run_measurements( api_key, dns_measurements, probe_source, retrieve_measurements_timeout) return ping_request_ids, ping_results, dns_request_ids, dns_results
def schedule_measurement(dest, probes, tag, stage): msm_status = defaultdict(list) traceroute = Traceroute( af=4, target=dest, description="%s_%s: Traceroute to %s" % (tag, stage, dest), protocol="ICMP", is_public=True, paris=16, can_visualize=False, ) trace_origin = AtlasSource(requested=len(probes), type="probes", value=",".join(probes)) try: atlas_req = AtlasCreateRequest(start_time=datetime.utcnow(), key=authkey, measurements=[traceroute], sources=[trace_origin], is_oneoff=True) (is_success, response) = atlas_req.create() # Check if we got a positive result if is_success: print response for m in response['measurements']: msm_status['list'].append(m) else: msm_status['failed'].append(dest) # This sleep is important to give time to the scheduled measurements to complete before trying more. time.sleep(3) except (urllib2.HTTPError, urllib2.URLError) as e: # Other kind of error msm_status['failed'].append(dest) print "Fatal Error: %s " % e return msm_status
def test_set_tags(self): # all ok kwargs = { "requested": 5, "value": "test", "type": "msm", "tags": {"include": ["one", "two"], "exclude": ["one", "two"]}} source = AtlasSource(**kwargs) self.assertEqual(source.clean(), None) self.assertEqual( source.tags, {"include": ["one", "two"], "exclude": ["one", "two"]} ) # include missing kwargs = { "requested": 5, "value": "test", "type": "msm", "tags": {"exclude": ["one", "two"]} } source = AtlasSource(**kwargs) self.assertEqual(source.clean(), None) # exclude missing kwargs = { "requested": 5, "value": "test", "type": "msm", "tags": {"include": ["one", "two"]} } source = AtlasSource(**kwargs) self.assertEqual(source.clean(), None) # invalid tag type kwargs = { "requested": 5, "value": "test", "type": "msm", "tags": {"include": ["one", 2], "exclude": ["one", "two"]} } self.assertRaises(MalFormattedSource, lambda: AtlasSource(**kwargs)) # unknown element kwargs = { "requested": 5, "value": "test", "type": "msm", "tags": { "include": ["one", 2], "exclude": ["one", "two"], "unknown": "?" } } self.assertRaises(MalFormattedSource, lambda: AtlasSource(**kwargs))
def test_build_api_struct(self): kwargs = {"requested": 5, "value": "test", "type": "msm"} source = AtlasSource(**kwargs) self.assertEqual(source.build_api_struct(), kwargs) validate(source.build_api_struct(), probes_create_schema)
def setUp(self): self.kwargs = {"requested": 5, "value": "test", "type": "country"} self.source = AtlasSource(**self.kwargs)