예제 #1
0
    def test_foreign_keys_explicit(self):
        chef_gusteau = factory.make("tests.Chef", fields={"first_name": "Gusteau"})

        self.assertEqual(Chef.objects.count(), 1)

        pizza = factory.make("tests.Pizza", fields={"chef_id": chef_gusteau.pk})
        self.assertEqual(pizza.chef, chef_gusteau)
        self.assertEqual(Chef.objects.count(), 1)
예제 #2
0
    def test_foreign_keys(self):
        chef_gusteau = factory.make('tests.Chef',
                                    fields={'first_name': 'Gusteau'})

        self.assertEqual(Chef.objects.count(), 1)

        pizza = factory.make('tests.Pizza', fields={'chef': chef_gusteau})
        self.assertEqual(pizza.chef, chef_gusteau)
        self.assertEqual(Chef.objects.count(), 1)
예제 #3
0
    def test_manytomany(self):
        pizza = factory.make('tests.Pizza', )
        self.assertEqual(pizza.toppings.count(), 0)

        pizza = factory.make(
            'tests.Pizza',
            fields={'toppings': [factory.make('tests.Topping')]})
        self.assertEqual(pizza.toppings.count(), 1)

        pizza = factory.make(
            'tests.Pizza',
            fields={'toppings': factory.make('tests.Topping', quantity=5)})
        self.assertEqual(pizza.toppings.count(), 5)
예제 #4
0
    def test_manytomany(self):
        pizza = factory.make("tests.Pizza")
        self.assertEqual(pizza.toppings.count(), 0)

        pizza = factory.make(
            "tests.Pizza", fields={"toppings": [factory.make("tests.Topping")]}
        )
        self.assertEqual(pizza.toppings.count(), 1)

        pizza = factory.make(
            "tests.Pizza",
            fields={"toppings": factory.make("tests.Topping", quantity=5)},
        )
        self.assertEqual(pizza.toppings.count(), 5)
예제 #5
0
    def test_foreign_keys(self):
        chef_gusteau = factory.make(
            'tests.Chef',
            fields={
                'first_name': 'Gusteau'
            }
        )

        pizza = factory.make(
            'tests.Pizza',
            fields={
                'chef': chef_gusteau
            }
        )
        self.assertEqual(pizza.chef, chef_gusteau)
예제 #6
0
    def test_lazy_field(self):
        chef_masters = factory.make('tests.Chef',
                                    fields={
                                        'first_name': 'Chef {}',
                                        'last_name': Lazy('first_name')
                                    },
                                    quantity=10)
        self.assertEqual(len(chef_masters), 10)
        self.assertEqual(chef_masters[0].first_name, 'Chef 0')
        self.assertEqual(chef_masters[0].first_name, chef_masters[0].last_name)
        self.assertEqual(chef_masters[1].first_name, 'Chef 1')
        self.assertEqual(chef_masters[0].first_name, chef_masters[0].last_name)

        margherita = factory.make(
            'tests.pizza', fields={'price': Lazy('get_price', tax=0.07)})
        self.assertEqual(margherita.price, Decimal('8.55'))
예제 #7
0
 def test_sequence_callable(self):
     margheritas = factory.make('tests.Pizza',
                                fields={'baked_on': timezone.now},
                                quantity=10)
     self.assertEqual(len(margheritas), 10)
     self.assertNotEqual(margheritas[0].baked_on, None)
     self.assertNotEqual(margheritas[0].baked_on, margheritas[1].baked_on)
