def test_create_study_plan_for_user(self): token = get_token_from_user(user=self.user) self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key) study_plan = StudyPlanFactory.build(name='AWS Certification') lesson_1 = LessonFactory.build() lesson_2 = LessonFactory.build() data = json.dumps({ 'name': study_plan.name, 'lessons': [{ 'topic': lesson_1.topic, }, { 'topic': lesson_2.topic, }] }) response = self.client.post(reverse('study-plan-list', kwargs={'version': 'v1'}), data=data, content_type='application/json') study_plan_created = StudyPlan.objects.get(name=study_plan.name) self.assertEqual(response.status_code, status.HTTP_201_CREATED) study_plan_data = json.loads(response.content) self.assertEqual(study_plan_data['name'], study_plan_created.name) self.assertEqual(study_plan_data['lessons'][0]['topic'], study_plan_created.lessons.all()[0].topic) self.assertEqual(study_plan_data['lessons'][1]['topic'], study_plan_created.lessons.all()[1].topic)
def setUp(self): self.lesson_1 = LessonFactory() self.lesson_2 = LessonFactory() self.study_plan = StudyPlanFactory( lessons=[self.lesson_1, self.lesson_2]) self.study_plan_serializer = StudyPlanSerializer( instance=self.study_plan)
def setUp(self) -> None: self.client = APIClient() self.user = UserFactory(first_name='John Due') self.user_membership = UserMembershipFactory(user=self.user) self.lesson = LessonFactory() self.study_plan = StudyPlanFactory( user_membership=self.user_membership, lessons=[self.lesson]) create_token(user=self.user)
def test_add_lesson_to_user_study_plan(self): lesson = LessonFactory() data = json.dumps({'topic': lesson.topic}) token = get_token_from_user(user=self.user) self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key) response = self.client.post(reverse('lesson-list', kwargs={'version': 'v1'}), data=data, content_type='application/json') self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def test_it_returns_403_for_free_user_when_access_study_plan_aggregated_data_feature_for_premium_accounts( self): user = UserFactory(first_name='Spike Lee') user_membership = UserMembershipFactory(user=user) lesson = LessonFactory() study_plan = StudyPlanFactory(user_membership=user_membership, lessons=[lesson]) create_token(user=user) token = get_token_from_user(user=user) self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key) response = self.client.get( reverse('study-plan-get-lesson-aggregated-data', kwargs={ 'version': 'v1', 'pk': study_plan.id }), ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def setUp(self): self.lesson = LessonFactory() self.lesson_serializer = LessonSerializer(instance=self.lesson)
def setUp(self) -> None: self.lesson = LessonFactory()
def setUp(self) -> None: self.lesson = LessonFactory() self.study_plan = StudyPlanFactory(lessons=[self.lesson])