1
# Copyright 2015 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Tests for `Partition`."""
6
from __future__ import (
17
from uuid import uuid4
19
from maasserver.enum import PARTITION_TABLE_TYPE
20
from maasserver.testing.factory import factory
21
from maasserver.testing.testcase import MAASServerTestCase
24
class TestPartition(MAASServerTestCase):
25
"""Tests for the `Partition` model."""
27
def test_get_node_returns_partition_table_node(self):
28
partition = factory.make_Partition()
30
partition.partition_table.get_node(), partition.get_node())
32
def test_get_block_size_returns_partition_table_block_size(self):
33
partition = factory.make_Partition()
35
partition.partition_table.get_block_size(),
36
partition.get_block_size())
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)
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)
50
def test_save_doesnt_overwrite_uuid(self):
52
table = factory.make_PartitionTable(
53
table_type=PARTITION_TABLE_TYPE.GPT)
54
partition = factory.make_Partition(partition_table=table, uuid=uuid)
56
self.assertEquals('%s' % uuid, partition.uuid)