def setUpTestData(cls): # Object of news and update model cls.usr = User.objects.create(username='******') cls.user = UserProfile.objects.create(user=cls.usr, dob=get_random_date()) cls.news = News.objects.create(title='news_1', date=get_random_date()) cls.update = Update.objects.create(title='update_1')
def setUpTestData(cls): cls.fa = FacultyAdvisor.objects.create(name='test_fa') cls.society_1 = Society.objects.create(name='society', slug='society_1', year='2000', is_active=True) cls.club_1 = Club.objects.create(name='club_1', society=cls.society_1, slug='club_1') cls.activity_1 = Activity.objects.create(name='activity_1', club=cls.club_1) cls.user_1 = User.objects.create(username='******') cls.user_profile_1 = UserProfile.objects.create(user=cls.user_1, dob=get_random_date(), roll='B00CS000') cls.senate_1 = Senate.objects.create(name='senate_1', year='2000', slug='senate_1') cls.senate_membership_1 = SenateMembership.objects.create( senate=cls.senate_1, userprofile=cls.user_profile_1) cls.social_link_1 = SocialLink.objects.create( club=cls.club_1, social_media='YT', link='https://youtube.com') cls.social_link_2 = SocialLink.objects.create( club=cls.club_1, social_media='AB', link='https://youtube.com') cls.contact_1 = Contact.objects.create(name='user')
class EventFactory(factory.django.DjangoModelFactory): class Meta: model = 'events.Event' name = factory.Faker('sentence', nb_words=4) description = factory.Faker('sentence', nb_words=30) location = factory.Faker('city') date = get_random_date() club = factory.SubFactory(ClubFactory)
def test_oauth_register_url_with_logged_in_case_1(self): # register url with logged in user & with no user profile data & data provided & dob < 13 year --> error in page # & will not create user profile object self.client.force_login(user=self.user_2) dob = str(get_random_date(True).year) + "-" + str( get_random_date(True).month) + "-" + str( get_random_date(True).day) # dob < 13 year data = { 'phone': ['1234567890'], 'gender': ['M'], 'dob': [dob], 'prog': ['BT'], 'branch': ['CSE'], 'year': ['1'], 'roll': ['B17CS013'] } response = self.client.post(reverse('oauth:register'), data, follow=True) self.assertTemplateUsed(response, 'oauth/register.html') self.assertFalse(UserProfile.objects.filter(user=self.user_2).exists()) self.client.logout()
def setUpTestData(cls): # make a user with user profile data cls.user_1 = User.objects.create(username='******') cls.user_profile_1 = UserProfile.objects.create(user=cls.user_1, roll='B17CS014', dob=get_random_date(), phone='1234567890', branch='CSE') cls.link_1 = SocialLink.objects.create(user=cls.user_1, social_media='YT', link='iitj.ac.in') cls.link_2 = SocialLink.objects.create(user=cls.user_1, social_media='AB', link='iitj.ac.in') # user with no user profile data cls.user_2 = User.objects.create(username='******')
class UserProfileFactory(factory.django.DjangoModelFactory): class Meta: model = 'oauth.UserProfile' django_get_or_create = ( 'user', 'roll', 'dob', 'gender', 'prog', 'year', 'phone', 'hometown', 'branch', 'skills', 'about',) email_confirmed = True prog = random.choice(['BT', 'MT', 'MSc', 'PhD']) roll = factory.Sequence(lambda n: 'B16CS%d' % n) user = factory.SubFactory(UserFactory) dob = get_random_date() gender = random.choice(['M', 'F']) year = random.choice(['1', '2', '3', '4', '5']) phone = random.randint(6000000000, 9999999999) avatar = factory.django.ImageField(color=random.choice(COLOUR)) cover = factory.django.ImageField(color=random.choice(COLOUR)) hometown = factory.Faker('city') branch = random.choice(['CSE', 'EE', 'ME']) skills = random.choice(SKILL) + ',' + random.choice(SKILL) + ',' + random.choice(SKILL) about = factory.Faker('sentence', nb_words=5)
def test_oauth_profile_edit_case_4(self): # profile edit & user doesn't own & profile exist --> response permission denied self.user_profile_2 = UserProfile.objects.create(user=self.user_2, roll='B17CS000', dob=get_random_date(), phone='1234567890', branch='CSE') data = { 'phone': ['0987654321'], 'year': ['1'], 'hometown': ['XYZ'], 'skills': [''], 'about': [''] } self.client.force_login(self.user_1) response = self.client.post(reverse( 'oauth:edit', kwargs={'roll': self.user_profile_2.roll}), data, follow=True) self.assertEqual(response.status_code, 403) self.user_profile_2.delete() self.client.logout()
def setUpTestData(cls): # Create event object cls.event_1 = Event.objects.create(name='event_1', date=get_random_date())