Пример #1
0
    def test_generate(self):
        GenerateSite().generate_site()
        assert True

        # This fails on travis, we probably need better reporting to see what is the actual difference
        # as I cannot see it. Unless it is only the file_date
        files = [
            'html/v/yougottalovefrontend-2016/vitaly-friedman-cutting-edge-responsive-web-design.json',
            'html/p/zohar-babin.json',
        ]
        for result_file in files:
            expected_file = 'samples/' + os.path.basename(result_file)
            #sys.stderr.write(result_file)
            #sys.stderr.write("\n")
            #sys.stderr.write(expected_file)
            #sys.stderr.write("\n")
            # read both files
            result = read_json(result_file)
            expected = read_json(expected_file)
            if 'file_date' in expected:
                del (expected['file_date'])
                del (result['file_date'])
            if result != expected:
                print("While testing {}\n".format(result_file))
                print("Expected: {}".format(expected))
                print("Received: {}".format(result))
            assert result == expected
Пример #2
0
 def test_locations(self, tmpdir):  # 1-5 10-16
     errors = [
         None,
         None,
         None,
         None,
         None,
         None,
         'ERROR 6: filename is not all lower case.',
         'ERROR 7: filename is not .json file.',
         'ERROR 8: filename has characters that are not accepted (a-z0-9-).',
         'ERROR 9: Invalid file name. Should contain the year "2016". In file',
         'ERROR 10: The value of city "OrlandoX" is not in our list. If this was not a typo, add it to data/locations.json. Found in',
         'ERROR 11: The value of city "Bukarest" is not in our list. If this was not a typo, add it to data/locations.json. Found in',
         'ERROR 12: The value of state "FloridaX" is not in our list. If this was not a typo, add it to data/locations.json. Found in',
         'ERROR 13: The value of country "USAX" is not in our list. If this was not a typo, add it to data/locations.json. Found in',
         'ERROR 14: Tag "blabla" is not in the list of tags found in data/tags.json. Check for typo. Add new tags if missing from our list. in file',
         'ERROR 15: Missing or empty "name" field in',
         'ERROR 16: The conference "name" should not include the year. Seen in',
         'ERROR 17: Missing or invalid "website" field in',
         'ERROR 18: The "city" field is missing. See docs/EVENTS.md. In file',
         'ERROR 19: The "state" field is missing. See docs/EVENTS.md. In file',
         'ERROR 20: The "country" field is missing. See docs/EVENTS.md. In file',
         'ERROR 21: The "location" field is missing. See docs/EVENTS.md. In file',
     ]
     print("Temp dir: ", tmpdir)
     for cnt in range(len(errors)):
         if errors[cnt] == None:
             continue
         test_dir_name = str(cnt)
         test_dir = tmpdir.mkdir(test_dir_name)
         test_dir.mkdir('events')
         tmp_dir = str(tmpdir)  # needed for Python older than 3.6 ??
         for filename in ['locations.json', 'series.json', 'tags.json']:
             shutil.copyfile(os.path.join('data', filename),
                             os.path.join(tmp_dir, test_dir_name, filename))
         for filename in os.listdir(
                 os.path.join('test_data', test_dir_name, 'events')):
             shutil.copyfile(
                 os.path.join('test_data', test_dir_name, 'events',
                              filename),
                 os.path.join(tmp_dir, test_dir_name, 'events', filename))
         os.environ['CAT_TEST'] = os.path.join(tmp_dir, test_dir_name)
         with pytest.raises(CATerror) as err:
             GenerateSite().generate_site()
         assert errors[cnt] in str(err.value)
         if cnt == 6:
             assert os.path.join(tmp_dir, test_dir_name, 'events',
                                 'Test-2016.json') in str(err.value)
         elif cnt == 7:
             assert os.path.join(tmp_dir, test_dir_name, 'events',
                                 'test-2016.txt') in str(err.value)
         elif cnt == 8:
             assert 'test_2016.json' in str(err.value)
         elif cnt == 9:
             assert os.path.join(tmp_dir, test_dir_name, 'events',
                                 'test.json') in str(err.value)
         else:
             assert os.path.join(tmp_dir, test_dir_name, 'events',
                                 'test-2016.json') in str(err.value)
