コード例 #1
0
 def test_events_schema_phone_type(self):
     '''
     Tests if the phone number string is formatted like:  "+1-326-437-9663"
     '''
     events = schematize_events(page_two_uri_event_items)
     for event in events:
         for k in event:
             if k == 'Event Phone':
                 val = event[k]
                 result = is_phonenumber_valid(val)
                 self.assertTrue(result)
コード例 #2
0
 def test_events_schema_currency_symbol_type(self):
     '''
     Tests if the currency symbol is a dollar sign
     '''
     events = schematize_events(page_two_uri_event_items)
     vals = []
     for event in events:
         for k in event:
             if k == 'Event Currency Symbol':
                 vals.append(event[k])
     result = all([x == '$' for x in vals])
     self.assertTrue(result)
コード例 #3
0
 def test_events_schema_currency_position_type(self):
     '''
     Tests if the Event Currency Position is 'prefix', 'suffix', or ''
     '''
     events = schematize_events(page_two_uri_event_items)
     for event in events:
         for k in event:
             if k == 'Event Currency Position':
                 val = event[k]
                 expected_vals = ['prefix', 'suffix', '']
                 result = val in expected_vals
                 self.assertTrue(result)
コード例 #4
0
 def test_events_schema_timezone_type(self):
     '''
     Tests if the timezone event field is 'America/New_York'
     '''
     events = schematize_events(page_two_uri_event_items)
     vals = []
     for event in events:
         for k in event:
             if k == 'Timezone':
                 val = event[k]
                 vals.append(val)
     result = all(x == 'America/New_York' for x in vals)
     self.assertTrue(result)
コード例 #5
0
 def test_events_schema_event_cost_type(self):
     '''
     Tests if the event cost is a string of digits
     '''
     events = schematize_events(page_two_uri_event_items)
     vals = []
     for event in events:
         for k in event:
             if k == 'Event Cost':
                 val = event[k]
                 vals.append(val)
     #empty strings are "falsy"
     result = all(x.isdigit() or not x for x in vals)
     self.assertTrue(result)
コード例 #6
0
 def test_events_schema_required_fields(self):
     '''
     Tests if the required events fields are present.
     '''
     events = schematize_events(page_two_uri_event_items)
     keys = set().union(*(d.keys() for d in events))
     schema = {
         'Event Name', 'Event Description', 'Event Start Date',
         'Event Start Time', 'Event End Date', 'Event End Time', 'Timezone',
         'All Day Event', 'Event Venue Name', 'Event Organizers',
         'Event Cost', 'Event Currency Symbol', 'Event Category',
         'Event Website'
     }
     result = schema.issubset(keys)
     self.assertTrue(result)
コード例 #7
0
 def test_events_schema_url_type(self):
     '''
     Tests if the event website and event featured image fields contain strings
     that pass Django's test as urls
     '''
     url = ['Event Website', 'Event Featured Image']
     events = schematize_events(page_two_uri_event_items)
     vals = []
     for event in events:
         for k in event:
             if k in url:
                 val = event[k]
                 vals.append(val)
     result = all([re.match(url_regex, x) for x in vals])
     self.assertTrue(result)
コード例 #8
0
 def test_events_schema_string_type(self):
     '''
     Tests if the str and comma delim event field types are strings.
     '''
     comma_delimited = [
         'Event Venue Name', 'Event Organizers', 'Event Category',
         'Event Tags'
     ]
     string = ['Event Description', 'Event Excerpt', 'Event Name']
     events = schematize_events(page_two_uri_event_items)
     vals = []
     for event in events:
         for k in event:
             if k in string or k in comma_delimited:
                 val = event[k]
                 vals.append(val)
     result = all([isinstance(x, str) for x in vals])
     self.assertTrue(result)
コード例 #9
0
 def test_events_schema_bool_type(self):
     '''
     Tests if the boolean type event fields are bool
     '''
     booleans = [
         'All Day Event', 'Hide from Event Listings',
         'Sticky in Month View', 'Event Show Map Link', 'Event Show Map',
         'Allow Comments', 'Allow Trackbacks and Pingbacks'
     ]
     events = schematize_events(page_two_uri_event_items)
     vals = []
     for event in events:
         for k in event:
             if k in booleans:
                 val = event[k]
                 vals.append(val)
     result = all([isinstance(x, bool) for x in vals])
     self.assertTrue(result)
コード例 #10
0
 def test_events_schema_date_type(self):
     '''
     Tests if the event start/end date fields are "%Y-%m-%d" 
     Examples:  '1966-01-01' or '1965-12-31'
     '''
     date = ['Event Start Date', 'Event End Date']
     events = schematize_events(page_two_uri_event_items)
     vals = []
     for event in events:
         for k in event:
             if k in date:
                 val = event[k]
                 vals.append(val)
     try:
         result = [datetime.strptime(x, "%Y-%m-%d") for x in vals]
     except ValueError:
         result = None
         raise EventDateFormatError
     self.assertIsNotNone(result)
コード例 #11
0
 def test_events_schema(self):
     '''
     Tests if all of the event fields conform in name to the schema.
     '''
     events = schematize_events(page_two_uri_event_items)
     keys = set().union(*(d.keys() for d in events))
     schema = {
         'Do Not Import', 'Event Name', 'Event Description',
         'Event Excerpt', 'Event Start Date', 'Event Start Time',
         'Event End Date', 'Event End Time', 'Timezone', 'All Day Event',
         'Hide Event From Event Listings', 'Event Sticky in Month View',
         'Feature Event', 'Event Venue Name', 'Event Organizers',
         'Event Show Map Link', 'Event Show Map', 'Event Cost',
         'Event Currency Symbol', 'Event Currency Position',
         'Event Category', 'Event Tags', 'Event Website',
         'Event Featured Image', 'Allow Comments',
         'Event Allow Trackbacks and Pingbacks'
     }
     result = keys.issubset(schema)
     self.assertTrue(result)
コード例 #12
0
 def test_events_schema_time_type(self):
     '''
     Tests if the Event Start Time and Event End Time fields follow
     the "%H:%M:%S" format. Examples: '21:30:00' or '00:50:00'
     '''
     time = ['Event Start Time', 'Event End Time']
     events = schematize_events(page_two_uri_event_items)
     vals = []
     for event in events:
         for k in event:
             if k in time:
                 val = event[k]
                 vals.append(val)
     try:
         result = [
             datetime.strptime(x, "%H:%M:%S") for x in vals if x != ''
         ]
     except ValueError:
         result = None
         raise EventTimeFormatError
     self.assertIsNotNone(result)
コード例 #13
0
 def test_schematize_events(self):
     result = schematize_events(page_two_uri_event_items)
     expected = schematized_page_two_event_items
     self.assertCountEqual(result, expected)