Beispiel #1
0
 def test_insert(self):
     departmentName = 'CSE'
     old_count = Department.objects.all().count()
     department = Department(departmentName=departmentName)
     department.save()
     new_count = Department.objects.all().count()
     self.assertNotEqual(old_count, new_count)
Beispiel #2
0
 def test_get(self):
     departmentName = 'CSE'
     department = Department(departmentName=departmentName)
     department.save()
     response = self.client.get('/department/')
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_200_OK)
Beispiel #3
0
 def test_str_department(self):
     """
     Testing __str__ of Department's model
     """
     dep = Department(name="Test string representation")
     dep.save()
     self.assertEqual(str(dep), "Test string representation")
Beispiel #4
0
 def test_get_by_id(self):
     deprtmentName = 'CSE'
     department = Department(departmentName=deprtmentName)
     department.save()
     data = Department.objects.get(departmentName=deprtmentName)
     response = self.client.get('/department/%s/' % data.departmentId)
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_200_OK)
Beispiel #5
0
 def test_delete(self):
     Department.objects.all().delete()
     department = Department(departmentName='CSE')
     department.save()
     saved_data = Department.objects.get(departmentName='CSE')
     response = self.client.delete('/department/%s/' %
                                   saved_data.departmentId)
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_202_ACCEPTED)
Beispiel #6
0
 def test_delete_not_found(self):
     Department.objects.all().delete()
     department = Department(departmentName='CSE')
     department.save()
     saved_data = Department.objects.get(departmentName='CSE')
     id = int(saved_data.departmentId) + 1
     response = self.client.delete('/department/%s/' % id)
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_404_NOT_FOUND)
Beispiel #7
0
 def test_post_exists(self):
     Department.objects.all().delete()
     departmentName = "CSE"
     department = Department(departmentName=departmentName)
     department.save()
     data = {"departmentName": "CSE"}
     response = self.client.post('/department/', data)
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_409_CONFLICT)
Beispiel #8
0
 def test_put(self):
     Professor.objects.all().delete()
     self.setup()
     department=Department(departmentName='EXTC')
     department.save()
     departmentId=Department.objects.get(departmentName='EXTC').departmentId
     data={"fname":"rkc","lname":"rkc","email":"*****@*****.**","mobile":"123456789","city":"nanded","state":"maha","department":departmentId}
     response=self.client.put('/professor/%s/' % self.professorId,data)
     self.assertEqual(json.loads(response.content)['Status'],status.HTTP_201_CREATED)
 def setUp(self):
     self.test_department = Department(name='测试部门', username='******', password='******')
     self.test_department.save()
     user = User.objects.create_user(
         username='******', password='******',
         email='*****@*****.**'
     )
     self.test_user = UserDetailInfo(username='******',
                                     department=self.test_department,
                                     user=user)
Beispiel #10
0
 def test_put(self):
     HOD.objects.all().delete()
     self.setup()
     department = Department(departmentName='EXTC')
     department.save()
     departmentId = Department.objects.get(
         departmentName='EXTC').departmentId
     data = {"departmentId": departmentId}
     response = self.client.put('/hod/%s/' % self.hodId, data)
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_201_CREATED)
Beispiel #11
0
 def test_put_not_found(self):
     Department.objects.all().delete()
     departmentName = 'CSE'
     department = Department(departmentName=departmentName)
     department.save()
     data = Department.objects.get(departmentName='CSE')
     id = int(data.departmentId) + 1
     data = {"departmentName": "EXTC"}
     response = self.client.put('/department/%s/' % id)
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_404_NOT_FOUND)
Beispiel #12
0
 def test_put(self):
     Department.objects.all().delete()
     departmentName = "CSE"
     department = Department(departmentName=departmentName)
     department.save()
     saved_data = Department.objects.get(departmentName='CSE')
     data = {"departmentName": "EXTC"}
     response = self.client.put('/department/%s/' % saved_data.departmentId,
                                data)
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_201_CREATED)
Beispiel #13
0
def seed_course_table():
    course = Course(name="Testing 101",
                    number=3342,
                    credit_hours=3,
                    department=(Department.get(Department.id == 1)))
    course.save()

    course = Course(name="Database Management Systems",
                    number=4523,
                    credit_hours=3,
                    department=(Department.get(Department.id == 2)))
    course.save()