예제 #8
0
    def test_update_or_make(self):
        already_there = factory.make(
            "tests.Chef", fields={"first_name": "Auguste", "last_name": "Gusteau"}
        )

        self.assertEqual(Chef.objects.count(), 1)
        chef_gusteau, created = factory.update_or_make(
            "tests.Chef", lookup={"last_name": "Gusteau"}, fields={"first_name": "Remi"}
        )
        self.assertEqual(Chef.objects.count(), 1)
        self.assertEqual(already_there, chef_gusteau)
        self.assertEqual(chef_gusteau.first_name, "Remi")

        self.assertFalse(created)

        chef_linguini, created = factory.update_or_make(
            "tests.Chef",
            lookup={"last_name": "Linguini"},
            fields={"first_name": "Alfredo"},
        )

        self.assertEqual(Chef.objects.count(), 2)
        self.assertTrue(created)
        self.assertEqual(chef_linguini.first_name, "Alfredo")
        self.assertEqual(chef_linguini.last_name, "Linguini")
예제 #9
0
 def test_save_hooks(self):
     user = factory.make('auth.User',
                         fields={
                             'username': '******',
                         },
                         pre_save=[lambda i: i.set_password('password')])
     self.assertTrue(user.check_password('password'))
예제 #10
0
 def test_field_inheritance(self):
     chef_gusteau = factory.make('tests.Chef',
                                 fields={'last_name': 'Gusteau'})
     self.assertTrue('@' in chef_gusteau.email_address)
     self.assertTrue(
         chef_gusteau.twitter_profile.startswith('http://')
         or chef_gusteau.twitter_profile.startswith('https://'))
예제 #11
0
 def test_fields(self):
     margherita = factory.make(
         'tests.Pizza',
         fields={'name': 'four cheeses'}
     )
     self.assertEqual(margherita.name, 'four cheeses')
     self.assertEqual(margherita.description, '')
예제 #12
0
    def test_foreign_keys_fail(self):
        chef_gusteau = factory.make('tests.Chef',
                                    fields={'last_name': 'Gusteau'})

        self.assertRaises(
            ForeignKeyError,
            factory.build,
            'tests.Pizza',
        )
        factory.build('tests.Pizza', fields={
            'chef': chef_gusteau,
        })

        chef_skinner = factory.build('tests.Chef',
                                     fields={
                                         'last_name': 'Skinner',
                                     })
        self.assertRaises(ForeignKeyError,
                          factory.build,
                          'tests.Pizza',
                          fields={
                              'chef': chef_skinner,
                          })

        factory.build('tests.Pizza',
                      fields={
                          'chef': chef_gusteau,
                          'critic': None,
                      })
예제 #13
0
 def setUp(self):
     self.regularuser = factory.make('auth.User',
                                     fields={
                                         'username': '******',
                                         'password': '******',
                                         'is_staff': False,
                                     })
예제 #14
0
 def test_blank(self):
     margherita = factory.make(
         'tests.Pizza',
         fields={'name': 'four cheeses', 'description': lambda n, f: f.sentence()}
     )
     self.assertEqual(margherita.name, 'four cheeses')
     self.assertNotEqual(margherita.description, '')
예제 #15
0
    def test_g_m(self):
        already_there = factory.make('tests.Chef',
                                     fields={
                                         'first_name': 'Auguste',
                                         'last_name': 'Gusteau',
                                     })

        self.assertEqual(Chef.objects.count(), 1)
        chef_gusteau, created = factory.g_m(
            'tests.Chef',
            lookup={'last_name': 'Gusteau'},
        )(first_name='Remi')
        self.assertEqual(Chef.objects.count(), 1)
        self.assertEqual(already_there, chef_gusteau)
        self.assertFalse(created)

        chef_linguini, created = factory.g_m(
            'tests.Chef',
            lookup={'last_name': 'Linguini'},
        )(first_name='Alfredo')

        self.assertEqual(Chef.objects.count(), 2)
        self.assertTrue(created)
        self.assertEqual(chef_linguini.first_name, 'Alfredo')
        self.assertEqual(chef_linguini.last_name, 'Linguini')
