def test_givenAuthorization_whenCallGet_thenGetAllUserProject(self):
     """ List all user projects"""
     add_project(self, self.authorization)
     with self.client:
         response = get_projects(self, self.authorization)
         data = json.loads(response.data.decode())['data']
         self.assertEqual(1, len(data))
         self.assertEqual('test project name', data[0]['name'])
         self.assertTrue(response.content_type == 'application/json')
         self.assertEqual(200, response.status_code)
 def test_givenAlreadyAddedProject_whenCallPost_thenShouldReturn409(self):
     """ Test add project with already added name"""
     add_project(self, self.authorization)
     with self.client:
         response = add_project(self, self.authorization)
         data = json.loads(response.data.decode())
         self.assertTrue(data['status'] == 'fail')
         self.assertTrue(
             data['message'] ==
             'Project name already exists. Please change the name.')
         self.assertTrue(response.content_type == 'application/json')
         self.assertEqual(409, response.status_code)
 def test_givenProjectData_whenCallPost_thenAddTheProject(self):
     """ Test for add project """
     with self.client:
         response = add_project(self, self.authorization)
         data = json.loads(response.data.decode())
         self.assertEqual('success', data['status'])
         self.assertEqual('Successfully added.', data['message'])
         self.assertTrue(response.content_type == 'application/json')
         self.assertEqual(201, response.status_code)
 def test_givenProjectId_whenCallGet_thenGetTheProject(self):
     """ Get a project"""
     response = add_project(self, self.authorization)
     data = json.loads(response.data.decode())
     with self.client:
         response = get_project(self, data['project_id'],
                                self.authorization)
         data = json.loads(response.data.decode())
         self.assertTrue(data['name'] == 'test project name')
         self.assertTrue(response.content_type == 'application/json')
         self.assertEqual(200, response.status_code)
 def test_givenAlreadyAddedProject_whenCallDelete_thenDeleteSuccessfully(
         self):
     """ Test delete already added project"""
     response = add_project(self, self.authorization)
     data = json.loads(response.data.decode())
     with self.client:
         response = delete_project(self, data['project_id'],
                                   self.authorization)
         data = json.loads(response.data.decode())
         self.assertTrue(data['status'] == 'success')
         self.assertTrue(data['message'] == 'Successfully deleted.')
         self.assertTrue(response.content_type == 'application/json')
         self.assertEqual(200, response.status_code)
Пример #6
0
def add_project_user(self):
    response = add_project(self, self.authorization)
    data = json.loads(response.data.decode())
    global project_id
    project_id = data['project_id']

    return self.client.post(
        '/projects/' + str(project_id) + '/users',
        data=json.dumps(dict(
            project_id=project_id,
            user_email='*****@*****.**',
            project_owner=False
        )),
        headers={'Authorization': self.authorization},
        content_type='application/json'
    )
Пример #7
0
def add_project_device(self):
    response = add_project(self, self.authorization)
    data = json.loads(response.data.decode())
    global project_id
    project_id = data['project_id']

    response = add_device(self)
    data = json.loads(response.data.decode())
    global device_id
    device_id = data['device_id']

    return self.client.post('/projects/' + str(project_id) + '/devices',
                            data=json.dumps(
                                dict(device_id=device_id,
                                     project_id=project_id)),
                            headers={'Authorization': self.authorization},
                            content_type='application/json')
 def test_givenUnauthorizedUser_whenCallGet_thenReturn401(self):
     """Test unauthorized user to not get a project"""
     add_project(self, self.authorization)
     with self.client:
         response = get_projects(self, "fake_token")
         self.assertEqual(401, response.status_code)