From f9379ec0ac7ecceea327bd9b7d3f82e02ceb5fbd Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Tue, 31 Jan 2017 09:56:34 +0100 Subject: [PATCH] Add test paragraph to readme --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 7a07b608a..85b4385bf 100644 --- a/README.md +++ b/README.md @@ -163,3 +163,30 @@ To build the documentation, run: ``` After this, generated documentation should be available in `docs/_build/html`. + +## Writing tests +It is recommended, when writing tests, to use the `ContributorFactory` located in `scipost.factories`. This will automatically generate a related user with Registered Contributor membership. You may probably need to use the fixture list `["permissions", "groups"]` in your tests make sure the permissions groups are working properly. +It is recommended, when writing tests for new models, to make use of ModelFactories instead of fixtures to prevent issues with altering fields in the model later on. + +A basic example of a test might look like: +```shell +from django.contrib.auth.models import Group +from django.test import TestCase + +from scipost.factories import ContributorFactory + + +class VetCommentaryRequestsTest(TestCase): + fixtures = ['groups', 'permissions'] + + def setUp(self): + self.contributor = ContributorFactory(user__password='test123') # The default password is `adm1n` + + def test_example_test(self): + group = Group.objects.get(name="Vetting Editors") + self.contributor.user.groups.add(group) # Assign user membership to an extra group + self.client.login(username=self.contributor.user.username, password='test123') + + # Write your tests here + +``` -- GitLab