예제 #16
0
    def test_lazy_field(self):
        chef_masters = factory.make(
            "tests.Chef",
            fields={"first_name": "Chef {}", "last_name": Lazy("first_name")},
            quantity=10,
        )
        self.assertEqual(len(chef_masters), 10)
        self.assertEqual(chef_masters[0].first_name, "Chef 0")
        self.assertEqual(chef_masters[0].first_name, chef_masters[0].last_name)
        self.assertEqual(chef_masters[1].first_name, "Chef 1")
        self.assertEqual(chef_masters[0].first_name, chef_masters[0].last_name)

        margherita = factory.make(
            "tests.pizza", fields={"price": Lazy("get_price", tax=0.07)}
        )
        self.assertEqual(margherita.price, Decimal("8.55"))
예제 #17
0
 def test_blank(self):
     margherita = factory.make(
         "tests.Pizza",
         fields={"name": "four cheeses", "description": lambda n, f: f.sentence()},
     )
     self.assertEqual(margherita.name, "four cheeses")
     self.assertNotEqual(margherita.description, "")
예제 #18
0
 def test_sequence(self):
     margheritas = factory.make(
         "tests.Pizza", fields={"name": "pizza {}"}, quantity=10
     )
     self.assertEqual(len(margheritas), 10)
     self.assertEqual(margheritas[0].name, "pizza 0")
     self.assertEqual(margheritas[1].name, "pizza 1")
예제 #19
0
 def test_password(self):
     user = factory.make('auth.User',
                         fields={
                             'username': '******',
                             'password': '******'
                         })
     self.assertTrue(user.check_password('password'))
예제 #20
0
 def test_field_inheritance(self):
     chef_gusteau = factory.make("tests.Chef", fields={"last_name": "Gusteau"})
     self.assertTrue("@" in chef_gusteau.email_address)
     self.assertTrue(
         chef_gusteau.twitter_profile.startswith("http://")
         or chef_gusteau.twitter_profile.startswith("https://")
     )
예제 #21
0
 def test_sequence(self):
     margheritas = factory.make('tests.Pizza',
                                fields={'name': 'pizza {}'},
                                quantity=10)
     self.assertEqual(len(margheritas), 10)
     self.assertEqual(margheritas[0].name, 'pizza 0')
     self.assertEqual(margheritas[1].name, 'pizza 1')
예제 #22
0
 def test_save_hooks(self):
     user = factory.make(
         "auth.User",
         fields={"username": "******"},
         pre_save=[lambda i: i.set_password("password")],
     )
     self.assertTrue(user.check_password("password"))
예제 #23
0
 def test_save_hooks(self):
     user = factory.make(
         'auth.User',
         fields={
             'username': '******',
         },
         pre_save=[lambda i: i.set_password('password')])
     self.assertTrue(user.check_password('password'))
예제 #24
0
 def test_password(self):
     user = factory.make(
         'auth.User',
         fields={
             'username': '******',
             'password': '******'
         })
     self.assertTrue(user.check_password('password'))
예제 #25
0
    def test_lazy_field(self):
        chef_masters = factory.make(
            'tests.Chef',
            fields={
                'first_name': 'Chef {}',
                'last_name': Lazy('first_name')
            },
            quantity=10)
        self.assertEqual(len(chef_masters), 10)
        self.assertEqual(chef_masters[0].first_name, 'Chef 0')
        self.assertEqual(chef_masters[0].first_name, chef_masters[0].last_name)
        self.assertEqual(chef_masters[1].first_name, 'Chef 1')
        self.assertEqual(chef_masters[0].first_name, chef_masters[0].last_name)

        margherita = factory.make(
            'tests.pizza', fields={'price': Lazy('get_price', tax=0.07)})
        self.assertEqual(margherita.price, Decimal('8.55'))
예제 #26
0
 def test_blank(self):
     margherita = factory.make('tests.Pizza',
                               fields={
                                   'name': 'four cheeses',
                                   'description': lambda n, f: f.sentence()
                               })
     self.assertEqual(margherita.name, 'four cheeses')
     self.assertNotEqual(margherita.description, '')
