Example #1
0
class ViewTest(TestCase):
  def setUp(self):
      self.client_stub = Client()
      self.person = Person(first_name = 'TestFirst',last_name = 'TestLast')
      self.person.save()
      self.phone = Phone(person = self.person,number = '7778889999')
      self.phone.save()
  def test_view_home_route(self):
      response = self.client_stub.get('/')
      self.assertEquals(response.status_code, 200)
  def test_view_contacts_route(self):
      response = self.client_stub.get('/all/')
      self.assertEquals(response.status_code, 200)
  def test_add_contact_route(self):
      response = self.client_stub.get('/add/')
      self.assertEqual(response.status_code, 200)
  def test_create_contact_successful_route(self):
      response = self.client_stub.post('/create',data = {'first_name' : 'testFirst', 'last_name':'tester', 'email':'*****@*****.**', 'address':'1234 nowhere', 'city':'far away', 'state':'CO', 'country':'USA', 'number':'987654321'})
      self.assertEqual(response.status_code, 302)
  def test_create_contact_unsuccessful_route(self):
      response = self.client_stub.post('/create',data = {'first_name' : 'tester_first_n@me', 'last_name':'test', 'email':'*****@*****.**', 'address':'5678 everywhere', 'city':'far from here', 'state':'CA', 'country':'USA', 'number':'987654321'})
      self.assertEqual(response.status_code, 200)
  def tearDown(self):
      self.phone.delete()
      self.person.delete()  
Example #2
0
class ViewTest(TestCase):

    def setUp(self):
        self.client_stub = Client()
        self.person = Person(first_name = 'TestFirst',last_name = 'TestLast')
        self.person.save()
        self.phone = Phone(person = self.person,number = '7778889999')
        self.phone.save()

    def test_view_home_route(self):
        response = self.client_stub.get('/')
        self.assertEquals(response.status_code, 200)

    def test_view_contacts_route(self):
        response = self.client_stub.get('/all/')
        self.assertEquals(response.status_code, 200)

    def test_add_contact_route(self):
        response = self.client_stub.get('/add/')
        self.assertEqual(response.status_code, 200)

    def test_create_contact_successful_route(self):
        response = self.client_stub.post('/create',data = {'first_name' : 'testFirst', 'last_name':'tester', 'email':'*****@*****.**', 'address':'1234 nowhere', 'city':'far away', 'state':'CO', 'country':'USA', 'number':'987654321'})
        self.assertEqual(response.status_code, 302)

    def test_create_contact_unsuccessful_route(self):
        response = self.client_stub.post('/create',data = {'first_name' : 'tester_first_n@me', 'last_name':'test', 'email':'*****@*****.**', 'address':'5678 everywhere', 'city':'far from here', 'state':'CA', 'country':'USA', 'number':'987654321'})
        self.assertEqual(response.status_code, 200)

    def tearDown(self):
        self.phone.delete()
        self.person.delete()
Example #3
0
    def test_unicode(self):
        phone = Phone()
        number = "8675309"
        phone.number = number

        expected = number
        actual = phone.__unicode__()
        self.assertEquals(expected, actual)
Example #4
0
 def setUp(self):
     self.client_stub = Client()
     self.person = Person(
         first_name='TestFirst',
         last_name='TestLast')
     self.person.save()
     self.phone = Phone(
         person=self.person,
         number='12345')
     self.phone.save()
Example #5
0
 def setUp(self):
     self.client_stub = Client()
     self.person = Person(first_name='TestFirst', last_name='TestLast')
     self.person.save()
     self.phone = Phone(person=self.person, number='7778889999')
     self.phone.save()
Example #6
0
class ViewTest(TestCase):

    def tearDown(self):
        self.phone.delete()
        self.person.delete()

    def setUp(self):
        self.client_stub = Client()
        self.person = Person(
            first_name='TestFirst',
            last_name='TestLast')
        self.person.save()
        self.phone = Phone(
            person=self.person,
            number='12345')
        self.phone.save()

    def test_view_inline_validation_valid_post(self):
        data = {
            'field_name': 'first_name',
            'field_value': 'victory'}
        response = self.client_stub.post('/validate', data)
        self.assertEquals(response.status_code, 200)

        self.assertEquals(response.content, '{"result":"valid"}')

    def test_view_inline_validation_invalid_post(self):
        data = {
            'field_name': 'first_name',
            'field_value': '++invalid++'}
        response = self.client_stub.post('/validate', data)
        self.assertEquals(response.status_code, 200)

        self.assertNotEquals(response.content, '{"result":"valid"}')

    def test_view_inline_validation_not_post_method(self):
        response = self.client_stub.get('/validate')
        self.assertEquals(response.status_code, 405)

    def test_view_inline_validation_empty_post(self):
        self.assertRaises(
            MultiValueDictKeyError,
            self.client_stub.post,
            '/validate')

    def test_view_home_route(self):
        response = self.client_stub.get('/')
        self.assertEquals(response.status_code, 200)

    def test_view_contacts_route(self):
        response = self.client_stub.get('/all/')
        self.assertEquals(response.status_code, 200)

    def test_add_contact_route(self):
        response = self.client_stub.get('/add/')
        self.assertEquals(response.status_code, 200)

    def test_create_contact_successful_route(self):
        data = {
            'first_name': 'testFirst',
            'last_name': 'testLast',
            'email': '*****@*****.**',
            'address': '123 Fake St',
            'city': 'Some Town',
            'state': 'MN',
            'country': 'USA',
            'number': '12345'}
        response = self.client_stub.post(
            '/create',
            data=data)
        self.assertEquals(response.status_code, 302)

    def test_create_fail_route(self):
        data = {
            'first_name': 'bad_@_bad',
            'last_name': 'testLast',
            'email': '*****@*****.**',
            'address': '123 Fake St',
            'city': 'Some Town',
            'state': 'MN',
            'country': 'USA',
            'number': '12345'}
        response = self.client_stub.post(
            '/create',
            data=data)
        self.assertEquals(response.status_code, 200)