from django.test import TestCase
import re
# Create your tests here.


class URLconversion(TestCase):
    from courses.models import convert_longurls, make_long_regex

    segments = make_long_regex()
    long = '<a href="https://saeta.physics.hmc.edu/p064/SW-Installation.html#crap" target="_pages">Installing and configuring software</a>'

    for n in range(1, len(segments)):
        regex = "".join(segments[:n + 1])
        m = re.search(regex, long, flags=re.DOTALL)
        if m:
            print(f"\"{' | '.join(m.groups())}\"")
        else:
            print(f"Failed for {n}: {regex}")
    short = convert_longurls(long)
    assert short.startswith('{')
