def test_build_with_multi_model_and_multi_count_and_single_initial(self): factory = Factory() count1 = 2 initial1 = {'decimal_field': Decimal('10.00')} initial_list1 = list() for _ in itertools.repeat(None, count1): initial_list1.append(initial1) count2 = 3 initial2 = {'char_field': 'test value'} initial_list2 = list() for _ in itertools.repeat(None, count2): initial_list2.append(initial2) args = ((ModelOne, initial_list1), (ModelTwo, initial_list2)) models = factory.build(*args) self.assertEqual(len(models), count1 + count2) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelOne) self.assertEqual(models[0].decimal_field, initial1['decimal_field']) self.assertEqual(models[1].decimal_field, initial1['decimal_field']) self.assertIsInstance(models[2], ModelTwo) self.assertIsInstance(models[3], ModelTwo) self.assertIsInstance(models[4], ModelTwo) self.assertEqual(models[2].char_field, initial2['char_field']) self.assertEqual(models[3].char_field, initial2['char_field']) self.assertEqual(models[4].char_field, initial2['char_field'])
def test_build_with_multi_model_and_multi_count_and_single_initial(self): factory = Factory() count1 = 2 initial1 = { 'decimal_field': Decimal('10.00') } initial_list1 = list() for _ in itertools.repeat(None, count1): initial_list1.append(initial1) count2 = 3 initial2 = { 'char_field': 'test value' } initial_list2 = list() for _ in itertools.repeat(None, count2): initial_list2.append(initial2) args = ((ModelOne, initial_list1), (ModelTwo, initial_list2)) models = factory.build(*args) self.assertEqual(len(models), count1 + count2) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelOne) self.assertEqual(models[0].decimal_field, initial1['decimal_field']) self.assertEqual(models[1].decimal_field, initial1['decimal_field']) self.assertIsInstance(models[2], ModelTwo) self.assertIsInstance(models[3], ModelTwo) self.assertIsInstance(models[4], ModelTwo) self.assertEqual(models[2].char_field, initial2['char_field']) self.assertEqual(models[3].char_field, initial2['char_field']) self.assertEqual(models[4].char_field, initial2['char_field'])
def test_build_with_multi_model_and_multi_count_and_multi_initial(self): factory = Factory() initial1_1 = { 'decimal_field': Decimal('10.00') } initial1_2 = { 'decimal_field': Decimal('8.00') } initial2_1 = { 'char_field': 'test value 1' } initial2_2 = { 'char_field': 'test value 2' } args = ((ModelOne, [initial1_1, initial1_2]), (ModelTwo, [initial2_1, initial2_2])) models = factory.build(*args) self.assertEqual(len(models), 4) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelOne) self.assertEqual(models[0].decimal_field, initial1_1['decimal_field']) self.assertEqual(models[1].decimal_field, initial1_2['decimal_field']) self.assertIsInstance(models[2], ModelTwo) self.assertIsInstance(models[3], ModelTwo) self.assertEqual(models[2].char_field, initial2_1['char_field']) self.assertEqual(models[3].char_field, initial2_2['char_field'])
def test_create_with_multi_model_and_multi_count(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) models = ModelTwo.objects.all() self.assertEqual(len(models), 0) factory = Factory() count1 = 2 count2 = 3 args = ((ModelOne, count1), (ModelTwo, count2)) models = factory.create(*args) self.assertEqual(len(models), count1 + count2) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelOne) self.assertIsInstance(models[2], ModelTwo) self.assertIsInstance(models[3], ModelTwo) self.assertIsInstance(models[4], ModelTwo) # Since ModelTwo has a FK and OneToOne to ModelOne we expect: # 1 for the count in the factory models (count1) # 1 for each OneToOne fields (count2) models = ModelOne.objects.all() self.assertEqual(len(models), count1 + count2) models = ModelTwo.objects.all() self.assertEqual(len(models), count2)
def test_create_with_multi_model_and_multi_count_and_multi_initial(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) models = ModelTwo.objects.all() self.assertEqual(len(models), 0) factory = Factory() initial1_1 = {'decimal_field': Decimal('10.00')} initial1_2 = {'decimal_field': Decimal('8.00')} initial2_1 = {'char_field': 'test value 1'} initial2_2 = {'char_field': 'test value 2'} args = ((ModelOne, [initial1_1, initial1_2]), (ModelTwo, [initial2_1, initial2_2])) models = factory.create(*args) self.assertEqual(len(models), 4) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelOne) self.assertEqual(models[0].decimal_field, initial1_1['decimal_field']) self.assertEqual(models[1].decimal_field, initial1_2['decimal_field']) self.assertIsInstance(models[2], ModelTwo) self.assertIsInstance(models[3], ModelTwo) self.assertEqual(models[2].char_field, initial2_1['char_field']) self.assertEqual(models[3].char_field, initial2_2['char_field']) # Since ModelTwo has a FK and OneToOne to ModelOne we expect: # 1 for the count in the factory models (count1) # 1 for each OneToOne fields (count2) models = ModelOne.objects.all() self.assertEqual(len(models), 4) models = ModelTwo.objects.all() self.assertEqual(len(models), 2)
def test_create_with_multi_model_and_single_count_and_single_initial(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) models = ModelTwo.objects.all() self.assertEqual(len(models), 0) factory = Factory() initial1 = { 'decimal_field': Decimal('10.00') } initial2 = { 'char_field': 'test value' } args = ((ModelOne, initial1), (ModelTwo, initial2)) models = factory.create(*args) self.assertIsInstance(models[0], ModelOne) self.assertEqual(models[0].decimal_field, initial1['decimal_field']) self.assertIsInstance(models[1], ModelTwo) self.assertEqual(models[1].char_field, initial2['char_field']) # Since ModelTwo has a FK and OneToOne to ModelOne we expect: # 1 for the count in the factory models # 1 for each OneToOne fields models = ModelOne.objects.all() self.assertEqual(len(models), 2) models = ModelTwo.objects.all() self.assertEqual(len(models), 1)
def test_build_with_multi_count(self): factory = Factory() count = 2 models = factory.build(ModelOne, count) self.assertEqual(len(models), count) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelOne) self.assertNotEqual(models[0], models[1])
def test_build_with_count_and_initial(self): factory = Factory() count = 1 initial = {'decimal_field': Decimal('10.00')} args = (ModelOne, initial) model = factory.build(*args) self.assertIsInstance(model, ModelOne) self.assertEqual(model.decimal_field, initial['decimal_field'])
def test_build_with_multi_model_and_single_count(self): factory = Factory() count1 = 1 count2 = 1 args = ((ModelOne, count1), (ModelTwo, count2)) models = factory.build(*args) self.assertEqual(len(models), 2) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelTwo)
def test_create_trivial(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) factory = Factory() model = factory.create(ModelOne) self.assertIsInstance(model, ModelOne) models = ModelOne.objects.all() self.assertEqual(len(models), 1)
def test_build_with_count_and_initial(self): factory = Factory() count = 1 initial = { 'decimal_field': Decimal('10.00') } args = (ModelOne, initial) model = factory.build(*args) self.assertIsInstance(model, ModelOne) self.assertEqual(model.decimal_field, initial['decimal_field'])
def test_build_with_multi_model_and_single_count_and_single_initial(self): factory = Factory() initial1 = {'decimal_field': Decimal('10.00')} initial2 = {'char_field': 'test value'} args = ((ModelOne, initial1), (ModelTwo, initial2)) models = factory.build(*args) self.assertIsInstance(models[0], ModelOne) self.assertEqual(models[0].decimal_field, initial1['decimal_field']) self.assertIsInstance(models[1], ModelTwo) self.assertEqual(models[1].char_field, initial2['char_field'])
def test_create_with_single_count(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) factory = Factory() count = 1 args = (ModelOne, count) model = factory.create(*args) self.assertIsInstance(model, ModelOne) models = ModelOne.objects.all() self.assertEqual(len(models), count)
class ReviewTestCase(TestCase): def setUp(self): self.factory = Factory() def test_average_rating(self): meal = self.factory.create(food_models.Meal) review1_init = {'rating': 1, 'meal': meal} review2_init = {'rating': 2, 'meal': meal} self.factory.create(models.Review, (review1_init, review2_init)) expected_results = '1.5 Stars' self.assertEqual(models.Review.average_rating(meal), expected_results)
def test_build_with_multi_count_and_multi_initial(self): factory = Factory() count = 2 initial1 = {'decimal_field': Decimal('10.00')} initial2 = {'decimal_field': Decimal('8.00')} args = (ModelOne, [initial1, initial2]) models = factory.build(*args) self.assertEqual(len(models), count) self.assertIsInstance(models[0], ModelOne) self.assertEqual(models[0].decimal_field, initial1['decimal_field']) self.assertIsInstance(models[1], ModelOne) self.assertEqual(models[1].decimal_field, initial2['decimal_field'])
def test_build_with_multi_model_and_multi_count(self): factory = Factory() count1 = 2 count2 = 3 args = ((ModelOne, count1), (ModelTwo, count2)) models = factory.build(*args) self.assertEqual(len(models), count1 + count2) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelOne) self.assertIsInstance(models[2], ModelTwo) self.assertIsInstance(models[3], ModelTwo) self.assertIsInstance(models[4], ModelTwo)
def test_create_with_count_and_initial(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) factory = Factory() initial = {'decimal_field': Decimal('10.00')} args = (ModelOne, initial) model = factory.create(*args) self.assertIsInstance(model, ModelOne) self.assertEqual(model.decimal_field, initial['decimal_field']) models = ModelOne.objects.all() self.assertEqual(len(models), 1)
def test_build_with_multi_count_and_single_initial(self): factory = Factory() count = 2 initial1 = {'decimal_field': Decimal('10.00')} initial_list = list() for _ in itertools.repeat(None, count): initial_list.append(initial1) args = (ModelOne, initial_list) models = factory.build(*args) self.assertEqual(len(models), count) self.assertIsInstance(models[0], ModelOne) self.assertEqual(models[0].decimal_field, initial1['decimal_field']) self.assertIsInstance(models[1], ModelOne) self.assertEqual(models[1].decimal_field, initial1['decimal_field'])
def create_question(question_text='', days=None, time=None): """ Creates a question with the given `question_text` and published the given number of `days` offset to now (negative for questions published in the past, positive for questions that have yet to be published). """ factory = Factory() if not time: time = timezone.now() + datetime.timedelta(days=days) initial = { 'question_text': question_text, 'pub_date': time, } return factory.create(Question, initial)
def test_create_with_count_and_initial(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) factory = Factory() initial = { 'decimal_field': Decimal('10.00') } args = (ModelOne, initial) model = factory.create(*args) self.assertIsInstance(model, ModelOne) self.assertEqual(model.decimal_field, initial['decimal_field']) models = ModelOne.objects.all() self.assertEqual(len(models), 1)
def test_create_with_multi_count(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) factory = Factory() count = 2 args = (ModelOne, count) models = factory.create(*args) self.assertEqual(len(models), count) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelOne) self.assertNotEqual(models[0], models[1]) models = ModelOne.objects.all() self.assertEqual(len(models), count)
def test_build_with_multi_model_and_single_count_and_single_initial(self): factory = Factory() initial1 = { 'decimal_field': Decimal('10.00') } initial2 = { 'char_field': 'test value' } args = ((ModelOne, initial1), (ModelTwo, initial2)) models = factory.build(*args) self.assertIsInstance(models[0], ModelOne) self.assertEqual(models[0].decimal_field, initial1['decimal_field']) self.assertIsInstance(models[1], ModelTwo) self.assertEqual(models[1].char_field, initial2['char_field'])
def test_build_with_multi_count_and_multi_initial(self): factory = Factory() count = 2 initial1 = { 'decimal_field': Decimal('10.00') } initial2 = { 'decimal_field': Decimal('8.00') } args = (ModelOne, [initial1, initial2]) models = factory.build(*args) self.assertEqual(len(models), count) self.assertIsInstance(models[0], ModelOne) self.assertEqual(models[0].decimal_field, initial1['decimal_field']) self.assertIsInstance(models[1], ModelOne) self.assertEqual(models[1].decimal_field, initial2['decimal_field'])
def test_build_with_multi_count_and_single_initial(self): factory = Factory() count = 2 initial1 = { 'decimal_field': Decimal('10.00') } initial_list = list() for _ in itertools.repeat(None, count): initial_list.append(initial1) args = (ModelOne, initial_list) models = factory.build(*args) self.assertEqual(len(models), count) self.assertIsInstance(models[0], ModelOne) self.assertEqual(models[0].decimal_field, initial1['decimal_field']) self.assertIsInstance(models[1], ModelOne) self.assertEqual(models[1].decimal_field, initial1['decimal_field'])
def test_create_with_multi_model_trivial(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) models = ModelTwo.objects.all() self.assertEqual(len(models), 0) factory = Factory() models = factory.create((ModelOne, ), (ModelTwo, )) self.assertEqual(len(models), 2) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelTwo) # Since ModelTwo has a FK and OneToOne to ModelOne we expect 2 models = ModelOne.objects.all() self.assertEqual(len(models), 2) models = ModelTwo.objects.all() self.assertEqual(len(models), 1)
def test_create_with_multi_count_and_multi_initial(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) factory = Factory() initial1 = {'decimal_field': Decimal('10.00')} initial2 = {'decimal_field': Decimal('8.00')} args = (ModelOne, [initial1, initial2]) models = factory.create(*args) self.assertEqual(len(models), 2) self.assertIsInstance(models[0], ModelOne) self.assertEqual(models[0].decimal_field, initial1['decimal_field']) self.assertIsInstance(models[1], ModelOne) self.assertEqual(models[1].decimal_field, initial2['decimal_field']) models = ModelOne.objects.all() self.assertEqual(len(models), 2)
class SuperSnazzyModelTests(TestCase): def setUp(self): self.factory = Factory() def test_sum_fib_nums(self): initial = { 'fib_index': 0, 'fib_num': '1000', } fib_history = self.factory.create(FibHistory, initial) self.assertEqual(fib_history.do_something_pointless(), 0) initial = { 'fib_index': 100, 'fib_num': 10, } fib_history = self.factory.create(FibHistory, initial) self.assertEqual(fib_history.do_something_pointless(), 1000)
def test_build_with_multi_model_and_multi_count_and_multi_initial(self): factory = Factory() initial1_1 = {'decimal_field': Decimal('10.00')} initial1_2 = {'decimal_field': Decimal('8.00')} initial2_1 = {'char_field': 'test value 1'} initial2_2 = {'char_field': 'test value 2'} args = ((ModelOne, [initial1_1, initial1_2]), (ModelTwo, [initial2_1, initial2_2])) models = factory.build(*args) self.assertEqual(len(models), 4) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelOne) self.assertEqual(models[0].decimal_field, initial1_1['decimal_field']) self.assertEqual(models[1].decimal_field, initial1_2['decimal_field']) self.assertIsInstance(models[2], ModelTwo) self.assertIsInstance(models[3], ModelTwo) self.assertEqual(models[2].char_field, initial2_1['char_field']) self.assertEqual(models[3].char_field, initial2_2['char_field'])
def test_create_with_multi_model_and_multi_count_and_single_initial(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) models = ModelTwo.objects.all() self.assertEqual(len(models), 0) factory = Factory() count1 = 2 initial1 = { 'decimal_field': Decimal('10.00') } initial_list1 = list() for _ in itertools.repeat(None, count1): initial_list1.append(initial1) count2 = 3 initial2 = { 'char_field': 'test value' } initial_list2 = list() for _ in itertools.repeat(None, count2): initial_list2.append(initial2) args = ((ModelOne, initial_list1), (ModelTwo, initial_list2)) models = factory.create(*args) self.assertEqual(len(models), count1 + count2) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelOne) self.assertEqual(models[0].decimal_field, initial1['decimal_field']) self.assertEqual(models[1].decimal_field, initial1['decimal_field']) self.assertIsInstance(models[2], ModelTwo) self.assertIsInstance(models[3], ModelTwo) self.assertIsInstance(models[4], ModelTwo) self.assertEqual(models[2].char_field, initial2['char_field']) self.assertEqual(models[3].char_field, initial2['char_field']) self.assertEqual(models[4].char_field, initial2['char_field']) # Since ModelTwo has a FK and OneToOne to ModelOne we expect: # 1 for the count in the factory models (count1) # 1 for each OneToOne fields (count2) models = ModelOne.objects.all() self.assertEqual(len(models), count1 + count2) models = ModelTwo.objects.all() self.assertEqual(len(models), count2)
def test_create_with_multi_model_and_single_count(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) models = ModelTwo.objects.all() self.assertEqual(len(models), 0) factory = Factory() count1 = 1 count2 = 1 args = ((ModelOne, count1), (ModelTwo, count2)) models = factory.create(*args) self.assertEqual(len(models), 2) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelTwo) # Since ModelTwo has a FK and OneToOne to ModelOne we expect 2 models = ModelOne.objects.all() self.assertEqual(len(models), 2) models = ModelTwo.objects.all() self.assertEqual(len(models), 1)
class MageTestCase(TestCase): def setUp(self): self.factory = Factory() def test_brothers_in_arms(self): # Exclude the mage itself mage_1 = self.factory.create( models.Mage, {'magic_type': constants.ARCANE}) expected = 0 self.assertEqual(mage_1.brothers_in_arms.count(), expected) # Let's add another mage with another magic_type self.factory.create(models.Mage, {'magic_type': constants.BLACK}) expected = 0 self.assertEqual(mage_1.brothers_in_arms.count(), expected) # Let's add another mage with the same magic_type self.factory.create(models.Mage, {'magic_type': constants.ARCANE}) expected = 1 self.assertEqual(mage_1.brothers_in_arms.count(), expected)
def test_create_with_multi_count_and_multi_initial(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) factory = Factory() initial1 = { 'decimal_field': Decimal('10.00') } initial2 = { 'decimal_field': Decimal('8.00') } args = (ModelOne, [initial1, initial2]) models = factory.create(*args) self.assertEqual(len(models), 2) self.assertIsInstance(models[0], ModelOne) self.assertEqual(models[0].decimal_field, initial1['decimal_field']) self.assertIsInstance(models[1], ModelOne) self.assertEqual(models[1].decimal_field, initial2['decimal_field']) models = ModelOne.objects.all() self.assertEqual(len(models), 2)
def test_create_with_multi_model_and_multi_count_and_single_initial(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) models = ModelTwo.objects.all() self.assertEqual(len(models), 0) factory = Factory() count1 = 2 initial1 = {'decimal_field': Decimal('10.00')} initial_list1 = list() for _ in itertools.repeat(None, count1): initial_list1.append(initial1) count2 = 3 initial2 = {'char_field': 'test value'} initial_list2 = list() for _ in itertools.repeat(None, count2): initial_list2.append(initial2) args = ((ModelOne, initial_list1), (ModelTwo, initial_list2)) models = factory.create(*args) self.assertEqual(len(models), count1 + count2) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelOne) self.assertEqual(models[0].decimal_field, initial1['decimal_field']) self.assertEqual(models[1].decimal_field, initial1['decimal_field']) self.assertIsInstance(models[2], ModelTwo) self.assertIsInstance(models[3], ModelTwo) self.assertIsInstance(models[4], ModelTwo) self.assertEqual(models[2].char_field, initial2['char_field']) self.assertEqual(models[3].char_field, initial2['char_field']) self.assertEqual(models[4].char_field, initial2['char_field']) # Since ModelTwo has a FK and OneToOne to ModelOne we expect: # 1 for the count in the factory models (count1) # 1 for each OneToOne fields (count2) models = ModelOne.objects.all() self.assertEqual(len(models), count1 + count2) models = ModelTwo.objects.all() self.assertEqual(len(models), count2)
def test_create_with_multi_model_and_multi_count_and_multi_initial(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) models = ModelTwo.objects.all() self.assertEqual(len(models), 0) factory = Factory() initial1_1 = { 'decimal_field': Decimal('10.00') } initial1_2 = { 'decimal_field': Decimal('8.00') } initial2_1 = { 'char_field': 'test value 1' } initial2_2 = { 'char_field': 'test value 2' } args = ((ModelOne, [initial1_1, initial1_2]), (ModelTwo, [initial2_1, initial2_2])) models = factory.create(*args) self.assertEqual(len(models), 4) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelOne) self.assertEqual(models[0].decimal_field, initial1_1['decimal_field']) self.assertEqual(models[1].decimal_field, initial1_2['decimal_field']) self.assertIsInstance(models[2], ModelTwo) self.assertIsInstance(models[3], ModelTwo) self.assertEqual(models[2].char_field, initial2_1['char_field']) self.assertEqual(models[3].char_field, initial2_2['char_field']) # Since ModelTwo has a FK and OneToOne to ModelOne we expect: # 1 for the count in the factory models (count1) # 1 for each OneToOne fields (count2) models = ModelOne.objects.all() self.assertEqual(len(models), 4) models = ModelTwo.objects.all() self.assertEqual(len(models), 2)
def test_resolve_args(self): factory = Factory() with self.assertRaises(InvalidArguments) as _: factory._resolve_args() with self.assertRaises(InvalidArguments) as _: factory._resolve_args('wrong_val') model, initial = factory._resolve_args(ModelOne) self.assertEqual(model, ModelOne) self.assertIsInstance(initial, tuple) self.assertIsNone(initial[0])
def test_create_with_multi_model_and_single_count_and_single_initial(self): models = ModelOne.objects.all() self.assertEqual(len(models), 0) models = ModelTwo.objects.all() self.assertEqual(len(models), 0) factory = Factory() initial1 = {'decimal_field': Decimal('10.00')} initial2 = {'char_field': 'test value'} args = ((ModelOne, initial1), (ModelTwo, initial2)) models = factory.create(*args) self.assertIsInstance(models[0], ModelOne) self.assertEqual(models[0].decimal_field, initial1['decimal_field']) self.assertIsInstance(models[1], ModelTwo) self.assertEqual(models[1].char_field, initial2['char_field']) # Since ModelTwo has a FK and OneToOne to ModelOne we expect: # 1 for the count in the factory models # 1 for each OneToOne fields models = ModelOne.objects.all() self.assertEqual(len(models), 2) models = ModelTwo.objects.all() self.assertEqual(len(models), 1)
def create_data(request): from fixtureless import Factory import itertools factory = Factory() initial = {"reliableGPS": False, "sponsored": True, "forCharity": False} initial_list = list() for _ in itertools.repeat(None, 20): initial_list.append(initial) users = factory.create(User, 10) social = factory.create(Social, 10) accounts = factory.create(AccountInfo, 10) locations = factory.create(Location, initial_list) payments = factory.create(Payment, 15) votes1 = factory.create(Vote, 60) comments = factory.create(Comment, 60) return Response(status=status.HTTP_200_OK)
def test_build_with_single_count(self): factory = Factory() count = 1 args = (ModelOne, count) model = factory.build(*args) self.assertIsInstance(model, ModelOne)
def test_build_trivial(self): factory = Factory() model = factory.build(ModelOne) self.assertIsInstance(model, ModelOne)
def setUp(self): self.factory = Factory()
This includes tests for shares, and uses the API provided by genesets. Ultimately it might be good to extract each of the API components into their respective reusable modules. """ from django.contrib.auth.models import User from django.test import TestCase from fixtureless import Factory from tastypie.test import ResourceTestCaseMixin, TestApiClient from organisms.models import Organism from genes.models import Gene from genesets.models import Geneset from collaborations.models import Share, Collaboration from collaborations.utils import get_collaborators, get_invites, get_inviteds factory = Factory() class ShareFromTestCase(ResourceTestCaseMixin, TestCase): """ Test that collaborators can share. Test that collaborators can share via the API. These test cases are for two users, u1 and u2 who collaborate and need to share genesets. """ def setUp(self): """ Set up test environment. Make two users, log in one of the users, create some genes and an organism, a geneset, and a collaboration.
def test_verify_kwargs(self): factory = Factory() # invalid kwarg type val = 'invalid type' with self.assertRaises(InvalidArguments) as _: factory._verify_kwargs(val) # invalid kwarg type in list val = ['invalid type'] with self.assertRaises(InvalidArguments) as _: factory._verify_kwargs(val) # valid kwarg type no list val = {'valid': 'type'} factory._verify_kwargs(val) # valid type val = [{'valid': 'type'}] factory._verify_kwargs(val) # valid type, invalid type, correct length val = [{'valid': 'type'}, 'invalid type'] with self.assertRaises(InvalidArguments) as _: factory._verify_kwargs(val)
def test_build_with_multi_model_trivial(self): factory = Factory() models = factory.build((ModelOne, ), (ModelTwo, )) self.assertEqual(len(models), 2) self.assertIsInstance(models[0], ModelOne) self.assertIsInstance(models[1], ModelTwo)
from fixtureless import Factory from public.models import Location factory = Factory() count = 5 location = factory.create(Location, count)