These are chat archives for django/django

1st
Dec 2018
#MW
@horlahlekhon
Dec 01 2018 09:34

hello, i have a question..... i want to test a view but it lives behind the login page; is there a way i can write a function in my def setup function at the start of a test class , which will log a user in for each instance or function of the tests in the class......

example :

i have a test setup class

class Setup_class(TestCase):

    def setUp(self):
        self.member = Member.objects.create_user(username="Lesegekan",first_name="Taiwo", last_name="T", gender="M",phone="09012325677",company="Tops sys", email="tops@t.com")
#how can i log the user in here..
        self.client = Client()


# so that i can use the logged in user to test all the below stuffs
class BookViewsTest(Setup_class):

    def test_new_book_page(self):
        response = self.client.get(reverse('books_new'))
        self.assertEquals(response.status_code, 200)
        self.assertTemplateUsed(response, 'new_book.html')
        self.assertContains(response, BookForm() )
johndiego
@johndiego
Dec 01 2018 23:53
hi guys
johndiego
@johndiego
Dec 01 2018 23:59
I need help with formset
someone help-me?
fsecada01
@fsecada01
Dec 01 2018 23:59
please state your current problem so that we may offer help!