Пример #3
0
 def test_locations(self):
     errors = [
         'ERROR 1: The value of city "OrlandoX" is not in our list. If this was not a typo, add it to data/locations.json. Found in',
         'ERROR 1: The value of state "FloridaX" is not in our list. If this was not a typo, add it to data/locations.json. Found in',
         'ERROR 1: The value of country "USAX" is not in our list. If this was not a typo, add it to data/locations.json. Found in',
         'ERROR 1: Tag "blabla" is not in the list of tags found in data/tags.json. Check for typo. Add new tags if missing from our list. in file',
         'ERROR 1: Missing or empty "name" field in',
         'ERROR 1: The conference "name" should not include the year. Seen in'
     ]
     for d in [1, 2, 3, 4, 5, 6]:
         for filename in ['locations.json', 'series.json', 'tags.json']:
             shutil.copyfile(os.path.join('data', filename),
                             os.path.join('test_data', str(d), filename))
         os.environ['CAT_TEST'] = os.path.join('test_data', str(d))
         with pytest.raises(SystemExit) as err:
             GenerateSite().generate_site()
         assert errors[d - 1] in str(err.value)
Пример #4
0
 def setUpClass(cls):
     GenerateSite().generate_site()
     cls.app = cat.app.catapp.test_client()
Пример #5
0
#!/usr/bin/env python3

import os
import sys

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from cat.code import GenerateSite

GenerateSite().generate_site()

# vim: expandtab
Пример #6
0
 def setUp(self):
     GenerateSite().generate_site()
     self.app = cat.app.catapp.test_client()
Пример #7
0
    def test_locations(self, tmpdir): # 1-5 10-16
        single_errors = [
            None,
            None,
            None,
            None,
            None,
            None,
            'ERROR 6: filename is not all lower case.',
            'ERROR 7: filename is not .json file.',
            'ERROR 8: filename has characters that are not accepted (a-z0-9-).',
            'ERROR 9: Invalid file name. Should contain the year "2016". In file',
            'ERROR 10: The value of city "OrlandoX" is not in our list. If this was not a typo, add it to data/locations.json. Found in',
            'ERROR 11: The value of city "Bukarest" is not in our list. If this was not a typo, add it to data/locations.json. Found in',
            'ERROR 12: The value of state "FloridaX" is not in our list. If this was not a typo, add it to data/locations.json. Found in',
            'ERROR 13: The value of country "USAX" is not in our list. If this was not a typo, add it to data/locations.json. Found in',
            'ERROR 14: Tag "blabla" is not in the list of tags found in data/tags.json. Check for typo. Add new tags if missing from our list. in file',
            'ERROR 15: Missing or empty "name" field in',
            'ERROR 16: The conference "name" should not include the year. Seen in',
            'ERROR 17: Missing or invalid "website" field in',
            'ERROR 18: The "city" field is missing. See docs/EVENTS.md. In file',
            'ERROR 19: The "state" field is missing. See docs/EVENTS.md. In file',
            'ERROR 20: The "country" field is missing. See docs/EVENTS.md. In file',
            'ERROR 21: The "location" field is missing. See docs/EVENTS.md. In file',
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None, # 30
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None, # 40
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None, # 50
            None,
            None,
            None,
            'ERROR 54: JSON Parsing error in',
        ]

        multi_errors = [
            None,
            [
                'ERROR 20: The "country" field is missing. See docs/EVENTS.md. In file',
                'ERROR 18: The "city" field is missing. See docs/EVENTS.md. In file',
            ],
            [
                'ERROR 14: Tag "qqrq" is not in the list of tags found in data/tags.json. Check for typo. Add new tags if missing from our list. in file',
                'ERROR 14: Tag "blabla" is not in the list of tags found in data/tags.json. Check for typo. Add new tags if missing from our list. in file',
                'ERROR 16: The conference "name" should not include the year. Seen in',
                'ERROR 21: The "location" field is missing. See docs/EVENTS.md. In file',
            ],
        ]

        for test_data_dir, errors in [( os.path.join('test_data', 'single'), single_errors ), ( os.path.join('test_data', 'multi'), multi_errors)]:
            print("Temp dir: ", tmpdir)
            for cnt in range(len(errors)):
                if errors[cnt] == None:
                    continue
                test_dir_name = str(cnt)
                test_dir = tmpdir.mkdir(test_dir_name)
                test_dir.mkdir('events')
                tmp_dir = str(tmpdir)   # needed for Python older than 3.6 ??
                for filename in ['locations.json', 'series.json', 'tags.json']:
                    shutil.copyfile(os.path.join('data', filename), os.path.join(tmp_dir, test_dir_name, filename))
                for filename in os.listdir(os.path.join(test_data_dir, test_dir_name, 'events')):
                    shutil.copyfile(os.path.join(test_data_dir, test_dir_name, 'events', filename), os.path.join(tmp_dir, test_dir_name, 'events', filename))
                os.environ['CAT_TEST'] = os.path.join(tmp_dir, test_dir_name)
                with pytest.raises(CATerror) as err:
                    GenerateSite().generate_site()
                if errors[cnt].__class__.__name__ == 'str':
                    assert errors[cnt] in str(err.value)
                    # Make sure there are no other errors:
                    err_str = str(err.value)
                    loc = err_str.index(errors[cnt])
                    stripped_err_str = err_str[0: loc] + err_str[loc + len(errors[cnt]) : ]
                    #assert 'ERROR' not in stripped_err_str
                elif errors[cnt].__class__.__name__ == 'list':
                    for e in errors[cnt]:
                        assert e in str(err.value)
                else:
                    raise Exception("Bad test")
                if cnt == 6:
                    assert os.path.join(tmp_dir, test_dir_name, 'events', 'Test-2016.json') in str(err.value)
                elif cnt == 7:
                    assert os.path.join(tmp_dir, test_dir_name, 'events', 'test-2016.txt') in str(err.value)
                elif cnt == 8:
                    assert 'test_2016.json' in str(err.value)
                elif cnt == 9:
                    assert os.path.join(tmp_dir, test_dir_name, 'events', 'test.json') in str(err.value)
                elif 10 <= cnt <= 21 or cnt == 54:
                    assert os.path.join(tmp_dir, test_dir_name, 'events', 'test-10{}.json'.format(cnt)) in str(err.value)
                else:
                    assert os.path.join(tmp_dir, test_dir_name, 'events', 'test-2016.json') in str(err.value)