Beispiel #14
0
 def test_put_not_found(self):
     HOD.objects.all().delete()
     self.setup()
     id = int(self.hodId) + 1
     departmentName = "EXTC"
     department = Department(departmentName=departmentName)
     department.save()
     departmentId = Department.objects.get(
         departmentName='EXTC').departmentId
     data = {"departmentId": departmentId}
     response = self.client.put('/hod/%s/' % id, data)
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_404_NOT_FOUND)
Beispiel #15
0
 def setup(self):
     departmentName='CSE'
     professerName='RKC'
     department=Department(departmentName=departmentName)
     department.save()
     department=Department.objects.get(departmentName=departmentName)
     self.department=department
     self.departmentId=department.departmentId
     professor=Professor(fname=professerName,lname=professerName,email='*****@*****.**',mobile='123456789',city='nanded',state='maha',department=self.department)
     professor.save()
     professor=Professor.objects.get(fname=professerName)
     self.professor=professor
     self.professorId=professor.professorId
class TestScrapyPlan(APITestCase):
    """
    测试爬取天窗修计划的情形
    """

    def setUp(self):
        self.test_department = Department(name='测试部门', username='******', password='******')
        self.test_department.save()
        user = User.objects.create_user(
            username='******', password='******',
            email='*****@*****.**'
        )
        self.test_user = UserDetailInfo(username='******',
                                        department=self.test_department,
                                        user=user)

    def test_scrapy_is_ok(self):
        """
        测试爬取是否正常,仅测试在内网的情况
        :return: 
        """
        if is_in_rail_net:
            start_date = datetime.date.today() - datetime.timedelta(days=8)
            end_date = datetime.date.today() - datetime.timedelta(days=1)
            url = reverse('查询天窗修计划历史')
            url += '?'
            url += '&'.join([
                'start_date=' + start_date.strftime('%Y-%m-%d'),
                'end_date=' + end_date.strftime('%Y-%m-%d'),
                'force_update=' + 'true'
            ])
            self.client.force_login(self.test_user.user)
            response = self.client.get(url)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.data['length'], len(response.data['data']))
            for i in response.data['data']:
                self.assertGreaterEqual(len(i['content']), 1)
        else:
            return

    def test_get_data_from_cache(self):
        """从缓存获取计划"""
        pass

    def test_get_date_by_generator(self):
        """
        测试生成函数是否工作
        :return: 
        """
        pass
Beispiel #17
0
 def test_put_coflict(self):
     HOD.objects.all().delete()
     self.setup()
     departmentName = "EXTC"
     department = Department(departmentName=departmentName)
     department.save()
     hod = HOD(departmentId=department, hod=self.professor)
     hod.save()
     departmentId = Department.objects.get(
         departmentName='EXTC').departmentId
     data = {"departmentId": departmentId}
     response = self.client.put('/hod/%s/' % self.hodId, data, fomat='json')
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_409_CONFLICT)
Beispiel #18
0
def add_department(title):
    dept = Department()
    dept.title = title
    
    deptUser = User()
    deptUser.username = title
    deptUser.set_password(title)
    deptUser.is_staff=True
    deptUser.is_active=True
    
    dept_group = Group.objects.get(name='Department')
    deptUser.save()
    dept.user = deptUser
    dept.save()
    dept_group.user_set.add(deptUser)
Beispiel #19
0
def user_edit(request):
    '''  api/user/edit POST
    编辑用户。
    para: name(str), password(str), department_id(str), role([...])
    return: code =
        200: success
        201: parameter error
        202:no such user
    '''
    name, pwd, department_id, roles = parse_args(request.body,
                                                 'name',
                                                 'password',
                                                 'department',
                                                 'role',
                                                 department='')

    if name == 'admin':
        return gen_response(code=203, message="admin 的信息不能被修改")

    user = User.objects.get(username=name)
    if pwd != '':
        user.set_password(pwd)
    try:
        department = Department.objects.get(id=department_id)
    except Department.DoesNotExist:
        department = Department.root()
    user.department = department
    user.save()
    user.set_roles(roles)

    return gen_response(code=200, message=f'{user.username} 信息修改')
