Ejemplo n.º 1
0
 def test_main(self):
     events = main()
     tests = [schema_test_required, schema_test_all, schema_test_types]
     for test in tests:
         with self.subTest(test=test):
             result = test(events)
             self.assertTrue(result)
Ejemplo n.º 2
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']
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.calendar_page,
                            status=200,
                            body=self.calendar_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_one_uri,
                            status=200,
                            body=self.event_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_two_uri,
                            status=200,
                            body=self.event_page_content)
     events = main()
     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)
Ejemplo n.º 3
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']
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.calendar_page,
                            status=200,
                            body=self.calendar_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_one_uri,
                            status=200,
                            body=self.event_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_two_uri,
                            status=200,
                            body=self.event_page_content)
     events = main()
     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)
Ejemplo n.º 4
0
 def test_events_schema_timezone_type(self):
     '''
     Tests if the timezone event field is 'America/New_York'
     '''
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.calendar_page,
                            status=200,
                            body=self.calendar_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_one_uri,
                            status=200,
                            body=self.event_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_two_uri,
                            status=200,
                            body=self.event_page_content)
     events = main()
     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)
Ejemplo n.º 5
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']
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.calendar_page,
                            status=200,
                            body=self.calendar_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_one_uri,
                            status=200,
                            body=self.event_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_two_uri,
                            status=200,
                            body=self.event_page_content)
     events = main()
     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)
Ejemplo n.º 6
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']
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.calendar_page,
                            status=200,
                            body=self.calendar_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_one_uri,
                            status=200,
                            body=self.event_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_two_uri,
                            status=200,
                            body=self.event_page_content)
     events = main()
     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)
Ejemplo n.º 7
0
 def test_events_schema_event_cost_type(self):
     '''
     Tests if the event cost is a string of digits
     '''
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.calendar_page,
                            status=200,
                            body=self.calendar_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_one_uri,
                            status=200,
                            body=self.event_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_two_uri,
                            status=200,
                            body=self.event_page_content)
     events = main()
     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)
Ejemplo n.º 8
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'
     ]
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.calendar_page,
                            status=200,
                            body=self.calendar_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_one_uri,
                            status=200,
                            body=self.event_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_two_uri,
                            status=200,
                            body=self.event_page_content)
     events = main()
     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)
Ejemplo n.º 9
0
 def test_events_schema(self):
     '''
     Tests if all of the event fields conform in name to the schema.
     '''
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.calendar_page,
                            status=200,
                            body=self.calendar_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_one_uri,
                            status=200,
                            body=self.event_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_two_uri,
                            status=200,
                            body=self.event_page_content)
     events = main()
     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)
Ejemplo n.º 10
0
 def test_events_schema_required_fields(self):
     '''
     Tests if the required events fields are present.
     '''
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.calendar_page,
                            status=200,
                            body=self.calendar_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_one_uri,
                            status=200,
                            body=self.event_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_two_uri,
                            status=200,
                            body=self.event_page_content)
     events = main()
     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)
Ejemplo n.º 11
0
 def test_main(self):
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.calendar_page,
                            status=200,
                            body=self.calendar_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_one_uri,
                            status=200,
                            body=self.event_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_two_uri,
                            status=200,
                            body=self.event_page_content)
     result = main()
     expected = main_expected
     self.assertEqual(result, expected)
Ejemplo n.º 12
0
 def test_events_schema_phone_type(self):
     '''
     Tests if the phone number string is formatted like:  "+1-326-437-9663"
     '''
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.calendar_page,
                            status=200,
                            body=self.calendar_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_one_uri,
                            status=200,
                            body=self.event_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_two_uri,
                            status=200,
                            body=self.event_page_content)
     events = main()
     for event in events:
         for k in event:
             if k == 'Event Phone':
                 val = event[k]
                 result = is_phonenumber_valid(val)
                 self.assertTrue(result)
Ejemplo n.º 13
0
 def test_events_schema_currency_position_type(self):
     '''
     Tests if the Event Currency Position is 'prefix', 'suffix', or ''
     '''
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.calendar_page,
                            status=200,
                            body=self.calendar_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_one_uri,
                            status=200,
                            body=self.event_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_two_uri,
                            status=200,
                            body=self.event_page_content)
     events = main()
     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)
Ejemplo n.º 14
0
 def test_events_schema_currency_symbol_type(self):
     '''
     Tests if the currency symbol is a dollar sign
     '''
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.calendar_page,
                            status=200,
                            body=self.calendar_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_one_uri,
                            status=200,
                            body=self.event_page_content)
     httpretty.register_uri(method=httpretty.GET,
                            uri=self.event_two_uri,
                            status=200,
                            body=self.event_page_content)
     events = main()
     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)