예제 #27
0
 def test_sequence_callable_lambda(self):
     margheritas = factory.make(
         'tests.Pizza',
         fields={'name': lambda n, f: 'pizza {}'.format(n)},
         quantity=10
     )
     self.assertEqual(len(margheritas), 10)
     self.assertEqual(margheritas[0].name, 'pizza 0')
     self.assertEqual(margheritas[1].name, 'pizza 1')
예제 #28
0
 def test_field_inheritance(self):
     chef_gusteau = factory.make(
         'tests.Chef',
         fields={
             'first_name': 'Gusteau'
         }
     )
     self.assertTrue('@' in chef_gusteau.email_address)
     self.assertTrue('http://' in chef_gusteau.twitter_profile)
예제 #29
0
 def test_sequence_callable(self):
     margheritas = factory.make(
         'tests.Pizza',
         fields={'backed_on': timezone.now},
         quantity=10
     )
     self.assertEqual(len(margheritas), 10)
     self.assertNotEqual(margheritas[0].backed_on, None)
     self.assertNotEqual(margheritas[0].backed_on, margheritas[1].backed_on)
예제 #30
0
 def test_sequence(self):
     margheritas = factory.make(
         'tests.Pizza',
         fields={'name': 'pizza {}'},
         quantity=10
     )
     self.assertEqual(len(margheritas), 10)
     self.assertEqual(margheritas[0].name, 'pizza 0')
     self.assertEqual(margheritas[1].name, 'pizza 1')
예제 #31
0
 def test_sequence_callable_lambda(self):
     margheritas = factory.make(
         "tests.Pizza",
         fields={"name": lambda n, f: "pizza {}".format(n)},
         quantity=10,
     )
     self.assertEqual(len(margheritas), 10)
     self.assertEqual(margheritas[0].name, "pizza 0")
     self.assertEqual(margheritas[1].name, "pizza 1")
예제 #32
0
 def test_sequence_callable_lambda(self):
     margheritas = factory.make('tests.Pizza',
                                fields={
                                    'name':
                                    lambda n, f: 'pizza {}'.format(n)
                                },
                                quantity=10)
     self.assertEqual(len(margheritas), 10)
     self.assertEqual(margheritas[0].name, 'pizza 0')
     self.assertEqual(margheritas[1].name, 'pizza 1')
예제 #33
0
    def test_manytomany(self):
        pizza = factory.make(
            'tests.Pizza',
        )
        self.assertEqual(pizza.toppings.count(), 0)

        pizza = factory.make(
            'tests.Pizza',
            fields={
                'toppings': [factory.make('tests.Topping')]
            }
        )
        self.assertEqual(pizza.toppings.count(), 1)

        pizza = factory.make(
            'tests.Pizza',
            fields={
                'toppings': factory.make('tests.Topping', quantity=5)
            }
        )
        self.assertEqual(pizza.toppings.count(), 5)
예제 #34
0
    def test_foreign_keys_fail(self):
        chef_gusteau = factory.make("tests.Chef", fields={"last_name": "Gusteau"})

        self.assertRaises(ForeignKeyError, factory.build, "tests.Pizza")
        factory.build("tests.Pizza", fields={"chef": chef_gusteau})

        chef_skinner = factory.build("tests.Chef", fields={"last_name": "Skinner"})
        self.assertRaises(
            ForeignKeyError, factory.build, "tests.Pizza", fields={"chef": chef_skinner}
        )

        factory.build("tests.Pizza", fields={"chef": chef_gusteau, "critic": None})