Пример #8
0
 def setup_class(self):
     if 'CAT_TEST' in os.environ:
         os.environ.pop('CAT_TEST')
     GenerateSite().generate_site()
     self.app = cat.app.catapp.test_client()
Пример #9
0
#!/usr/bin/env python3

import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from cat.code import GenerateSite

# read all the events
# list the ones that have youtube value which is not - and that does NOT have the video directory.
# list the ones that have no youtube entry or that it is empty
# Only show events that have already finished.

gs = GenerateSite()
gs.read_events()
no_videos = ''
no_youtube = ''
for e in sorted(gs.conferences, key=lambda e: e['start_date'], reverse=True):
    #exit(e)
    if e.get('videos_url'):
        continue

    youtube = e.get('youtube')

    if e['end_date'] > gs.now:
        if youtube:
            exit("ERROR. There is a youtube entry in a future event {}".format(
                e['nickname']))
        continue

    if youtube:
        if youtube != '-':
Пример #10
0
 def test_people(self):
     gs = GenerateSite()
     gs.read_people()
     report = gs.check_people()
     sys.stderr.write(report)
     assert report == ''
Пример #11
0
 def test_videos(self):
     gs = GenerateSite()
     gs.read_videos()
     report = gs.check_videos()
     sys.stderr.write(report)
     assert report == ''
Пример #12
0
#!/usr/bin/env python3
import sys
import os

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from cat.code import GenerateSite

gs = GenerateSite()

gs.read_videos()
report = gs.check_videos()
if report != '':
    print(report)

gs.read_people()
report = gs.check_people()
if report != '':
    print(report)

# vim: expandtab

Пример #13
0
#!/usr/bin/env python3
import sys
import os

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from cat.code import GenerateSite

# list people who only have their name

gs = GenerateSite()
gs.generate_site()  #blush
for nickname in gs.people:
    fields = gs.people[nickname]['info'].keys()
    if len(fields) == 1:
        videos = len(gs.people[nickname]['videos'])
        episodes = len(gs.people[nickname]['episodes'])
        hosting = len(gs.people[nickname]['hosting'])
        total = videos + episodes + hosting
        # for now let's only care about people who have at least one something in the database
        # later, when we merge the videos from PerlTV more people will have something
        if total > 0:
            print("{}  https://codeandtalk.com/p/{}".format(
                gs.people[nickname]['info']['name'], nickname))
        #print(gs.people[nickname])

# vim: expandtab
Пример #14
0
def print_debug(msg):
    if verbosity:
        print (msg)

year_to_check = str(args.year)

if args.reference:
    reference_year = str(args.reference)
else:
    reference_year = str(args.year - 1)

print_debug('Year to check: {}'.format(year_to_check))
print_debug('Reference year: {}'.format(reference_year))

site = GenerateSite()
site.read_all()
for event, details in sorted(site.events.items()):
    if event.endswith(reference_year):
        next_event = event.replace(reference_year, year_to_check)
        if next_event not in site.events:
            print_debug('Checking event {}'.format(next_event))
            url = details['website']
            if url.find(reference_year) != -1:
                new_url = url.replace(reference_year, year_to_check)
                print_debug('Checking changed URL {}'.format(new_url))
                try:
                    response = requests.get(new_url)
                    if response.status_code == 200:
                        print('Potential missing event: {}'.format(next_event))
                        print(new_url)