Example #1
0
 def test_shuffle_data(self):
     gift_circle = GiftCircle("test_unit_3.txt")
     parsed = gift_circle.parse_data()
     shuffled = gift_circle.shuffle_data()
     names_shuffled = [ s['name'] for s in shuffled ]
     names_shuffled.sort()
     self.assertEqual(names_shuffled, [ p['name'] for p in parsed ])
     elem = random.choice(names_shuffled)
     self.assertTrue(elem in names_shuffled)
     with self.assertRaises(ValueError):
         random.sample(names_shuffled, 4)
     for elem in random.sample(names_shuffled, 3):
         self.assertTrue(elem in names_shuffled)
Example #2
0
 def test_send_circle(self, mock_smtplib):
     gift_circle = GiftCircle("test_unit_3.txt")
     gift_circle.parse_data()
     gift_circle.shuffle_data()
     smtpserver = mock_smtplib.return_value
     smtpserver.sendmail.return_value={}
     gift_circle.send_circle()
     self.assertTrue(smtpserver.sendmail.called)
Example #3
0
    def test_send_circle(self, mock_twilio):
        gift_circle = GiftCircle("test_unit_6.txt")
        gift_circle.parse_data()
        gift_circle.shuffle_data()

        import random
        class message(object):
            sid = "SM"+"".join(random.choice("abcdef0123456789") for i in range(32))
        twilio = mock_twilio.return_value
        twilio.sms.messages.create.return_value=message()
        gift_circle.send_circle()
        self.assertTrue(twilio.sms.messages.create.called)
Example #4
0
    def test_parse_data(self):
        gift_circle = GiftCircle("test_unit.txt")
        parsed = gift_circle.parse_data()
        self.assertListEqual(parsed, [{'name'    : "Nombre1",
                                       'contacts': [{'addr':"*****@*****.**",'type':Email}],
                                      },
                                      {'name'    : "Nombre2",
                                       'contacts': [{'addr':"*****@*****.**",'type':Email}],
                                      },
                                     ])
        self.assertListEqual(parsed, gift_circle.parsed)

        gift_circle = GiftCircle("test_unit_2.txt")
        parsed = gift_circle.parse_data()
        self.assertListEqual(parsed, [{'name'    : "Nombre1",
                                       'contacts': [{'addr':"*****@*****.**",'type':Email}],
                                      },
                                      {'name'    : "Nombre2",
                                       'contacts': [{'addr':"*****@*****.**",'type':Email}],
                                      },
                                     ])
        self.assertListEqual(parsed, gift_circle.parsed)

        gift_circle = GiftCircle("test_unit_3.txt")
        parsed = gift_circle.parse_data()
        self.assertListEqual(parsed, [{'name'    : "Nombre1",
                                       'contacts': [{'addr':"*****@*****.**",'type':Email}],
                                      },
                                      {'name'    : "Nombre2",
                                       'contacts': [{'addr':"*****@*****.**",'type':Email}],
                                      },
                                      {'name'    : "Nombre3",
                                       'contacts': [{'addr':"*****@*****.**",'type':Email},
                                                    {'addr':"*****@*****.**",'type':Email}],
                                      },
                                     ])
        self.assertListEqual(parsed, gift_circle.parsed)

        gift_circle = GiftCircle("test_unit_5.txt")
        with self.assertRaisesRegexp(Exception, "'GiftCircle' bad contact") as ex:
            gift_circle.parse_data()
Example #5
0
 def test_malContacto(self):
     gf = GiftCircle('test_unit_5.txt')
     with self.assertRaisesRegexp(Exception, "'GiftCircle' bad contact") as ex:
         pd = gf.parse_data()
Example #6
0
 def test_setEmailAndSMS(self):
     gf = GiftCircle('test_unit_4.txt')
     pd = gf.parse_data()
     self.assertEqual(pd[2]['contacts'][0]['type'], Email)
     self.assertEqual(pd[2]['contacts'][1]['type'], SMS)
Example #7
0
 def test_cannotsend_without_shuffle(self):
     gift_circle = GiftCircle("test_unit_3.txt")
     gift_circle.parse_data()
     with self.assertRaisesRegexp(AttributeError, "'GiftCircle' object has no attribute 'shuffled'") as ex:
         gift_circle.send_circle("This is a test message")
Example #8
0
 def test_cannotshuffle_without_parse(self):
     gift_circle = GiftCircle("test_unit_3.txt")
     with self.assertRaisesRegexp(AttributeError, "'GiftCircle' object has no attribute 'parsed'") as ex:
         shuffled = gift_circle.shuffle_data()