def test_universities(logged_in): UniversityFactory.create_batch(11, is_verified=False) UniversityFactory.create_batch(12, is_verified=True) response = logged_in.client.get(reverse('universities:universities')) assert response.status_code == 200 response = response.json() assert response['count'] == 12 assert len(response['results']) == 12
def test_university_retrieve_list(logged_in_admin): university = UniversityFactory() response = logged_in_admin.client.get( reverse('admins:university-detail', kwargs={'pk': university.pk})) assert response.status_code == 200 assert response.json()['name'] == university.name UniversityFactory.create_batch(10) response = logged_in_admin.client.get(reverse('admins:university-list')) assert response.status_code == 200 assert len(response.json()['results']) == 11
def test_university_update(logged_in_admin): university = UniversityFactory(keywords='test') payload = dict(name='NPUA', keywords=None) response = logged_in_admin.client.put( reverse('admins:university-detail', kwargs={'pk': university.pk}), json.dumps(payload), content_type='application/json', ) university.refresh_from_db() assert response.status_code == 200 assert university.name == payload['name'] assert university.keywords == payload['keywords'] assert response.json()['name'] == payload['name'] assert response.json()['keywords'] == payload['keywords']
def test_education_put(logged_in): education = EducationFactory(user=logged_in.user) university = UniversityFactory() payload = dict( university_name=university.name, start_year=1996, end_year=2000, degree='phd', field_of_study=FuzzyText().fuzz(), description=FuzzyText(length=500).fuzz(), ) response = logged_in.client.put( reverse('universities:education_detail', kwargs={'pk': education.pk}), data=payload, content_type='application/json', ) education.refresh_from_db() assert response.status_code == 200 assert education.university.pk == university.pk assert education.start_year == payload['start_year'] assert education.end_year == payload['end_year'] assert education.degree == payload['degree'] assert education.field_of_study == payload['field_of_study'] assert education.description == payload['description']
class UniversityAPITest(TestCase): def setUp(self): self.api_url = reverse('fun-universities-api:universities-list') self.user = UserFactory(username='******', password='******') # user with profile self.univ_1 = UniversityFactory(code='test-university-1') self.univ_2 = UniversityFactory(code='test-university-2') def login_as_admin(self): self.user.is_staff = True self.user.save() self.client.login(username='******', password='******') def test_course_list_api_response_loads(self): self.login_as_admin() response = self.client.get(self.api_url) data = json.loads(response.content) self.assertIn('results', data) def test_can_update_university_score_as_admin(self): self.login_as_admin() self.univ_1.score = 0 self.univ_1.save() data = {'score': 100} url = reverse('fun-universities-api:universities-detail', args=[self.univ_1.id] ) response = self.client.put(url, data) response_data = json.loads(response.content) self.assertEqual(100, response_data['score']) def test_cannot_update_course_score_if_not_logged_in(self): self.client.logout() data = {'score': 100} url = reverse('fun-universities-api:universities-detail', args=[self.univ_1.id] ) response = self.client.put(url, data) self.assertNotEqual(response.status_code, 200)
def test_universities_filter(logged_in): UniversityFactory(name='Engineering University of Armenia', is_verified=True, keywords='Armenia Հայաստան') UniversityFactory(name='American University of Armenia', is_verified=True, keywords='Armenia Հայաստան') UniversityFactory(name='Medical Institute of Armenia', is_verified=True, keywords='Armenia Հայաստան') response = logged_in.client.get('{}?q={}'.format(reverse('universities:universities'), 'հայաստան')) assert response.status_code == 200 response = response.json() assert len(response['results']) == 3 response = logged_in.client.get('{}?q={}'.format(reverse('universities:universities'), 'medical')) response = response.json() assert len(response['results']) == 1 response = logged_in.client.get('{}?q={}'.format( reverse('universities:universities'), 'Engineering University of Armenia', )) response = response.json() assert len(response['results']) == 1
def setUp(self): super(BaseCourseList, self).setUp(create_user=False) self.user = User.objects.create(username='******', is_staff=True) self.user.set_password('password') self.user.save() self.backoffice_group, created = Group.objects.get_or_create(name='fun_backoffice') self.user.groups.add(self.backoffice_group) UserProfile.objects.create(user=self.user) self.client.login(username=self.user.username, password='******') self.university = UniversityFactory.create() self.course1 = CourseFactory.create(number='001', display_name=u"unpublished", ispublic=False) CourseAboutFactory.create(course_id=self.course1.id, course_runtime=self.course1.runtime) self.course2 = CourseFactory.create(org=self.university.code, number='002', display_name=u"published", ispublic=True) self.list_url = reverse('backoffice:courses-list')
def setUp(self): super(BaseBackoffice, self).setUp() self.university = UniversityFactory.create() self.init(False, self.university.code) self.list_url = reverse('backoffice:courses-list')
def setUp(self): self.api_url = reverse('fun-universities-api:universities-list') self.user = UserFactory(username='******', password='******') # user with profile self.univ_1 = UniversityFactory(code='test-university-1') self.univ_2 = UniversityFactory(code='test-university-2')