~rvb/maas/dj-migrations

« back to all changes in this revision

Viewing changes to src/maasserver/models/tests/test_partition.py

  • Committer: Raphael Badin
  • Date: 2015-03-13 15:22:22 UTC
  • mfrom: (3631.1.15 maas)
  • Revision ID: raphael.badin@canonical.com-20150313152222-nhq1vs6hop1ooq7e
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2015 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Tests for `Partition`."""
 
5
 
 
6
from __future__ import (
 
7
    absolute_import,
 
8
    print_function,
 
9
    unicode_literals,
 
10
    )
 
11
 
 
12
str = None
 
13
 
 
14
__metaclass__ = type
 
15
__all__ = []
 
16
 
 
17
from uuid import uuid4
 
18
 
 
19
from maasserver.enum import PARTITION_TABLE_TYPE
 
20
from maasserver.testing.factory import factory
 
21
from maasserver.testing.testcase import MAASServerTestCase
 
22
 
 
23
 
 
24
class TestPartition(MAASServerTestCase):
 
25
    """Tests for the `Partition` model."""
 
26
 
 
27
    def test_get_node_returns_partition_table_node(self):
 
28
        partition = factory.make_Partition()
 
29
        self.assertEquals(
 
30
            partition.partition_table.get_node(), partition.get_node())
 
31
 
 
32
    def test_get_block_size_returns_partition_table_block_size(self):
 
33
        partition = factory.make_Partition()
 
34
        self.assertEquals(
 
35
            partition.partition_table.get_block_size(),
 
36
            partition.get_block_size())
 
37
 
 
38
    def test_doesnt_set_uuid_if_partition_table_is_MBR(self):
 
39
        table = factory.make_PartitionTable(
 
40
            table_type=PARTITION_TABLE_TYPE.MBR)
 
41
        partition = factory.make_Partition(partition_table=table)
 
42
        self.assertIsNone(partition.uuid)
 
43
 
 
44
    def test_set_uuid_if_partition_table_is_GPT(self):
 
45
        table = factory.make_PartitionTable(
 
46
            table_type=PARTITION_TABLE_TYPE.GPT)
 
47
        partition = factory.make_Partition(partition_table=table)
 
48
        self.assertIsNotNone(partition.uuid)
 
49
 
 
50
    def test_save_doesnt_overwrite_uuid(self):
 
51
        uuid = uuid4()
 
52
        table = factory.make_PartitionTable(
 
53
            table_type=PARTITION_TABLE_TYPE.GPT)
 
54
        partition = factory.make_Partition(partition_table=table, uuid=uuid)
 
55
        partition.save()
 
56
        self.assertEquals('%s' % uuid, partition.uuid)