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))
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]
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)
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))
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 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))
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 __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)
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]
def test_get_relative_url(self): url = '/foo/bar/qux' s = Session() self.assertEquals('%s%s' % (ROOT_URL, url), s.get_url(url))
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)
def test_get_relative_url_root(self): url = '/' s = Session() self.assertEquals('%s/' % ROOT_URL, s.get_url(url))
def test_get_absolute_url(self): url = 'http://example.com' s = Session() self.assertEquals(url, s.get_url(url))
def setUp(self): self.session = Session() self.soup = BeautifulSoup('') self._DidelEntity_populate = DidelEntity.populate