Beispiel #1
0
class TestForwardMigrations(MigratorTestCase):
    """
    Test entire schema migration sequence for the users app
    """

    migrate_from = ('users', helpers.getOldestMigrationFile('users'))
    migrate_to = ('users', helpers.getNewestMigrationFile('users'))

    def prepare(self):

        User = self.old_state.apps.get_model('auth', 'user')

        User.objects.create(username='******',
                            email='*****@*****.**',
                            password='******')

        User.objects.create(username='******',
                            email='*****@*****.**',
                            password='******')

    def test_users_exist(self):

        User = self.new_state.apps.get_model('auth', 'user')

        self.assertEqual(User.objects.count(), 2)
Beispiel #2
0
class TestForwardMigrations(MigratorTestCase):
    """
    Test entire schema migration sequence for the build app
    """

    migrate_from = ('build', helpers.getOldestMigrationFile('build'))
    migrate_to = ('build', helpers.getNewestMigrationFile('build'))

    def prepare(self):
        """
        Create initial data!
        """

        Part = self.old_state.apps.get_model('part', 'part')

        buildable_part = Part.objects.create(
            name='Widget',
            description='Buildable Part',
            active=True,
        )

        with self.assertRaises(TypeError):
            # Cannot set the 'assembly' field as it hasn't been added to the db schema
            Part.objects.create(name='Blorb',
                                description='ABCDE',
                                assembly=True)

        Build = self.old_state.apps.get_model('build', 'build')

        Build.objects.create(part=buildable_part,
                             title='A build of some stuff',
                             quantity=50)

    def test_items_exist(self):

        Part = self.new_state.apps.get_model('part', 'part')

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

        Build = self.new_state.apps.get_model('build', 'build')

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

        # Check that the part object now has an assembly field
        part = Part.objects.all().first()
        part.assembly = True
        part.save()
        part.assembly = False
        part.save()
Beispiel #3
0
class TestForwardMigrations(MigratorTestCase):
    """
    Test entire schema migration
    """

    migrate_from = ('order', helpers.getOldestMigrationFile('order'))
    migrate_to = ('order', helpers.getNewestMigrationFile('order'))

    def prepare(self):
        """
        Create initial data set
        """

        # Create a purchase order from a supplier
        Company = self.old_state.apps.get_model('company', 'company')

        supplier = Company.objects.create(name='Supplier A',
                                          description='A great supplier!',
                                          is_supplier=True)

        PurchaseOrder = self.old_state.apps.get_model('order', 'purchaseorder')

        # Create some orders
        for ii in range(10):

            order = PurchaseOrder.objects.create(
                supplier=supplier,
                reference=f"{ii}-abcde",
                description="Just a test order")

            # Initially, the 'reference_int' field is unavailable
            with self.assertRaises(AttributeError):
                print(order.reference_int)

    def test_ref_field(self):
        """
        Test that the 'reference_int' field has been created and is filled out correctly
        """

        PurchaseOrder = self.new_state.apps.get_model('order', 'purchaseorder')

        for ii in range(10):

            order = PurchaseOrder.objects.get(reference=f"{ii}-abcde")

            # The integer reference field must have been correctly updated
        self.assertEqual(order.reference_int, ii)
Beispiel #4
0
class TestReferenceMigration(MigratorTestCase):
    """
    Test custom migration which adds 'reference' field to Build model
    """

    migrate_from = ('build', helpers.getOldestMigrationFile('build'))
    migrate_to = ('build', '0018_build_reference')

    def prepare(self):
        """
        Create some builds
        """

        Part = self.old_state.apps.get_model('part', 'part')

        part = Part.objects.create(name='Part', description='A test part')

        Build = self.old_state.apps.get_model('build', 'build')

        Build.objects.create(part=part,
                             title='My very first build',
                             quantity=10)

        Build.objects.create(part=part,
                             title='My very second build',
                             quantity=10)

        Build.objects.create(part=part,
                             title='My very third build',
                             quantity=10)

        # Ensure that the builds *do not* have a 'reference' field
        for build in Build.objects.all():
            with self.assertRaises(AttributeError):
                print(build.reference)

    def test_build_reference(self):

        Build = self.new_state.apps.get_model('build', 'build')

        self.assertEqual(Build.objects.count(), 3)

        # Check that the build reference is properly assigned
        for build in Build.objects.all():
            self.assertEqual(str(build.reference), str(build.pk))
Beispiel #5
0
class TestForwardMigrations(MigratorTestCase):
    """Unit testing class for testing 'company' app migrations"""

    migrate_from = ('company', helpers.getOldestMigrationFile('company'))
    migrate_to = ('company', helpers.getNewestMigrationFile('company'))

    def prepare(self):
        """Create some simple Company data, and ensure that it migrates OK."""
        Company = self.old_state.apps.get_model('company', 'company')

        Company.objects.create(name='MSPC',
                               description='Michael Scotts Paper Company',
                               is_supplier=True)

    def test_migrations(self):
        """Test the database state after applying all migrations"""
        Company = self.new_state.apps.get_model('company', 'company')

        self.assertEqual(Company.objects.count(), 1)
Beispiel #6
0
class TestForwardMigrations(MigratorTestCase):
    """
    Test entire schema migration sequence for the part app
    """

    migrate_from = ('part', helpers.getOldestMigrationFile('part'))
    migrate_to = ('part', helpers.getNewestMigrationFile('part'))

    def prepare(self):
        """
        Create initial data
        """

        Part = self.old_state.apps.get_model('part', 'part')

        Part.objects.create(name='A', description='My part A')
        Part.objects.create(name='B', description='My part B')
        Part.objects.create(name='C', description='My part C')
        Part.objects.create(name='D', description='My part D')
        Part.objects.create(name='E', description='My part E')

        # Extract one part object to investigate
        p = Part.objects.all().last()

        # Initially some fields are not present
        with self.assertRaises(AttributeError):
            print(p.has_variants)

        with self.assertRaises(AttributeError):
            print(p.is_template)

    def test_models_exist(self):

        Part = self.new_state.apps.get_model('part', 'part')

        self.assertEqual(Part.objects.count(), 5)

        for part in Part.objects.all():
            part.is_template = True
            part.save()
            part.is_template = False
            part.save()