예제 #35
0
    def test_gis_fields(self):
        from django.contrib.gis import gdal, geos

        gigis = factory.make("tests.Pizzeria")
        self.assertTrue(isinstance(gigis.hq, geos.Point))
        self.assertTrue(isinstance(gigis.directions, geos.LineString))
        self.assertTrue(isinstance(gigis.floor_plan, geos.Polygon))
        self.assertTrue(isinstance(gigis.locations, geos.MultiPoint))
        self.assertTrue(isinstance(gigis.routes, geos.MultiLineString))
        self.assertTrue(isinstance(gigis.delivery_areas, geos.MultiPolygon))
        self.assertTrue(
            isinstance(gigis.all_the_things, geos.GeometryCollection))
        self.assertTrue(isinstance(gigis.rast, gdal.GDALRaster))
예제 #36
0
    def test_password(self):
        user = factory.make(
            "auth.User", fields={"username": "******", "password": "******"}
        )
        self.assertTrue(user.check_password("password"))

        user, created = factory.update_or_make(
            "auth.User",
            lookup={"username": "******"},
            fields={"password": "******"},
        )
        self.assertFalse(created)
        self.assertTrue(user.check_password("new_password"))
예제 #37
0
    def test_postgres_fields(self):
        gigis_special = factory.make('tests.SpecialtyPizza')
        self.assertTrue(isinstance(gigis_special.toppings, list))
        for topping in gigis_special.toppings:
            self.assertTrue(isinstance(topping, text_type))

        self.assertTrue(isinstance(gigis_special.metadata, dict))
        self.assertTrue(isinstance(gigis_special.price_range, NumericRange))
        self.assertTrue(isinstance(gigis_special.price_range.lower, int))
        self.assertTrue(isinstance(gigis_special.sales, NumericRange))
        self.assertTrue(isinstance(gigis_special.sales.lower, int))
        self.assertTrue(isinstance(gigis_special.available_on, DateTimeTZRange))
        self.assertTrue(isinstance(gigis_special.available_on.lower, datetime))
        self.assertNotEqual(gigis_special.available_on.lower.tzinfo, None)
예제 #38
0
    def test_gis_fields(self):
        from django.contrib.gis import gdal, geos

        gigis = factory.make('tests.Pizzeria')
        self.assertTrue(isinstance(gigis.hq, geos.Point))
        self.assertTrue(isinstance(gigis.directions, geos.LineString))
        self.assertTrue(isinstance(gigis.floor_plan, geos.Polygon))
        self.assertTrue(isinstance(gigis.locations, geos.MultiPoint))
        self.assertTrue(isinstance(gigis.routes, geos.MultiLineString))
        self.assertTrue(isinstance(gigis.delivery_areas, geos.MultiPolygon))
        self.assertTrue(isinstance(gigis.all_the_things, geos.GeometryCollection))

        if django_version >= (1, 9, 0):
            self.assertTrue(isinstance(gigis.rast, gdal.GDALRaster))
예제 #39
0
    def test_json(self):
        gigis_special = factory.make(
            "tests.SpecialtyPizza",
            fields={"nutritional_values": {
                "Calories": 310
            }})
        self.assertEqual(gigis_special.nutritional_values, {"Calories": 310})

        gigis_special, created = factory.update_or_make(
            "tests.SpecialtyPizza",
            lookup={"id": gigis_special.id},
            fields={
                "nutritional_values": {
                    "Calories": {
                        "Total": 310,
                        "From Fat": 120
                    }
                }
            },
        )
        self.assertFalse(created)
        self.assertEqual(
            gigis_special.nutritional_values,
            {"Calories": {
                "Total": 310,
                "From Fat": 120
            }},
        )

        summer_special, created = factory.update_or_make(
            "tests.SpecialtyPizza",
            lookup={"name": "Summer Special"},
            fields={
                "nutritional_values": {
                    "Calories": {
                        "Total": 310,
                        "From Fat": 120
                    }
                }
            },
        )

        self.assertTrue(created)
        self.assertEqual(
            summer_special.nutritional_values,
            {"Calories": {
                "Total": 310,
                "From Fat": 120
            }},
        )
