|
| 1 | +""" |
| 2 | +GitLab API: |
| 3 | +https://docs.gitlab.com/ce/api/topics.html |
| 4 | +""" |
| 5 | +importpytest |
| 6 | +importresponses |
| 7 | + |
| 8 | +fromgitlab.v4.objectsimportTopic |
| 9 | + |
| 10 | +name="GitLab" |
| 11 | +new_name="gitlab-test" |
| 12 | +topic_content= { |
| 13 | +"id":1, |
| 14 | +"name":name, |
| 15 | +"description":"GitLab is an open source end-to-end software development platform.", |
| 16 | +"total_projects_count":1000, |
| 17 | +"avatar_url":"http://www.gravatar.com/avatar/a0d477b3ea21970ce6ffcbb817b0b435?s=80&d=identicon", |
| 18 | +} |
| 19 | +topics_url="http://localhost/api/v4/topics" |
| 20 | +topic_url=f"{topics_url}/1" |
| 21 | + |
| 22 | + |
| 23 | +@pytest.fixture |
| 24 | +defresp_list_topics(): |
| 25 | +withresponses.RequestsMock()asrsps: |
| 26 | +rsps.add( |
| 27 | +method=responses.GET, |
| 28 | +url=topics_url, |
| 29 | +json=[topic_content], |
| 30 | +content_type="application/json", |
| 31 | +status=200, |
| 32 | + ) |
| 33 | +yieldrsps |
| 34 | + |
| 35 | + |
| 36 | +@pytest.fixture |
| 37 | +defresp_get_topic(): |
| 38 | +withresponses.RequestsMock()asrsps: |
| 39 | +rsps.add( |
| 40 | +method=responses.GET, |
| 41 | +url=topic_url, |
| 42 | +json=topic_content, |
| 43 | +content_type="application/json", |
| 44 | +status=200, |
| 45 | + ) |
| 46 | +yieldrsps |
| 47 | + |
| 48 | + |
| 49 | +@pytest.fixture |
| 50 | +defresp_create_topic(): |
| 51 | +withresponses.RequestsMock()asrsps: |
| 52 | +rsps.add( |
| 53 | +method=responses.POST, |
| 54 | +url=topics_url, |
| 55 | +json=topic_content, |
| 56 | +content_type="application/json", |
| 57 | +status=200, |
| 58 | + ) |
| 59 | +yieldrsps |
| 60 | + |
| 61 | + |
| 62 | +@pytest.fixture |
| 63 | +defresp_update_topic(): |
| 64 | +updated_content=dict(topic_content) |
| 65 | +updated_content["name"]=new_name |
| 66 | + |
| 67 | +withresponses.RequestsMock()asrsps: |
| 68 | +rsps.add( |
| 69 | +method=responses.PUT, |
| 70 | +url=topic_url, |
| 71 | +json=updated_content, |
| 72 | +content_type="application/json", |
| 73 | +status=200, |
| 74 | + ) |
| 75 | +yieldrsps |
| 76 | + |
| 77 | + |
| 78 | +@pytest.fixture |
| 79 | +defresp_delete_topic(no_content): |
| 80 | +withresponses.RequestsMock()asrsps: |
| 81 | +rsps.add( |
| 82 | +method=responses.DELETE, |
| 83 | +url=topic_url, |
| 84 | +json=no_content, |
| 85 | +content_type="application/json", |
| 86 | +status=204, |
| 87 | + ) |
| 88 | +yieldrsps |
| 89 | + |
| 90 | + |
| 91 | +deftest_list_topics(gl,resp_list_topics): |
| 92 | +topics=gl.topics.list() |
| 93 | +assertisinstance(topics,list) |
| 94 | +assertisinstance(topics[0],Topic) |
| 95 | +asserttopics[0].name==name |
| 96 | + |
| 97 | + |
| 98 | +deftest_get_topic(gl,resp_get_topic): |
| 99 | +topic=gl.topics.get(1) |
| 100 | +assertisinstance(topic,Topic) |
| 101 | +asserttopic.name==name |
| 102 | + |
| 103 | + |
| 104 | +deftest_create_topic(gl,resp_create_topic): |
| 105 | +topic=gl.topics.create({"name":name}) |
| 106 | +assertisinstance(topic,Topic) |
| 107 | +asserttopic.name==name |
| 108 | + |
| 109 | + |
| 110 | +deftest_update_topic(gl,resp_update_topic): |
| 111 | +topic=gl.topics.get(1,lazy=True) |
| 112 | +topic.name=new_name |
| 113 | +topic.save() |
| 114 | +asserttopic.name==new_name |
| 115 | + |
| 116 | + |
| 117 | +deftest_delete_topic(gl,resp_delete_topic): |
| 118 | +topic=gl.topics.get(1,lazy=True) |
| 119 | +topic.delete() |