Ejemplo n.º 1
0
 def test_belonging(self):
     metal = Course('metalli', 'beep.com')
     metalinside = Course('metalli', 'beep.com')
     other = Course('other', 'doesntmatter')
     courses = Courses()
     courses.append(metalinside, other)
     assert metal in courses
Ejemplo n.º 2
0
 def test_notbelonging(self):
     metal = Course('metalli', 'beep.com')
     courseinside = Course('polimeri', 'beep.com')
     other = Course('other', 'doesntmatter')
     courses = Courses()
     courses.append(courseinside, other)
     assert metal not in courses
Ejemplo n.º 3
0
 def test_sync_courses_remove(self):
     guy = User('fakeid', 'fakepwd')
     metal = Course('metalli', 'beep.com')
     other = Course('other', 'doesntmatter')
     online = Courses()
     online.append(metal)
     guy.available_courses.append(metal, other)
     guy.sync_available_courses(online)
     assert guy.available_courses == online
Ejemplo n.º 4
0
 def test_remove(self):
     all = Courses()
     one = Courses()
     metal = Course('metalli', 'beep.com')
     other = Course('other', 'doesntmatter')
     all.append(metal, other)
     one.append(other)
     all.remove(metal)
     assert all == one
Ejemplo n.º 5
0
def step_impl(context):
    new_course = Course('newcourse', 'fakelink')
    common_course = Course('common', 'commonlink')
    guy = User('fakeid', 'fakepwd')
    guy.available_courses.append(new_course, common_course)
    context.guy = guy
    online_courses = Courses()
    online_courses.append(common_course)
    context.online_courses = online_courses
Ejemplo n.º 6
0
    def test__len__(self):
        courses = Courses()
        courses.append(Course({'name': 'metalli',
                               'friendlyURL': 'beep.com',
                               'classPK': 1}),
                       Course({'name': 'other',
                               'friendlyURL': 'beep.com',
                               'classPK': 2}))

        assert len(courses) == 2
Ejemplo n.º 7
0
 def test_sync_courses_new_course(self):
     guy = User('fakeid', 'fakepwd')
     metal = Course({'name': 'metalli',
                     'friendlyURL': 'beep.com',
                     'classPK': 1})
     other = Course({'name': 'other',
                     'friendlyURL': 'doesntmatter',
                     'classPK': 2})
     online = Courses()
     online.append(metal, other)
     guy.available_courses.append(metal)
     guy.sync_available_courses(online)
     assert guy.available_courses == online
Ejemplo n.º 8
0
    def test_notbelonging(self):
        metal = Course({'name': 'metalli',
                        'friendlyURL': 'beep.com',
                        'classPK': 1})
        courseinside = Course({'name': 'polimeri',
                               'friendlyURL': 'beep.com',
                               'classPK': 1})
        other = Course({'name': 'other',
                        'friendlyURL': 'doesntmatter',
                        'classPK': 2})

        courses = Courses()
        courses.append(courseinside, other)
        assert metal not in courses
Ejemplo n.º 9
0
 def test_hash_not_depending_on_order(self):
     oneorder = Courses()
     otherorder = Courses()
     metal = Course('metalli', 'beep.com')
     polim = Course('polimeri', 'beep.it')
     oneorder.append(metal, polim)
     otherorder.append(polim, metal)
     assert hash(oneorder) == hash(otherorder)
Ejemplo n.º 10
0
 def test_append(self):
     metal = Course('metalli', 'beep.com')
     other = Course('other', 'doesntmatter')
     oneatatime = Courses()
     # append in two steps
     oneatatime.append(metal)
     oneatatime.append(other)
     twocourses = Courses()
     twocourses.append(other, metal)
     # append in one step
     assert twocourses == oneatatime
