Example #1
0
 def test_create_question(self):
     self.setUpAndLogin()
     c = Client()
     resp = c.post('/AskCATie/question/create/',
                   data={
                       'title': self.q_title,
                       'body': self.q_body,
                       'code': 337,
                       'lecture': reformat_for_url(self.name)
                   },
                   HTTP_AUTHORIZATION=self.token)
     self.assertEqual(resp.status_code, status.HTTP_200_OK)
     resp = c.get(self.q_url, HTTP_AUTHORIZATION=self.token)
     resp_content_str = resp.content.decode('utf-8')
     question = json.loads(resp_content_str)
     self.assertEqual(question['title'], self.q_title)
     self.assertEqual(question['body'], self.q_body)
     self.assertEqual(question['lecture'], reformat_for_url(self.name))
     self.assertEqual(question['poster'], self.username)
Example #2
0
 def test_get_lecture(self):
     self.setUpData()
     self.loginAdmin()
     c = Client()
     url = '/courses/' + str(self.conc_crse.code) + '/' + \
           reformat_for_url(self.name) + '/'
     resp = c.get(url, HTTP_AUTHORIZATION=self.token)
     resp_content_str = resp.content.decode('utf-8')
     resp_content_json = json.loads(resp_content_str)
     self.assertEqual(resp_content_json['name'], self.name)
     self.assertEqual(resp_content_json['video'], self.video)
Example #3
0
 def test_create_lecture(self):
     self.setUpData()
     self.loginAdmin()
     c = Client()
     resp = c.post('/lectures/create/',
                   data={
                       'name': self.create_name,
                       'code': self.conc_crse.code,
                       'video': self.video
                   },
                   HTTP_AUTHORIZATION=self.token)
     self.assertEqual(resp.status_code, status.HTTP_200_OK)
     url = '/courses/' + str(self.conc_crse.code) + '/' + \
           reformat_for_url(self.create_name) + '/'
     resp = c.get(url, HTTP_AUTHORIZATION=self.token)
     resp_content_str = resp.content.decode('utf-8')
     resp_content_json = json.loads(resp_content_str)
     self.assertEqual(resp_content_json['name'], self.create_name)
     self.assertEqual(resp_content_json['video'], self.video)
Example #4
0
 def test_get_question(self):
     self.setUpAndLogin()
     self.create_dummy_question()
     commenter = self.create_commenter()
     self.create_dummy_comment(commenter)
     c = Client()
     resp = c.get(self.q_url, HTTP_AUTHORIZATION=self.token)
     resp_content_str = resp.content.decode('utf-8')
     question = json.loads(resp_content_str)
     self.assertEqual(question['title'], self.q_title)
     self.assertEqual(question['body'], self.q_body)
     self.assertEqual(question['lecture'], reformat_for_url(self.name))
     self.assertEqual(question['poster'], self.q_poster_name_dummy)
     comments = question['comment_set']
     self.assertEqual(len(comments), 1)
     comment = comments[0]
     self.assertEqual(comment['poster'], self.commenter_name_dummy)
     self.assertEqual(comment['score'], 0)
     self.assertEqual(comment['questionId'], question['id'])
     self.assertEqual(comment['parentId'], None)
Example #5
0
 def save(self, *args, **kwargs):
     if not self.urlName:
         self.urlName = reformat_for_url(self.name)
     super(Lecture, self).save(*args, **kwargs)