Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

from django.test import TestCase 

import members.models 

from ddt import ddt, data, unpack 

 

 

@ddt 

class TestEmailAddress(TestCase): 

 

def setUp(self): 

# One member is all we need 

self.member = members.models.Member(first_name='first', last_name='last', address_1='address', 

address_country='DE') 

self.member.save() 

 

def test_uniqueness(self): 

from django.db import IntegrityError 

email_address_1 = members.models.EmailAddress(person=self.member, email_address='a@example.com') 

email_address_2 = members.models.EmailAddress(person=self.member, email_address='a@example.com') 

email_address_1.save() 

with self.assertRaises(IntegrityError, msg='If this fails try deleting your db.sqlite3 and rebuilding it.'): 

email_address_2.save() 

 

@data( 

[[{'email_address': 'a@example.com'}], [True]], 

[[ 

{'email_address': 'a@example.com'}, 

{'email_address': 'b@example.com', 'gpg_key_id': '0x12341234'} 

], [True, False]], 

[[ 

{'email_address': 'a@example.com'}, 

{'email_address': 'b@example.com', 'is_primary': True} 

], [False, True]] 

) 

@unpack 

def test_primary_at_creation(self, email_addresses, primary_states): 

for email_address in email_addresses: 

members.models.EmailAddress(person=self.member, **email_address).save() 

 

self.assertEqual(members.models.EmailAddress.objects.filter(is_primary=True).count(), 1, 

'There should be exactly one primary email address at any given time') 

 

self.assertEqual([email.is_primary for email in members.models.EmailAddress.objects.all()], primary_states) 

 

def test_primary_at_deletion(self): 

email_address_1 = members.models.EmailAddress(person=self.member, email_address='a@example.com') 

email_address_1.save() 

email_address_2 = members.models.EmailAddress( 

person=self.member, email_address='b@example.com', is_primary=True) 

email_address_2.save() 

email_address_2.delete() 

 

self.assertTrue(email_address_1.is_primary)