Ejemplo n.º 11
0
 def test_remove(self):
     all = Courses()
     one = Courses()
     metal = Course({'name': 'metalli',
                     'friendlyURL': 'beep.com',
                     'classPK': 1})
     other = Course({'name': 'other',
                     'friendlyURL': 'doesntmatter',
                     'classPK': 2})
     all.append(metal, other)
     one.append(other)
     all.remove(metal)
     assert all == one
Ejemplo n.º 12
0
 def test_ignoreotherbadnames(self):
     clean_list = [
         Course({'name': '[2016-17] - ANALISI MATEMATICA 1 [ FEDERICO MARIO GIOVANNI VEGNI ]',
                 'friendlyURL': 'beep.com',
                 'classPK': 122035314}),
         Course({'name': '[2016-17] - GEOMETRIA E ALGEBRA LINEARE [ PAOLO DULIO ]',
                 'friendlyURL': 'beep.com',
                 'classPK': 115041662}),
         Course({'name': '[2017-18] - DISPOSITIVI ELETTRONICI [ ANDREA LEONARDO LACAITA ]',
                 'friendlyURL': 'beep.com',
                 'classPK': 115292440})
     ]
     clean_courses = Courses()
     clean_courses.append(*clean_list)
     # the following html file is like courses-page.html, but prettified
     # i.e has multiple lines, like humans would expect html pages.
     path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         'nicer-courses-page.json')
     with open(path) as fake_courses:
         temp_courses = json.load(fake_courses)
         courses = Courses()
         for elem in temp_courses:
             course = Course(elem)
             courses.append(course)
         assert courses == clean_courses
Ejemplo n.º 13
0
 def test_ignorebeepcourse(self):
     clean_list = [
         Course({'name': '[2016-17] - ANALISI MATEMATICA 1 [ FEDERICO MARIO GIOVANNI VEGNI ]',
                 'friendlyURL': 'beep.com',
                 'classPK': 122035314}),
         Course({'name': '[2016-17] - GEOMETRIA E ALGEBRA LINEARE [ PAOLO DULIO ]',
                 'friendlyURL': 'beep.com',
                 'classPK': 115041662}),
         Course({'name': '[2017-18] - DISPOSITIVI ELETTRONICI [ ANDREA LEONARDO LACAITA ]',
                 'friendlyURL': 'beep.com',
                 'classPK': 115292440})
             ]
     clean_courses = Courses()
     clean_courses.append(*clean_list)
     # the following file is an exact copy of what you get online.
     # It's a one-line document
     path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         'courses-page.json')
     with open(path) as fake_courses:
         temp_courses = json.load(fake_courses)
         courses = Courses()
         for elem in temp_courses:
             course = Course(elem)
             courses.append(course)
         assert courses == clean_courses
Ejemplo n.º 14
0
    def test_difference(self):
        offline_metal = Course('metalli', 'beep.com')
        offline_polim = Course('polimeri', 'beep.it')
        metal = Course('metalli', 'beep.com')
        polim = Course('polimeri', 'beep.it')

        offline = Courses()
        offline.append(offline_polim, offline_metal)
        online = Courses()
        online.append(metal, polim)
        for course in online:
            print('online {}'.format(course.name))
        for course in offline:
            print('offline {}'.format(course.name))
        assert online - offline == []
