示例#1
0
 def setUp(self):
     """
     Runs before each test.
     """
     self.c = ModelResourceClient('http://localhost:8000/resources',
                                  'sharrock_modelresource_example', '1.0',
                                  'userresource')
     self.tom = User.objects.create(username='******')
     self.dick = User.objects.create(username='******')
     self.harry = User.objects.create(username='******')
示例#2
0
文件: tests.py 项目: Axilent/sharrock
 def setUp(self):
     """
     Runs before each test.
     """
     self.c = ModelResourceClient('http://localhost:8000/resources','sharrock_modelresource_example','1.0','userresource')
     self.tom = User.objects.create(username='******')
     self.dick = User.objects.create(username='******')
     self.harry = User.objects.create(username='******')
示例#3
0
文件: tests.py 项目: Axilent/sharrock
class ModelResourceClientTests(unittest.TestCase):
    """
    Tests a model resource.
    """
    def setUp(self):
        """
        Runs before each test.
        """
        self.c = ModelResourceClient('http://localhost:8000/resources','sharrock_modelresource_example','1.0','userresource')
        self.tom = User.objects.create(username='******')
        self.dick = User.objects.create(username='******')
        self.harry = User.objects.create(username='******')
    
    def tearDown(self):
        """
        Runs after each test.
        """
        self.harry.delete()
        self.dick.delete()
        self.tom.delete()
        self.c = None
    
    def test_list(self):
        """
        Tests the listing of a resource.
        """
        results = self.c.list()
        usernames = [result['username'] for result in results]
        self.assertTrue('Tom' in usernames)
        self.assertTrue('Dick' in usernames)
        self.assertTrue('Harry' in usernames)
    
    def test_get(self):
        """
        Tests the get function.
        """
        tom_dict = self.c.get(self.tom.pk)
        self.assertEquals(tom_dict['username'],self.tom.username)
    
    def test_create(self):
        """
        Tests create function.
        """
        zelda_dict = self.c.create(username='******')
        zelda_model = User.objects.get(pk=zelda_dict['id'])
        self.assertEquals('Zelda',zelda_model.username)
    
    def test_update(self):
        """
        Tests the update function.
        """
        self.c.update(self.tom.pk,first_name='Thomas',last_name='Wayne')
        tom = User.objects.get(pk=self.tom.pk)
        self.assertEquals(tom.first_name,'Thomas')
        self.assertEquals(tom.last_name,'Wayne')
    
    def test_delete(self):
        """
        Tests the delete function.
        """
        tom_pk = self.tom.pk
        self.c.delete(tom_pk)
        self.assertRaises(User.DoesNotExist,User.objects.get,pk=tom_pk)
示例#4
0
class ModelResourceClientTests(unittest.TestCase):
    """
    Tests a model resource.
    """
    def setUp(self):
        """
        Runs before each test.
        """
        self.c = ModelResourceClient('http://localhost:8000/resources',
                                     'sharrock_modelresource_example', '1.0',
                                     'userresource')
        self.tom = User.objects.create(username='******')
        self.dick = User.objects.create(username='******')
        self.harry = User.objects.create(username='******')

    def tearDown(self):
        """
        Runs after each test.
        """
        self.harry.delete()
        self.dick.delete()
        self.tom.delete()
        self.c = None

    def test_list(self):
        """
        Tests the listing of a resource.
        """
        results = self.c.list()
        usernames = [result['username'] for result in results]
        self.assertTrue('Tom' in usernames)
        self.assertTrue('Dick' in usernames)
        self.assertTrue('Harry' in usernames)

    def test_get(self):
        """
        Tests the get function.
        """
        tom_dict = self.c.get(self.tom.pk)
        self.assertEquals(tom_dict['username'], self.tom.username)

    def test_create(self):
        """
        Tests create function.
        """
        zelda_dict = self.c.create(username='******')
        zelda_model = User.objects.get(pk=zelda_dict['id'])
        self.assertEquals('Zelda', zelda_model.username)

    def test_update(self):
        """
        Tests the update function.
        """
        self.c.update(self.tom.pk, first_name='Thomas', last_name='Wayne')
        tom = User.objects.get(pk=self.tom.pk)
        self.assertEquals(tom.first_name, 'Thomas')
        self.assertEquals(tom.last_name, 'Wayne')

    def test_delete(self):
        """
        Tests the delete function.
        """
        tom_pk = self.tom.pk
        self.c.delete(tom_pk)
        self.assertRaises(User.DoesNotExist, User.objects.get, pk=tom_pk)