예제 #40
0
    def test_postgres_fields(self):
        gigis_special = factory.make("tests.SpecialtyPizza")
        self.assertTrue(isinstance(gigis_special.toppings, list))
        for topping in gigis_special.toppings:
            self.assertTrue(isinstance(topping, text_type))

        self.assertTrue(isinstance(gigis_special.metadata, dict))
        self.assertTrue(isinstance(gigis_special.price_range, NumericRange))
        self.assertTrue(isinstance(gigis_special.price_range.lower, int))
        self.assertTrue(isinstance(gigis_special.sales, NumericRange))
        self.assertTrue(isinstance(gigis_special.sales.lower, int))
        self.assertTrue(isinstance(gigis_special.available_on,
                                   DateTimeTZRange))
        self.assertTrue(isinstance(gigis_special.available_on.lower, datetime))
        self.assertNotEqual(gigis_special.available_on.lower.tzinfo, None)
        self.assertTrue(isinstance(gigis_special.nutritional_values, dict))
예제 #41
0
    def test_model(self):
        margherita = factory.make('tests.Pizza')

        # field.default
        self.assertFalse(margherita.gluten_free)
        # field.null
        self.assertFalse(margherita.price)

        # field.blank
        self.assertEqual(margherita.description, '')

        # field.choices
        self.assertIn(margherita.thickness, [0, 1, 2])

        # required field
        self.assertNotEqual(margherita.name, '')

        self.assertNotEqual(margherita.chef.first_name, '')
예제 #42
0
    def test_model(self):
        margherita = factory.make('tests.Pizza')

        # field.default
        self.assertFalse(margherita.gluten_free)
        # field.null
        self.assertFalse(margherita.price)

        # field.blank
        self.assertEqual(margherita.description, '')

        # field.choices
        self.assertIn(margherita.thickness, [0, 1, 2])

        # required field
        self.assertNotEqual(margherita.name, '')

        self.assertNotEqual(margherita.chef.first_name, '')
예제 #43
0
    def test_foreign_keys_fail(self):
        chef_gusteau = factory.make(
            'tests.Chef',
            fields={
                'first_name': 'Gusteau'
            }
        )

        self.assertRaises(ForeignKeyError, factory.build,
            'tests.Pizza',
        )
        factory.build(
            'tests.Pizza',
            fields={
                'chef': chef_gusteau,
            }
        )

        chef_skinner = factory.build(
            'tests.Chef',
            fields={
                'first_name': 'Skinner',
            }
        )
        self.assertRaises(ForeignKeyError, factory.build,
            'tests.Pizza',
            fields={
                'chef': chef_skinner,
            }
        )

        factory.build(
            'tests.Pizza',
            fields={
                'chef': chef_gusteau,
                'critic': None,
            }
        )
예제 #44
0
    def test_array(self):
        gigis_special = factory.make(
            "tests.SpecialtyPizza",
            fields={"toppings": ["black olives", "green olives"]},
        )
        self.assertEqual(gigis_special.toppings,
                         ["black olives", "green olives"])

        gigis_special, created = factory.update_or_make(
            "tests.SpecialtyPizza",
            lookup={"id": gigis_special.id},
            fields={
                "toppings":
                ["black olives", "green olives", "cremini mushrooms"]
            },
        )
        self.assertFalse(created)
        self.assertEqual(
            gigis_special.toppings,
            ["black olives", "green olives", "cremini mushrooms"],
        )

        summer_special, created = factory.update_or_make(
            "tests.SpecialtyPizza",
            lookup={"name": "Summer Special"},
            fields={
                "toppings":
                ["black olives", "green olives", "cremini mushrooms"]
            },
        )

        self.assertTrue(created)
        self.assertEqual(
            summer_special.toppings,
            ["black olives", "green olives", "cremini mushrooms"],
        )
예제 #45
0
 def test_fields(self):
     margherita = factory.make('tests.Pizza',
                               fields={'name': 'four cheeses'})
     self.assertEqual(margherita.name, 'four cheeses')
     self.assertEqual(margherita.description, '')