File: test_fields.py

package info (click to toggle)
django-macaddress 1.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 164 kB
  • sloc: python: 213; makefile: 4
file content (27 lines) | stat: -rw-r--r-- 897 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from django.core.exceptions import ValidationError
from django.test import TestCase
from django.db import transaction

from netaddr.core import AddrFormatError

from .models import NetworkThingy


class MACAddressFieldTestCase(TestCase):
    def test_insert_valid_macaddress(self):
        mac_example = '00:11:22:33:44:aa'
        x = NetworkThingy(mac=mac_example)
        x.save()
        qm = NetworkThingy.objects
        self.assertEqual(x.mac, mac_example)
        self.assertEqual(qm.get(mac=mac_example).mac, mac_example)
        self.assertEqual(qm.all().count(), 1)

    def test_insert_invalid_macaddress(self):
        invalid_mac = 'XX'
        with transaction.atomic():
            x = NetworkThingy()
            with self.assertRaises(ValidationError):
                x.mac = invalid_mac
                x.save()
        self.assertEqual(NetworkThingy.objects.all().count(), 0)