Exemplo n.º 1
0
    def test_save(self):
        cl = make_contactlog()
        operator = make_operator()

        f = ContactForm(data={'callsign': 'W2PE',
                              'mode': Mode.objects.get(name='CW').id,
                              'band': Band.objects.get(name='20m').id,
                              'frequency': '14.125',
                              'when': '2011-01-02 03:04',
                              'rst_sent': '59',
                              'rst_received': '599',
                              'contest_exchange_sent': '1/NY',
                              'contest_exchange_received': '33/WV'})

        self.assertTrue(f.is_valid())
        self.assertEquals(0, Contact.objects.filter(callsign='W2PE').count())

        contact = f.save(contact_log=cl,operator=operator)

        self.assertEquals(1, Contact.objects.filter(callsign='W2PE').count())
        self.assertEquals('W2PE', contact.callsign)
        self.assertEquals('2011-01-02 03:04:00', unicode(contact.when))
        self.assertEquals(cl, contact.contact_log)
        self.assertEquals(operator, contact.operator)
        self.assertEquals('CW', contact.mode.name)
        self.assertEquals('20m', contact.band.name)
        self.assertEquals('59', contact.rst_sent)
        self.assertEquals('599', contact.rst_received)
        self.assertEquals('1/NY', contact.contest_exchange_sent)
        self.assertEquals('33/WV', contact.contest_exchange_received)
        self.assertEquals('14.125', contact.frequency)
Exemplo n.º 2
0
 def test_validate_band(self):
     f = ContactForm(data={'band': None})
     self.assertFalse(f.is_valid())
     self.assertEquals([u"Please select a band or enter a frequency."], f.errors.get('__all__'))
     
     f = ContactForm(data={'frequency': '7.1'})
     self.assertFalse(f.is_valid())
     self.assertFalse(f.errors.get('__all__'))
Exemplo n.º 3
0
    def test_save_set_band(self):
        cl = make_contactlog()
        operator = make_operator()

        f = ContactForm(data={'callsign': 'W2PE',
                              'frequency': '14.243',
                              'mode': Mode.objects.get(name='CW').id})
        self.assertTrue(f.is_valid())
        self.assertEquals(0, Contact.objects.filter(callsign='W2PE').count())

        contact = f.save(contact_log=cl,operator=operator)

        self.assertEquals(1, Contact.objects.filter(callsign='W2PE').count())
        self.assertEquals('W2PE', contact.callsign)
        self.assertEquals('20m', contact.band.name)

        f = ContactForm(data={'callsign': 'W2PE',
                              'frequency': '1.000',
                              'mode': Mode.objects.get(name='CW').id})
        self.assertFalse(f.is_valid())
        self.assertEquals({'__all__': [u'Please select a band or enter a frequency.']}, f.errors)
Exemplo n.º 4
0
    def test_save_set_when(self):
        cl = make_contactlog()
        operator = make_operator()

        f = ContactForm(data={'callsign': 'W2PE',
                              'mode': Mode.objects.get(name='CW').id,
                              'band': Band.objects.get(name='20m').id})

        self.assertTrue(f.is_valid())
        self.assertEquals(0, Contact.objects.filter(callsign='W2PE').count())

        contact = f.save(contact_log=cl,operator=operator)

        self.assertEquals(1, Contact.objects.filter(callsign='W2PE').count())
        self.assertEquals('W2PE', contact.callsign)
            
        d = datetime.datetime.utcnow()
        self.assertEquals(d.year, contact.when.year)
        self.assertEquals(d.month, contact.when.month)
        self.assertEquals(d.day, contact.when.day)
        self.assertEquals(d.hour, contact.when.hour)
        self.assertEquals(d.minute, contact.when.minute)
Exemplo n.º 5
0
    def test_validate_frequency(self):
        f = ContactForm(data={'frequency': None})
        self.assertFalse(f.is_valid())
        self.assertFalse(f.errors.get('frequency'))

        f = ContactForm(data={'frequency': 'asdf'})
        self.assertFalse(f.is_valid())
        self.assertEquals([u"Please enter frequency in the format 7.123"], f.errors.get('frequency'))

        f = ContactForm(data={'frequency': '-1.0'})
        self.assertFalse(f.is_valid())
        self.assertEquals([u"Frequency must be positive."], f.errors.get('frequency'))
Exemplo n.º 6
0
    def test_validate_rst_received(self):
        f = ContactForm(data={'rst_received': None})
        self.assertFalse(f.is_valid())
        self.assertFalse(f.errors.get('rst_received'))

        for bad_rst in ('abc','5','5999','69','00','3a'):
            f = ContactForm(data={'rst_received': bad_rst})
            self.assertFalse(f.is_valid())
            self.assertEquals([u'RST Received should be in the format 59 or 599.'],f.errors.get('rst_received'))
        
        f = ContactForm(data={'rst_received': '599'})
        self.assertFalse(f.is_valid())
        self.assertFalse(f.errors.get('rst_received'))
Exemplo n.º 7
0
    def test_get_fieldless_errors(self):
        f = ContactForm()  
        self.assertFalse(f.get_fieldless_errors())

        f = ContactForm({'asd':'asdfsafd'})
        self.assertEquals([u'Please select a band or enter a frequency.'], f.get_fieldless_errors())
Exemplo n.º 8
0
 def test_contest_exchange_received(self):
     f = ContactForm(data={'contest_exchange_received': None})
     self.assertFalse(f.is_valid())
     self.assertFalse(f.errors.get('contest_exchange_received'))
Exemplo n.º 9
0
 def test_validate_mode(self):
     f = ContactForm(data={'mode': None})
     self.assertFalse(f.is_valid())
     self.assertEquals([u"Please select a mode."], f.errors.get('mode'))
Exemplo n.º 10
0
 def test_validate_callsign(self):
     f = ContactForm(data={'callsign': None})
     self.assertFalse(f.is_valid())
     self.assertEquals([u"Please provide the contact's callsign."], f.errors.get('callsign'))
Exemplo n.º 11
0
 def test_validate_when_missing(self):
     f = ContactForm(data={'when': None})
     self.assertFalse(f.is_valid())
     self.assertFalse(f.errors.get('when'))
Exemplo n.º 12
0
 def test_validate_when_present(self):
     f = ContactForm(data={'when': '2011-01-02 03:04'})
     self.assertFalse(f.is_valid())
     self.assertFalse(f.errors.get('when'))