示例#1
0
 def test_get_ensure_text_false_without_case_sensitive_match(self):
     path = '/foo/xyz/aq1'
     url = '%s%s' % (ROOT_URL, path)
     responses.add(responses.GET, url, body="that's ok", status=200)
     s = Session()
     self.assertFalse(s.get_ensure_text(path, 'OK'))
     self.assertEquals(1, len(responses.calls))
示例#2
0
 def test_get_ensure_text_false_without_case_sensitive_match(self):
     path = '/foo/xyz/aq1'
     url = '%s%s' % (ROOT_URL, path)
     responses.add(responses.GET, url, body="that's ok", status=200)
     s = Session()
     self.assertFalse(s.get_ensure_text(path, 'OK'))
     self.assertEquals(1, len(responses.calls))
示例#3
0
class Student(DidelEntity):
    """
    A virtual student, i.e. a DidEL session
    """

    def __init__(self, username, password):
        super(Student, self).__init__()
        self.session = Session()
        self.username = username
        self.path = '/claroline/auth/profile.php'
        self._courses = {}  # cache
        self.session.login(self.username, password)
        self.fetch(self.session)


    def populate(self, soup, *args, **kw):
        aliases = {'officialCode': 'code', 'uidToEdit': 'auth_id'}
        for attr in ('firstname', 'lastname', 'officialCode', 'username',
                'email', 'phone', 'skype', 'uidToEdit'):
            value = soup.select('input#%s' % attr)[0].attrs['value']
            attr = aliases.get(attr, attr)
            setattr(self, attr, value)


    def get_course(self, ref):
        """
        Return a Course object
        """
        if not ref in self._courses:
            c = Course(ref, self)
            c.fetch(self.session)
            self._courses[ref] = c
        return self._courses[ref]
示例#4
0
 def test_post_requests_object(self):
     url = 'http://www.example.com/foo'
     body = "okx&Asq'"
     responses.add(responses.POST, url, body=body, status=200)
     s = Session()
     resp = s.post(url)
     self.assertEquals(1, len(responses.calls))
     self.assertIsInstance(resp, requests.Response)
示例#5
0
 def test_post_requests_object(self):
     url = 'http://www.example.com/foo'
     body = "okx&Asq'"
     responses.add(responses.POST, url, body=body, status=200)
     s = Session()
     resp = s.post(url)
     self.assertEquals(1, len(responses.calls))
     self.assertIsInstance(resp, requests.Response)
示例#6
0
 def test_get_ensure_text_true_on_match(self):
     path = '/foo/xyz/aq1'
     url = '%s%s' % (ROOT_URL, path)
     ok = 'okaayy'
     responses.add(responses.GET, url, body="(a%sx" % ok, status=200)
     s = Session()
     self.assertTrue(s.get_ensure_text(path, ok))
     self.assertEquals(1, len(responses.calls))
示例#7
0
 def test_get_ensure_text_true_on_match(self):
     path = '/foo/xyz/aq1'
     url = '%s%s' % (ROOT_URL, path)
     ok = 'okaayy'
     responses.add(responses.GET, url, body="(a%sx" % ok, status=200)
     s = Session()
     self.assertTrue(s.get_ensure_text(path, ok))
     self.assertEquals(1, len(responses.calls))
示例#8
0
 def __init__(self, username, password, autofetch=True):
     super(Student, self).__init__()
     self.session = Session()
     self.username = username
     self.path = '/claroline/auth/profile.php'
     self._courses = {}  # cache
     self.logged = self.session.login(self.username, password)
     if autofetch:
         self.fetch(self.session)
示例#9
0
 def test_get_ensure_text_raise_on_error(self):
     path = '/foo/xyz/aq1'
     url = '%s%s' % (ROOT_URL, path)
     responses.add(responses.GET, url, body='oops', status=404)
     s = Session()
     self.assertRaises(DidelServerError, s.get_ensure_text, path, 'oops')
     self.assertEquals(1, len(responses.calls))
示例#10
0
 def __init__(self, username, password):
     super(Student, self).__init__()
     self.session = Session()
     self.username = username
     self.path = '/claroline/auth/profile.php'
     self._courses = {}  # cache
     self.session.login(self.username, password)
     self.fetch(self.session)
示例#11
0
 def __init__(self, username, password, autofetch=True):
     super(Student, self).__init__()
     self.session = Session()
     self.username = username
     self.path = '/claroline/auth/profile.php'
     self._courses = {}  # cache
     self.logged = self.session.login(self.username, password)
     self.add_resource("courses", CoursesMainPage())
     if autofetch:
         self.fetch(self.session)
示例#12
0
class Student(DidelEntity):
    """
    A virtual student, i.e. a DidEL session
    """
    def __init__(self, username, password, autofetch=True):
        super(Student, self).__init__()
        self.session = Session()
        self.username = username
        self.path = '/claroline/auth/profile.php'
        self._courses = {}  # cache
        self.logged = self.session.login(self.username, password)
        if autofetch:
            self.fetch(self.session)

    def populate(self, soup, *args, **kw):
        if not self.logged:
            raise DidelLoginRequired()
        aliases = {'officialCode': 'code', 'uidToEdit': 'auth_id'}
        for attr in ('firstname', 'lastname', 'officialCode', 'username',
                     'email', 'phone', 'skype', 'uidToEdit'):
            value = soup.select('input#%s' % attr)[0].attrs['value']
            attr = aliases.get(attr, attr)
            setattr(self, attr, value)

    def get_course(self, ref):
        """
        Return a Course object
        """
        if not self.logged:
            raise DidelLoginRequired()
        if not ref in self._courses:
            c = Course(ref, self)
            c.fetch(self.session)
            self._courses[ref] = c
        return self._courses[ref]

    def get_all_courses(self):
        """
        return all courses
        """
        if not self.logged:
            raise DidelLoginRequired()
        sc = StudentCoursesRefs()
        sc.fetch(self.session)
        return [self.get_course(ref) for ref in sc.refs]
示例#13
0
 def test_get_relative_url(self):
     url = '/foo/bar/qux'
     s = Session()
     self.assertEquals('%s%s' % (ROOT_URL, url), s.get_url(url))
示例#14
0
 def test_get_set_default_ua(self):
     url = 'http://www.example.com/foo'
     responses.add(responses.GET, url, body='ok', status=200)
     Session().get(url)
     self.assertEquals(1, len(responses.calls))
     self.assertIn('User-Agent', responses.calls[0].request.headers)
示例#15
0
 def test_get_relative_url(self):
     url = '/foo/bar/qux'
     s = Session()
     self.assertEquals('%s%s' % (ROOT_URL, url), s.get_url(url))
示例#16
0
 def test_get_relative_url_root(self):
     url = '/'
     s = Session()
     self.assertEquals('%s/' % ROOT_URL, s.get_url(url))
示例#17
0
 def test_get_absolute_url(self):
     url = 'http://example.com'
     s = Session()
     self.assertEquals(url, s.get_url(url))
示例#18
0
 def test_get_relative_url_root(self):
     url = '/'
     s = Session()
     self.assertEquals('%s/' % ROOT_URL, s.get_url(url))
示例#19
0
 def setUp(self):
     self.session = Session()
     self.soup = BeautifulSoup('')
     self._DidelEntity_populate = DidelEntity.populate
示例#20
0
 def test_get_absolute_url(self):
     url = 'http://example.com'
     s = Session()
     self.assertEquals(url, s.get_url(url))