forked from TencentBlueKing/bk-sops
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c7630d
commit 65ec14c
Showing
7 changed files
with
140 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 3.2.15 on 2023-12-05 06:56 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("core", "0025_auto_20230609_2101"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="UserFavoriteProject", | ||
fields=[ | ||
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("username", models.CharField(max_length=128, verbose_name="用户名")), | ||
("project_id", models.IntegerField(verbose_name="项目id")), | ||
], | ||
options={ | ||
"verbose_name": "用户收藏项目 UserFavoriteProject", | ||
"verbose_name_plural": "用户收藏项目 UserFavoriteProject", | ||
"unique_together": {("username", "project_id")}, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community | ||
Edition) available. | ||
Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" | ||
|
||
from django.test import TestCase | ||
|
||
from gcloud.core.models import UserFavoriteProject | ||
|
||
|
||
class UserFavoriteProjectTestCase(TestCase): | ||
def setUp(self): | ||
self.username = "user" | ||
self.project_id = 1 | ||
|
||
def tearDown(self): | ||
UserFavoriteProject.objects.all().delete() | ||
|
||
def test_add_user_favorite_project(self): | ||
self.assertEqual(UserFavoriteProject.objects.count(), 0) | ||
UserFavoriteProject.objects.add_user_favorite_project(self.username, self.project_id) | ||
self.assertEqual(UserFavoriteProject.objects.count(), 1) | ||
|
||
def test_remove_user_favorite_project(self): | ||
UserFavoriteProject.objects.create(username=self.username, project_id=self.project_id) | ||
self.assertEqual(UserFavoriteProject.objects.count(), 1) | ||
UserFavoriteProject.objects.remove_user_favorite_project(self.username, self.project_id) | ||
self.assertEqual(UserFavoriteProject.objects.count(), 0) | ||
|
||
def test_get_user_favorite_projects(self): | ||
UserFavoriteProject.objects.create(username=self.username, project_id=1) | ||
UserFavoriteProject.objects.create(username=self.username, project_id=2) | ||
self.assertEqual(list(UserFavoriteProject.objects.get_user_favorite_projects(self.username)), [1, 2]) |