Ejemplo n.º 15
0
 def test_ignorebeepcourse(self):
     clean_list = [
         Course(
             '[2014-15] - ADVANCED CHEMISTRY FOR MATERIALS ENGINEERING [ MATERIALS ENGINEERING AND NANOTECHNOLOGY ]',
             'beep.com'),
         Course(
             '[2014-15] - DURABILITY OF MATERIALS [ MATERIALS ENGINEERING AND NANOTECHNOLOGY ]',
             'beep.com'),
         Course(
             '[2014-15] - FAILURE AND CONTROL OF METALS [ MAURIZIO VEDANI ]',
             'beep.com'),
         Course(
             '[2014-15] - MATHEMATICAL METHODS FOR MATERIALS ENGINEERING [ MICHELE DI CRISTO ]',
             'beep.com'),
         Course(
             '[2014-15] - MECHANICAL BEHAVIOUR OF MATERIALS [ LAURA VERGANI ]',
             'beep.com'),
         Course(
             '[2014-15] - MICRO ELECTRO MECHANICAL SYSTEMS (MEMS) [ ALBERTO CORIGLIANO ]',
             'beep.com'),
         Course(
             '[2014-15] - PHYSICAL PROPERTIES OF MOLECULAR MATERIALS [ MATTEO MARIA SAVERIO TOMMASINI ]',
             'beep.com'),
         Course('[2014-15] - PHYSICS OF NANOSTRUCTURES [ CARLO S. CASARI ]',
                'beep.com'),
         Course('[2014-15] - SOLID STATE PHYSICS [ CARLO ENRICO BOTTANI ]',
                'beep.com'),
         Course(
             '[2014-15] - STRUCTURAL CHEMISTRY OF MATERIALS [ GUIDO RAOS ]',
             'beep.com'),
     ]
     clean_courses = Courses()
     clean_courses.append(*clean_list)
     # the following file is an exact copy of what you get online.
     # It's a one-line document
     path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         'courses-page.html')
     with open(path) as fake_courses:
         text = fake_courses.read()
         user = User("doesn't matter", 'nope')
         temp_courses = user._courses_scraper(text)
         courses = Courses()
         for elem in temp_courses:
             course = Course(elem[0], elem[1])
             courses.append(course)
         assert courses == clean_courses
Ejemplo n.º 16
0
    def test_hash_not_depending_on_order(self):
        oneorder = Courses()
        otherorder = Courses()
        metal = Course({'name': 'metalli',
                        'friendlyURL': 'beep.com',
                        'classPK': 1})
        polim = Course({'name': 'polimeri',
                        'friendlyURL': 'beep.it',
                        'classPK': 2})

        oneorder.append(metal, polim)
        otherorder.append(polim, metal)
        assert hash(oneorder) == hash(otherorder)
Ejemplo n.º 17
0
    def test_append(self):
        metal = Course({'name': 'metalli',
                        'friendlyURL': 'beep.com',
                        'classPK': 1})
        other = Course({'name': 'other',
                        'friendlyURL': 'doesntmatter',
                        'classPK': 2})

        oneatatime = Courses()
        # append in two steps
        oneatatime.append(metal)
        oneatatime.append(other)
        twocourses = Courses()
        twocourses.append(other, metal)
        # append in one step
        assert twocourses == oneatatime
Ejemplo n.º 18
0
    def test_difference(self):
        polim = Course({'name': 'polimeri',
                        'friendlyURL': 'beep.com',
                        'classPK': 1})
        offline_polim = Course({'name': 'polimeri',
                                'friendlyURL': 'beep.com',
                                'classPK': 1})

        metal = Course({'name': 'metalli',
                        'friendlyURL': 'beep.com',
                        'classPK': 1})
        offline_metal = Course({'name': 'metalli',
                                'friendlyURL': 'beep.com',
                                'classPK': 1})

        offline = Courses()
        offline.append(offline_polim, offline_metal)
        online = Courses()
        online.append(metal, polim)
        for course in online:
            print('online {}'.format(course.name))
        for course in offline:
            print('offline {}'.format(course.name))
        assert online - offline == []
Ejemplo n.º 19
0
 def test_return_hash(self):
     courses = Courses()
     courses.append(Course('metalli', 'beep.com'))
     assert hash(courses) is not None
Ejemplo n.º 20
0
 def test_return_hash(self):
     courses = Courses()
     courses.append(Course({'name': 'metalli',
                            'friendlyURL': 'beep.com',
                            'classPK': 1}))
     assert hash(courses) is not None
Ejemplo n.º 21
0
 def test__len__(self):
     courses = Courses()
     courses.append(Course('metalli', 'beep.com'),
                    Course('other', 'doesntmatter'))
     assert len(courses) == 2