Beispiel #20
0
def user_add(request):
    '''  api/user/add POST
    添加用户。
    para: name(str), department(str), role([...])
    return: code =
        200: success
        201: parameter error
        400: Validation Error when saving user
    '''

    name, department_id, roles = parse_args(request.body,
                                            'name',
                                            'department',
                                            'role',
                                            department='')
    try:
        department = Department.objects.get(id=department_id)
    except Department.DoesNotExist:
        department = Department.root()

    user = User(username=name, department=department)
    user.set_password('123456')
    user.full_clean()
    user.save()
    user.set_roles(roles)
    return gen_response(code=200, message=f'添加用户 {name}')
def add_admin():
    ''' 增加用户名密码均为 admin 的超级用户 '''
    from department.models import Department
    from .models import User
    if not User.objects.filter(username='******').exists():
        admin = User(username='******',
                     department=Department.root(),
                     is_superuser=True)
        admin.set_password('admin')
        admin.save()
 def get(self, request,  institute_id=None, department_id=None, group_id=None, format=None):
     if group_id:
         group = Group.get_by_id(group_id)
         if not group:
             return Response(status=status.HTTP_404_NOT_FOUND)
         serialized_data = GroupSerializer(group)
         return Response(serialized_data.data)
     institute = Institute.get_by_id(institute_id)
     department = Department.get_by_id(department_id)
     groups = Group.objects.filter(institute=institute, department=department)
     return Response(groups.data)
Beispiel #23
0
 def test_put_coflict(self):
     Department.objects.all().delete()
     departmentName = "CSE"
     department = Department(departmentName=departmentName)
     department.save()
     departmentName = "EXTC"
     department = Department(departmentName=departmentName)
     department.save()
     saved_data = Department.objects.get(departmentName='EXTC')
     data = {"departmentName": "CSE"}
     response = self.client.put('/department/%s/' % saved_data.departmentId,
                                data,
                                fomat='json')
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_409_CONFLICT)
def edit(department_code, course_number):
    try:
        course = Course.select().join(Department).where(
            Department.code == department_code,
            Course.number == course_number).get()
    except model.DoesNotExist:
        abort(404)

    form = CourseForm(obj=course)
    form.department.choices = [(d.id, d.name) for d in Department.select()]
    if form.validate_on_submit():
        form.populate_obj(course)
        course.save()

        return redirect(course.absolute_url())

    return render_template('course/form.html', title="Edit course", form=form)
def create():
    form = CourseForm()

    # WTForms doesn't handle relationships between objects well
    # their documentation suggests this for populating the deparment select list
    # FIXME: move this to a constructor (?) on the CourseForm object
    form.department.choices = [(d.id, d.name) for d in Department.select()]

    if form.validate_on_submit():
        course = Course()
        form.populate_obj(course)
        course.save()

        return redirect(course.absolute_url())

    return render_template('course/form.html',
                           title="Add new course",
                           form=form)
Beispiel #26
0
 def get_queryset(self):
     return Department.get_categories_from_id(self.kwargs.get('id'))
Beispiel #27
0
def recreate_department_table():
    Department.drop_table(fail_silently=True)
    Department.create_table(fail_silently=True)
Beispiel #28
0
def seed_department_table():
    dept = Department(name="Testing Department", code="TEST")
    dept.save()

    dept = Department(name="Computer Science/Engineering", code="CSCE")
    dept.save()
Beispiel #29
0
 def test_string_representation(self):
     department = Department(name="Department string")
     self.assertEqual(str(department), department.name)
Beispiel #30
0
def departmentFactory():
    deps = []
    new_department = Department()
    new_department.name = dep_levels.pop(0)
    new_department.parent = None
    new_department.save()
    deps.append(new_department)
    try:
        for parent in deps:
            new_department = Department()
            if len(dep_levels) > 0:
                new_department.name = dep_levels.pop(0)
                new_department.parent = parent
                new_department.save()
                deps.append(new_department)
            else:
                print('List is empty')
    except:
        print('finish')
def init_department():
    ''' 增加顶层部门 '''
    from department.models import Department

    if not Department.objects.all().exists():
        top = Department(name='总公司', parent=None)
        top.save()

        d_1 = Department(name='开发部', parent=top)
        d_11 = Department(name='前端组', parent=d_1)
        d_12 = Department(name='后端组', parent=d_1)

        d_2 = Department(name='市场部', parent=top)
        d_3 = Department(name='运维部', parent=top)
        d_4 = Department(name='人力资源部', parent=top)
        d_5 = Department(name='财务部', parent=top)

        for department in [d_1, d_11, d_12, d_2, d_3, d_4, d_5]:
            department.save()